முக்கிய உள்ளடக்கத்திற்கு செல்க

பிரௌசர் ஆப்ஜெக்ட்

__ Extends:__ EventEmitter

பிரௌசர் ஆப்ஜெக்ட் என்பது பிரௌசர் அல்லது மொபைல் சாதனத்தைக் கட்டுப்படுத்த நீங்கள் பயன்படுத்தும் செஷன் நிகழ்வாகும். நீங்கள் WDIO டெஸ்ட் ரன்னரைப் பயன்படுத்தினால், குளோபல் browser அல்லது driver ஆப்ஜெக்ட் மூலம் WebDriver நிகழ்வை அணுகலாம் அல்லது @wdio/globalsஐப் பயன்படுத்தி இறக்குமதி செய்யலாம். நீங்கள் தனித்தனி முறையில் WebdriverIO ஐப் பயன்படுத்தினால், பிரௌசர் ஆப்ஜெக்ட் remote முறையில் திருப்பியளிக்கப்படும்.

டெஸ்ட் ரன்னெறால் செஷன் தொடங்கப்படுகிறது. செஷனை முடிப்பதற்கும் இதுவே செல்கிறது. இது டெஸ்ட் ரன்னர் செயல்முறையாலும் செய்யப்படுகிறது.

Properties

பிரௌசர் ஆப்ஜெக்ட் பின்வரும் பண்புகளைக் கொண்டுள்ளது:

பெயர்வகைவிவரங்கள்
capabilitiesObjectAssigned capabilities from the remote server.
Example:
{
acceptInsecureCerts: false,
browserName: 'chrome',
browserVersion: '105.0.5195.125',
chrome: {
chromedriverVersion: '105.0.5195.52',
userDataDir: '/var/folders/3_/pzc_f56j15vbd9z3r0j050sh0000gn/T/.com.google.Chrome.76HD3S'
},
'goog:chromeOptions': { debuggerAddress: 'localhost:64679' },
networkConnectionEnabled: false,
pageLoadStrategy: 'normal',
platformName: 'mac os x',
proxy: {},
setWindowRect: true,
strictFileInteractability: false,
timeouts: { implicit: 0, pageLoad: 300000, script: 30000 },
unhandledPromptBehavior: 'dismiss and notify',
'webauthn:extension:credBlob': true,
'webauthn:extension:largeBlob': true,
'webauthn:virtualAuthenticators': true
}
requestedCapabilitiesObjectரிமோட் சர்வரிலிருந்து கேட்கப்பட்ட திறன்கள்.
Example:
{ browserName: 'chrome' }
sessionIdStringSession id assigned from the remote server.
optionsObjectபிரௌசர் ஆப்ஜெக்ட் எவ்வாறு உருவாக்கப்பட்டது என்பதைப் பொறுத்து WebdriverIO options. மேலும் setup typesகாண்க.
commandListString[]பிரௌசர் நிகழ்வில் பதிவுசெய்யப்பட்ட கட்டளைகளின் பட்டியல்
isW3CBooleanIndicates if this is a W3C session
isChromeBooleanIndicates if this Chrome instance
isFirefoxBooleanIndicates if this Firefox instance
isBidiBooleanIndicates if this session uses Bidi
isSauceBooleanIndicates if this session is Running on Sauce Labs
isMacAppBooleanIndicates if this session is Running for a native Mac App
isWindowsAppBooleanIndicates if this session is Running for a native Windows App
isMobileBooleanமொபைல் அமர்வைக் குறிக்கிறது. Mobile Flagsஇன் கீழ் மேலும் பார்க்கவும்.
isIOSBooleanமொபைல் அமர்வைக் குறிக்கிறது. Mobile Flagsஇன் கீழ் மேலும் பார்க்கவும்.
isAndroidBooleanAndroid அமர்வைக் குறிக்கிறது. Mobile Flagsஇன் கீழ் மேலும் பார்க்கவும்.
isNativeContextBooleanIndicates if the mobile is in the NATIVE_APP context. See more under Mobile Flags.
mobileContextstringThe will provide the current context the driver is in, for example NATIVE_APP, WEBVIEW_<packageName> for Android or WEBVIEW_<pid> for iOS. It will save an extra WebDriver to driver.getContext(). See more under Mobile Flags.

Methods

உங்கள் அமர்வுக்கு பயன்படுத்தப்படும் ஆட்டோமேஷன் பின்தளத்தின் அடிப்படையில், browser objectஉடன் எந்த Protocol Commands இணைக்கப்படும் என்பதை WebdriverIO அடையாளம் காட்டுகிறது. எடுத்துக்காட்டாக, நீங்கள் Chrome இல் தானியங்கு அமர்வை இயக்கினால், elementHover போன்ற Chromium குறிப்பிட்ட கட்டளைகளுக்கான அணுகலைப் பெறுவீர்கள், ஆனால் Appium commands க்கு அல்ல.

மேலும் WebdriverIO ஆனது, பக்கத்தில் உள்ள browser அல்லது elements உடன் தொடர்பு கொள்ள, பயன்படுத்தப் பரிந்துரைக்கப்படும் வசதியான முறைகளின் தொகுப்பை வழங்குகிறது.

கூடுதலாக, பின்வரும் கட்டளைகள் கிடைக்கின்றன:

பெயர்சுட்டீடுகள்(பாராமீட்டர்கள்)விவரங்கள்
addCommand- commandName (Type: String)
- fn (Type: Function)
- attachToElement (Type: boolean)
கலவை நோக்கங்களுக்காகப் பிரௌசர் ஆப்ஜெக்ட்டினிலிருந்து அழைக்கப்படும் தனிப்பயன் கட்டளைகளை வரையறுக்க அனுமதிக்கிறது. Custom Command வழிகாட்டியில் மேலும் படிக்கவும்.
overwriteCommand- commandName (Type: String)
- fn (Type: Function)
- attachToElement (Type: boolean)
தனிப்பயன் செயல்பாட்டுடன் எந்த பிரௌசர் கட்டளையையும் மேலெழுத அனுமதிக்கிறது. பிரமேஒர்க் பயன்படுத்துபவர்களைக் குழப்பக்கூடும் என்பதால் கவனமாகப் பயன்படுத்தவும். Custom Command வழிகாட்டியில் மேலும் படிக்கவும்.
addLocatorStrategy- strategyName (Type: String)
- fn (Type: Function)
தனிப்பயன் செலெக்டர் உத்தியை வரையறுக்க அனுமதிக்கிறது, மேலும் Selectors வழிகாட்டியில் படிக்கவும்.

குறிப்புகள்

Mobile Flags

உங்கள் அமர்வு மொபைல் சாதனத்தில் இயங்குகிறதா இல்லையா என்பதன் அடிப்படையில் உங்கள் டெஸ்டை மாற்ற வேண்டும் என்றால், சரிபார்க்க மொபைல் flagsகளை அணுகலாம்.

எடுத்துக்காட்டாக, இந்தக் கட்டமைப்பு கொடுக்கப்பட்டுள்ளது:

// wdio.conf.js
export const config = {
// ...
capabilities: \\{
platformName: 'iOS',
app: 'net.company.SafariLauncher',
udid: '123123123123abc',
deviceName: 'iPhone',
// ...
}
// ...
}

உங்கள் டெஸ்டில் இந்தக் flagsகளை நீங்கள் அணுகலாம்:

// Note: `driver` is the equivalent to the `browser` object but semantically more correct
// you can choose which global variable you want to use
console.log(driver.isMobile) // outputs: true
console.log(driver.isIOS) // outputs: true
console.log(driver.isAndroid) // outputs: false

எடுத்துக்காட்டாக, உங்கள் page objects இல் உள்ள செலக்டர்ஸுகளை சாதன வகையின் அடிப்படையில் வரையறுக்க விரும்பினால், இது பயனுள்ளதாக இருக்கும்:

// mypageobject.page.js
import Page from './page'

class LoginPage extends Page {
// ...
get username() {
const selectorAndroid = 'new UiSelector().text("Cancel").className("android.widget.Button")'
const selectorIOS = 'UIATarget.localTarget().frontMostApp().mainWindow().buttons()[0]'
const selectorType = driver.isAndroid ? 'android' : 'ios'
const selector = driver.isAndroid ? selectorAndroid : selectorIOS
return $(`${selectorType}=${selector}`)
}
// ...
}

குறிப்பிட்ட சாதன வகைகளுக்கான குறிப்பிட்ட டெஸ்டுகளை மட்டும் இயக்க இந்தக் flagsகளைப் பயன்படுத்தலாம்:

// mytest.e2e.js
describe('my test', () => {
// ...
// only run test with Android devices
if (driver.isAndroid) {
it('tests something only for Android', () => {
// ...
})
}
// ...
})

Events

பிரவுசர் ஆப்ஜெக்ட் ஒரு EventEmitter மற்றும் உங்கள் பயன்பாட்டு நிகழ்வுகளுக்காக இரண்டு நிகழ்வுகள் வெளியிடப்படும்.

நிகழ்வுகளின் பட்டியல் இங்கே. இது இன்னும் கிடைக்கக்கூடிய நிகழ்வுகளின் முழு பட்டியல் அல்ல என்பதை நினைவில் கொள்ளவும். மேலும் நிகழ்வுகளின் விளக்கங்களை இங்கே சேர்ப்பதன் மூலம் ஆவணத்தைப் புதுப்பிக்கப் பங்களிக்க தயங்க வேண்டாம்.

request.start

This event is fired before a WebDriver request is sent to the driver. It contains information about the request and its payload.

browser.on('request.start', (ev: RequestInit) => {
// ...
})

request.end

This event is fired once the request to the driver received a response. The event object either contains the response body as result or an error if the WebDriver command failed.

browser.on('request.end', (ev: { result: unknown, error?: Error }) => {
// ...
})

request.retry

The retry event can notify you when WebdriverIO attempts to retry running the command, e.g. due to a network issue. It contains information about the error that caused the retry and the amount of retries already done.

browser.on('request.retry', (ev: { error: Error, retryCount: number }) => {
// ...
})

command

This event is emitted whenever WebdriverIO sends a WebDriver Classic command. It contains the following information:

  • command: the command name, e.g. navigateTo
  • method: the HTTP method used to send the command request, e.g. POST
  • endpoint: the command endpoint, e.g. /session/fc8dbda381a8bea36a225bd5fd0c069b/url
  • body: the command payload, e.g. { url: 'https://webdriver.io' }

result

This event is emitted whenever WebdriverIO receives a result of a WebDriver Classic command. It contains the same information as the command event with the addition of the following information:

  • result: the command result

bidiCommand

This event is emitted whenever WebdriverIO sends a WebDriver Bidi command to the browser driver. It contains information about:

  • method: WebDriver Bidi command method
  • params: associated command parameter (see API)

bidiResult

In case of a successful command execution, the event payload will be:

  • type: success
  • id: the command id
  • result: the command result (see API)

In case of a command error, the event payload will be:

  • type: error
  • id: the command id
  • error: the error code, e.g. invalid argument
  • message: details about the error
  • stacktrace: a stack trace

request.start

This event is fired before a WebDriver request is sent to the driver. It contains information about the request and its payload.

browser.on('request.start', (ev: RequestInit) => {
// ...
})

request.end

This event is fired once the request to the driver received a response. The event object either contains the response body as result or an error if the WebDriver command failed.

browser.on('request.end', (ev: { result: unknown, error?: Error }) => {
// ...
})

request.retry

The retry event can notify you when WebdriverIO attempts to retry running the command, e.g. due to a network issue. It contains information about the error that caused the retry and the amount of retries already done.

browser.on('request.retry', (ev: { error: Error, retryCount: number }) => {
// ...
})

request.performance

இது WebDriver நிலை செயல்பாடுகளை அளவிடும் நிகழ்வு. WebdriverIO WebDriver பின்தளத்திற்கு கோரிக்கையை அனுப்பும் போதெல்லாம், இந்த நிகழ்வு சில பயனுள்ள தகவல்களுடன் வெளியிடப்படும்:

  • durationMillisecond: கோரிக்கையின் கால அளவு மில்லி வினாடியில்.
  • error: கோரிக்கை தோல்வியுற்றால் Error object.
  • request: Request object. நீங்கள் url, method, headers போன்றவற்றைக் காணலாம்.
  • retryCount: இது 0எனில், கோரிக்கை முதல் முயற்சி. WebDriverIO தன்னிச்சையாக மீண்டும் முயற்சிக்கும்போது இது அதிகரிக்கும்.
  • success: Boolean கோரிக்கை வெற்றியடைந்ததா இல்லையா என்பதைப் பிரதிநிதித்துவப்படுத்தும். அது falseஎன்றால், error property வழங்கப்படும்.

உதாரண நிகழ்வு:

Object {
"durationMillisecond": 0.01770925521850586,
"error": [Error: Timeout],
"request": Object { ... },
"retryCount": 0,
"success": false,
},

Custom Commands

பொதுவாகப் பயன்படுத்தப்படும் பணிப்பாய்வுகளைத் தவிர்க்க, பிரவுசர் ஸ்கோப்பில் தனிப்பயன் கட்டளைகளை அமைக்கலாம். மேலும் தகவலுக்கு Custom Commands இல் உள்ள எங்கள் வழிகாட்டியைப் பார்க்கவும்.

Welcome! How can I help?

WebdriverIO AI Copilot