codeceptjs 3.6.4 → 3.6.5-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/codecept.js +84 -63
- package/lib/assert/empty.js +19 -19
- package/lib/assert/equal.js +32 -30
- package/lib/assert/error.js +14 -14
- package/lib/assert/include.js +42 -42
- package/lib/assert/throws.js +13 -11
- package/lib/assert/truth.js +17 -18
- package/lib/command/configMigrate.js +57 -52
- package/lib/command/definitions.js +88 -88
- package/lib/command/dryRun.js +65 -63
- package/lib/command/generate.js +191 -181
- package/lib/command/info.js +39 -37
- package/lib/command/init.js +289 -286
- package/lib/command/interactive.js +32 -32
- package/lib/command/list.js +26 -26
- package/lib/command/run-multiple.js +113 -93
- package/lib/command/run-rerun.js +22 -22
- package/lib/command/run-workers.js +63 -63
- package/lib/command/run.js +24 -26
- package/lib/command/utils.js +64 -63
- package/lib/data/context.js +60 -60
- package/lib/data/dataScenarioConfig.js +47 -47
- package/lib/data/dataTableArgument.js +29 -29
- package/lib/data/table.js +26 -20
- package/lib/helper/AI.js +67 -65
- package/lib/helper/ApiDataFactory.js +72 -69
- package/lib/helper/Appium.js +409 -379
- package/lib/helper/ExpectHelper.js +214 -248
- package/lib/helper/FileSystem.js +77 -78
- package/lib/helper/GraphQL.js +44 -43
- package/lib/helper/GraphQLDataFactory.js +49 -50
- package/lib/helper/JSONResponse.js +64 -62
- package/lib/helper/Mochawesome.js +28 -28
- package/lib/helper/MockServer.js +12 -12
- package/lib/helper/Nightmare.js +664 -572
- package/lib/helper/Playwright.js +1320 -1211
- package/lib/helper/Protractor.js +663 -629
- package/lib/helper/Puppeteer.js +1232 -1124
- package/lib/helper/REST.js +87 -72
- package/lib/helper/TestCafe.js +490 -491
- package/lib/helper/WebDriver.js +1294 -1156
- package/lib/interfaces/bdd.js +38 -51
- package/lib/interfaces/featureConfig.js +19 -19
- package/lib/interfaces/gherkin.js +122 -111
- package/lib/interfaces/scenarioConfig.js +29 -29
- package/lib/listener/artifacts.js +9 -9
- package/lib/listener/config.js +24 -23
- package/lib/listener/exit.js +12 -12
- package/lib/listener/helpers.js +42 -42
- package/lib/listener/mocha.js +11 -11
- package/lib/listener/retry.js +32 -30
- package/lib/listener/steps.js +50 -51
- package/lib/listener/timeout.js +53 -53
- package/lib/plugin/allure.js +14 -14
- package/lib/plugin/autoDelay.js +29 -36
- package/lib/plugin/autoLogin.js +70 -66
- package/lib/plugin/commentStep.js +18 -18
- package/lib/plugin/coverage.js +92 -77
- package/lib/plugin/customLocator.js +20 -19
- package/lib/plugin/debugErrors.js +24 -24
- package/lib/plugin/eachElement.js +37 -37
- package/lib/plugin/fakerTransform.js +6 -6
- package/lib/plugin/heal.js +66 -63
- package/lib/plugin/pauseOnFail.js +10 -10
- package/lib/plugin/retryFailedStep.js +31 -38
- package/lib/plugin/retryTo.js +28 -28
- package/lib/plugin/screenshotOnFail.js +107 -86
- package/lib/plugin/selenoid.js +131 -117
- package/lib/plugin/standardActingHelpers.js +2 -8
- package/lib/plugin/stepByStepReport.js +102 -92
- package/lib/plugin/stepTimeout.js +23 -22
- package/lib/plugin/subtitles.js +34 -34
- package/lib/plugin/tryTo.js +39 -29
- package/lib/plugin/wdio.js +77 -72
- package/lib/template/heal.js +11 -14
- package/package.json +4 -2
- package/translations/de-DE.js +1 -1
- package/translations/fr-FR.js +1 -1
- package/translations/index.js +9 -9
- package/translations/it-IT.js +1 -1
- package/translations/ja-JP.js +1 -1
- package/translations/pl-PL.js +1 -1
- package/translations/pt-BR.js +1 -1
- package/translations/ru-RU.js +1 -1
- package/translations/zh-CN.js +1 -1
- package/translations/zh-TW.js +1 -1
- package/typings/promiseBasedTypes.d.ts +238 -0
- package/typings/types.d.ts +32 -0
package/lib/helper/Appium.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
let webdriverio
|
|
1
|
+
let webdriverio
|
|
2
2
|
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const axios = require('axios').default
|
|
5
|
-
const { v4: uuidv4 } = require('uuid')
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const axios = require('axios').default
|
|
5
|
+
const { v4: uuidv4 } = require('uuid')
|
|
6
6
|
|
|
7
|
-
const Webdriver = require('./WebDriver')
|
|
8
|
-
const AssertionFailedError = require('../assert/error')
|
|
9
|
-
const { truth } = require('../assert/truth')
|
|
10
|
-
const recorder = require('../recorder')
|
|
11
|
-
const Locator = require('../locator')
|
|
12
|
-
const ConnectionRefused = require('./errors/ConnectionRefused')
|
|
7
|
+
const Webdriver = require('./WebDriver')
|
|
8
|
+
const AssertionFailedError = require('../assert/error')
|
|
9
|
+
const { truth } = require('../assert/truth')
|
|
10
|
+
const recorder = require('../recorder')
|
|
11
|
+
const Locator = require('../locator')
|
|
12
|
+
const ConnectionRefused = require('./errors/ConnectionRefused')
|
|
13
13
|
|
|
14
|
-
const mobileRoot = '//*'
|
|
15
|
-
const webRoot = 'body'
|
|
14
|
+
const mobileRoot = '//*'
|
|
15
|
+
const webRoot = 'body'
|
|
16
16
|
const supportedPlatform = {
|
|
17
17
|
android: 'Android',
|
|
18
18
|
iOS: 'iOS',
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
|
|
21
21
|
const vendorPrefix = {
|
|
22
22
|
appium: 'appium',
|
|
23
|
-
}
|
|
23
|
+
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Appium helper extends [Webdriver](http://codecept.io/helpers/WebDriver/) helper.
|
|
@@ -175,19 +175,21 @@ class Appium extends Webdriver {
|
|
|
175
175
|
|
|
176
176
|
// @ts-ignore
|
|
177
177
|
constructor(config) {
|
|
178
|
-
super(config)
|
|
178
|
+
super(config)
|
|
179
179
|
|
|
180
|
-
this.isRunning = false
|
|
180
|
+
this.isRunning = false
|
|
181
181
|
if (config.appiumV2 === true) {
|
|
182
|
-
this.appiumV2 = true
|
|
182
|
+
this.appiumV2 = true
|
|
183
183
|
}
|
|
184
|
-
this.axios = axios.create()
|
|
184
|
+
this.axios = axios.create()
|
|
185
185
|
|
|
186
|
-
webdriverio = require('webdriverio')
|
|
186
|
+
webdriverio = require('webdriverio')
|
|
187
187
|
if (!config.appiumV2) {
|
|
188
|
-
console.log(
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
console.log(
|
|
189
|
+
'The Appium core team does not maintain Appium 1.x anymore since the 1st of January 2022. Please migrating to Appium 2.x by adding appiumV2: true to your config.',
|
|
190
|
+
)
|
|
191
|
+
console.log('More info: https://bit.ly/appium-v2-migration')
|
|
192
|
+
console.log('This Appium 1.x support will be removed in next major release.')
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
|
|
@@ -204,7 +206,7 @@ class Appium extends Webdriver {
|
|
|
204
206
|
}
|
|
205
207
|
}
|
|
206
208
|
}
|
|
207
|
-
`)
|
|
209
|
+
`)
|
|
208
210
|
}
|
|
209
211
|
|
|
210
212
|
// set defaults
|
|
@@ -225,166 +227,174 @@ class Appium extends Webdriver {
|
|
|
225
227
|
timeouts: {
|
|
226
228
|
script: 0, // ms
|
|
227
229
|
},
|
|
228
|
-
}
|
|
230
|
+
}
|
|
229
231
|
|
|
230
232
|
// override defaults with config
|
|
231
|
-
config = Object.assign(defaults, config)
|
|
233
|
+
config = Object.assign(defaults, config)
|
|
232
234
|
|
|
233
|
-
config.baseUrl = config.url || config.baseUrl
|
|
235
|
+
config.baseUrl = config.url || config.baseUrl
|
|
234
236
|
if (config.desiredCapabilities && Object.keys(config.desiredCapabilities).length) {
|
|
235
|
-
config.capabilities =
|
|
237
|
+
config.capabilities =
|
|
238
|
+
this.appiumV2 === true ? this._convertAppiumV2Caps(config.desiredCapabilities) : config.desiredCapabilities
|
|
236
239
|
}
|
|
237
240
|
|
|
238
241
|
if (this.appiumV2) {
|
|
239
|
-
config.capabilities[`${vendorPrefix.appium}:deviceName`] =
|
|
240
|
-
|
|
241
|
-
config.capabilities[`${vendorPrefix.appium}:
|
|
242
|
-
|
|
242
|
+
config.capabilities[`${vendorPrefix.appium}:deviceName`] =
|
|
243
|
+
config[`${vendorPrefix.appium}:device`] || config.capabilities[`${vendorPrefix.appium}:deviceName`]
|
|
244
|
+
config.capabilities[`${vendorPrefix.appium}:browserName`] =
|
|
245
|
+
config[`${vendorPrefix.appium}:browser`] || config.capabilities[`${vendorPrefix.appium}:browserName`]
|
|
246
|
+
config.capabilities[`${vendorPrefix.appium}:app`] =
|
|
247
|
+
config[`${vendorPrefix.appium}:app`] || config.capabilities[`${vendorPrefix.appium}:app`]
|
|
248
|
+
config.capabilities[`${vendorPrefix.appium}:tunnelIdentifier`] =
|
|
249
|
+
config[`${vendorPrefix.appium}:tunnelIdentifier`] ||
|
|
250
|
+
config.capabilities[`${vendorPrefix.appium}:tunnelIdentifier`] // Adding the code to connect to sauce labs via sauce tunnel
|
|
243
251
|
} else {
|
|
244
|
-
config.capabilities.deviceName = config.device || config.capabilities.deviceName
|
|
245
|
-
config.capabilities.browserName = config.browser || config.capabilities.browserName
|
|
246
|
-
config.capabilities.app = config.app || config.capabilities.app
|
|
247
|
-
config.capabilities.tunnelIdentifier = config.tunnelIdentifier || config.capabilities.tunnelIdentifier
|
|
252
|
+
config.capabilities.deviceName = config.device || config.capabilities.deviceName
|
|
253
|
+
config.capabilities.browserName = config.browser || config.capabilities.browserName
|
|
254
|
+
config.capabilities.app = config.app || config.capabilities.app
|
|
255
|
+
config.capabilities.tunnelIdentifier = config.tunnelIdentifier || config.capabilities.tunnelIdentifier // Adding the code to connect to sauce labs via sauce tunnel
|
|
248
256
|
}
|
|
249
257
|
|
|
250
|
-
config.capabilities.platformName = config.platform || config.capabilities.platformName
|
|
251
|
-
config.waitForTimeoutInSeconds = config.waitForTimeout / 1000
|
|
258
|
+
config.capabilities.platformName = config.platform || config.capabilities.platformName
|
|
259
|
+
config.waitForTimeoutInSeconds = config.waitForTimeout / 1000 // convert to seconds
|
|
252
260
|
|
|
253
261
|
// [CodeceptJS compatible] transform host to hostname
|
|
254
|
-
config.hostname = config.host || config.hostname
|
|
262
|
+
config.hostname = config.host || config.hostname
|
|
255
263
|
|
|
256
264
|
if (!config.app && config.capabilities.browserName) {
|
|
257
|
-
this.isWeb = true
|
|
258
|
-
this.root = webRoot
|
|
265
|
+
this.isWeb = true
|
|
266
|
+
this.root = webRoot
|
|
259
267
|
} else {
|
|
260
|
-
this.isWeb = false
|
|
261
|
-
this.root = mobileRoot
|
|
268
|
+
this.isWeb = false
|
|
269
|
+
this.root = mobileRoot
|
|
262
270
|
}
|
|
263
271
|
|
|
264
|
-
this.platform = null
|
|
272
|
+
this.platform = null
|
|
265
273
|
if (config.capabilities[`${vendorPrefix.appium}:platformName`]) {
|
|
266
|
-
this.platform = config.capabilities[`${vendorPrefix.appium}:platformName`].toLowerCase()
|
|
274
|
+
this.platform = config.capabilities[`${vendorPrefix.appium}:platformName`].toLowerCase()
|
|
267
275
|
}
|
|
268
276
|
|
|
269
277
|
if (config.capabilities.platformName) {
|
|
270
|
-
this.platform = config.capabilities.platformName.toLowerCase()
|
|
278
|
+
this.platform = config.capabilities.platformName.toLowerCase()
|
|
271
279
|
}
|
|
272
280
|
|
|
273
|
-
return config
|
|
281
|
+
return config
|
|
274
282
|
}
|
|
275
283
|
|
|
276
284
|
_convertAppiumV2Caps(capabilities) {
|
|
277
|
-
const _convertedCaps = {}
|
|
285
|
+
const _convertedCaps = {}
|
|
278
286
|
for (const [key, value] of Object.entries(capabilities)) {
|
|
279
287
|
if (!key.startsWith(vendorPrefix.appium)) {
|
|
280
288
|
if (key !== 'platformName' && key !== 'bstack:options') {
|
|
281
|
-
_convertedCaps[`${vendorPrefix.appium}:${key}`] = value
|
|
289
|
+
_convertedCaps[`${vendorPrefix.appium}:${key}`] = value
|
|
282
290
|
} else {
|
|
283
|
-
_convertedCaps[`${key}`] = value
|
|
291
|
+
_convertedCaps[`${key}`] = value
|
|
284
292
|
}
|
|
285
293
|
} else {
|
|
286
|
-
_convertedCaps[`${key}`] = value
|
|
294
|
+
_convertedCaps[`${key}`] = value
|
|
287
295
|
}
|
|
288
296
|
}
|
|
289
|
-
return _convertedCaps
|
|
297
|
+
return _convertedCaps
|
|
290
298
|
}
|
|
291
299
|
|
|
292
300
|
static _config() {
|
|
293
|
-
return [
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
301
|
+
return [
|
|
302
|
+
{
|
|
303
|
+
name: 'app',
|
|
304
|
+
message: 'Application package. Path to file or url',
|
|
305
|
+
default: 'http://localhost',
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
name: 'platform',
|
|
309
|
+
message: 'Mobile Platform',
|
|
310
|
+
type: 'list',
|
|
311
|
+
choices: ['iOS', supportedPlatform.android],
|
|
312
|
+
default: supportedPlatform.android,
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
name: 'device',
|
|
316
|
+
message: 'Device to run tests on',
|
|
317
|
+
default: 'emulator',
|
|
318
|
+
},
|
|
319
|
+
]
|
|
308
320
|
}
|
|
309
321
|
|
|
310
322
|
async _startBrowser() {
|
|
311
323
|
if (this.appiumV2 === true) {
|
|
312
|
-
this.options.capabilities = this._convertAppiumV2Caps(this.options.capabilities)
|
|
313
|
-
this.options.desiredCapabilities = this._convertAppiumV2Caps(this.options.desiredCapabilities)
|
|
324
|
+
this.options.capabilities = this._convertAppiumV2Caps(this.options.capabilities)
|
|
325
|
+
this.options.desiredCapabilities = this._convertAppiumV2Caps(this.options.desiredCapabilities)
|
|
314
326
|
}
|
|
315
327
|
|
|
316
328
|
try {
|
|
317
329
|
if (this.options.multiremote) {
|
|
318
|
-
this.browser = await webdriverio.multiremote(this.options.multiremote)
|
|
330
|
+
this.browser = await webdriverio.multiremote(this.options.multiremote)
|
|
319
331
|
} else {
|
|
320
|
-
this.browser = await webdriverio.remote(this.options)
|
|
332
|
+
this.browser = await webdriverio.remote(this.options)
|
|
321
333
|
}
|
|
322
334
|
} catch (err) {
|
|
323
335
|
if (err.toString().indexOf('ECONNREFUSED')) {
|
|
324
|
-
throw new ConnectionRefused(err)
|
|
336
|
+
throw new ConnectionRefused(err)
|
|
325
337
|
}
|
|
326
|
-
throw err
|
|
338
|
+
throw err
|
|
327
339
|
}
|
|
328
|
-
this.$$ = this.browser.$$.bind(this.browser)
|
|
340
|
+
this.$$ = this.browser.$$.bind(this.browser)
|
|
329
341
|
|
|
330
|
-
this.isRunning = true
|
|
342
|
+
this.isRunning = true
|
|
331
343
|
if (this.options.timeouts && this.isWeb) {
|
|
332
|
-
await this.defineTimeout(this.options.timeouts)
|
|
344
|
+
await this.defineTimeout(this.options.timeouts)
|
|
333
345
|
}
|
|
334
346
|
if (this.options.windowSize === 'maximize' && !this.platform) {
|
|
335
|
-
const res = await this.browser.execute('return [screen.width, screen.height]')
|
|
347
|
+
const res = await this.browser.execute('return [screen.width, screen.height]')
|
|
336
348
|
return this.browser.windowHandleSize({
|
|
337
349
|
width: res.value[0],
|
|
338
350
|
height: res.value[1],
|
|
339
|
-
})
|
|
351
|
+
})
|
|
340
352
|
}
|
|
341
353
|
if (this.options.windowSize && this.options.windowSize.indexOf('x') > 0 && !this.platform) {
|
|
342
|
-
const dimensions = this.options.windowSize.split('x')
|
|
354
|
+
const dimensions = this.options.windowSize.split('x')
|
|
343
355
|
await this.browser.windowHandleSize({
|
|
344
356
|
width: dimensions[0],
|
|
345
357
|
height: dimensions[1],
|
|
346
|
-
})
|
|
358
|
+
})
|
|
347
359
|
}
|
|
348
360
|
}
|
|
349
361
|
|
|
350
362
|
async _after() {
|
|
351
|
-
if (!this.isRunning) return
|
|
363
|
+
if (!this.isRunning) return
|
|
352
364
|
if (this.options.restart) {
|
|
353
|
-
this.isRunning = false
|
|
354
|
-
return this.browser.deleteSession()
|
|
365
|
+
this.isRunning = false
|
|
366
|
+
return this.browser.deleteSession()
|
|
355
367
|
}
|
|
356
368
|
if (this.isWeb && !this.platform) {
|
|
357
|
-
return super._after()
|
|
369
|
+
return super._after()
|
|
358
370
|
}
|
|
359
371
|
}
|
|
360
372
|
|
|
361
373
|
async _withinBegin(context) {
|
|
362
374
|
if (this.isWeb) {
|
|
363
|
-
return super._withinBegin(context)
|
|
375
|
+
return super._withinBegin(context)
|
|
364
376
|
}
|
|
365
377
|
if (context === 'webview') {
|
|
366
|
-
return this.switchToWeb()
|
|
378
|
+
return this.switchToWeb()
|
|
367
379
|
}
|
|
368
380
|
if (typeof context === 'object') {
|
|
369
|
-
if (context.web) return this.switchToWeb(context.web)
|
|
370
|
-
if (context.webview) return this.switchToWeb(context.webview)
|
|
381
|
+
if (context.web) return this.switchToWeb(context.web)
|
|
382
|
+
if (context.webview) return this.switchToWeb(context.webview)
|
|
371
383
|
}
|
|
372
|
-
return this.switchToContext(context)
|
|
384
|
+
return this.switchToContext(context)
|
|
373
385
|
}
|
|
374
386
|
|
|
375
387
|
_withinEnd() {
|
|
376
388
|
if (this.isWeb) {
|
|
377
|
-
return super._withinEnd()
|
|
389
|
+
return super._withinEnd()
|
|
378
390
|
}
|
|
379
|
-
return this.switchToNative()
|
|
391
|
+
return this.switchToNative()
|
|
380
392
|
}
|
|
381
393
|
|
|
382
394
|
_buildAppiumEndpoint() {
|
|
383
|
-
const {
|
|
384
|
-
protocol, port, hostname, path,
|
|
385
|
-
} = this.browser.options;
|
|
395
|
+
const { protocol, port, hostname, path } = this.browser.options
|
|
386
396
|
// Build path to Appium REST API endpoint
|
|
387
|
-
return `${protocol}://${hostname}:${port}${path}
|
|
397
|
+
return `${protocol}://${hostname}:${port}${path}`
|
|
388
398
|
}
|
|
389
399
|
|
|
390
400
|
/**
|
|
@@ -422,11 +432,11 @@ class Appium extends Webdriver {
|
|
|
422
432
|
* @param {*} fn
|
|
423
433
|
*/
|
|
424
434
|
async runOnIOS(caps, fn) {
|
|
425
|
-
if (this.platform !== 'ios') return
|
|
426
|
-
recorder.session.start('iOS-only actions')
|
|
427
|
-
await this._runWithCaps(caps, fn)
|
|
428
|
-
await recorder.add('restore from iOS session', () => recorder.session.restore())
|
|
429
|
-
return recorder.promise()
|
|
435
|
+
if (this.platform !== 'ios') return
|
|
436
|
+
recorder.session.start('iOS-only actions')
|
|
437
|
+
await this._runWithCaps(caps, fn)
|
|
438
|
+
await recorder.add('restore from iOS session', () => recorder.session.restore())
|
|
439
|
+
return recorder.promise()
|
|
430
440
|
}
|
|
431
441
|
|
|
432
442
|
/**
|
|
@@ -464,11 +474,11 @@ class Appium extends Webdriver {
|
|
|
464
474
|
* @param {*} fn
|
|
465
475
|
*/
|
|
466
476
|
async runOnAndroid(caps, fn) {
|
|
467
|
-
if (this.platform !== 'android') return
|
|
468
|
-
recorder.session.start('Android-only actions')
|
|
469
|
-
await this._runWithCaps(caps, fn)
|
|
470
|
-
await recorder.add('restore from Android session', () => recorder.session.restore())
|
|
471
|
-
return recorder.promise()
|
|
477
|
+
if (this.platform !== 'android') return
|
|
478
|
+
recorder.session.start('Android-only actions')
|
|
479
|
+
await this._runWithCaps(caps, fn)
|
|
480
|
+
await recorder.add('restore from Android session', () => recorder.session.restore())
|
|
481
|
+
return recorder.promise()
|
|
472
482
|
}
|
|
473
483
|
|
|
474
484
|
/**
|
|
@@ -485,11 +495,11 @@ class Appium extends Webdriver {
|
|
|
485
495
|
*/
|
|
486
496
|
/* eslint-disable */
|
|
487
497
|
async runInWeb(fn) {
|
|
488
|
-
if (!this.isWeb) return
|
|
489
|
-
recorder.session.start('Web-only actions')
|
|
498
|
+
if (!this.isWeb) return
|
|
499
|
+
recorder.session.start('Web-only actions')
|
|
490
500
|
|
|
491
|
-
recorder.add('restore from Web session', () => recorder.session.restore(), true)
|
|
492
|
-
return recorder.promise()
|
|
501
|
+
recorder.add('restore from Web session', () => recorder.session.restore(), true)
|
|
502
|
+
return recorder.promise()
|
|
493
503
|
}
|
|
494
504
|
/* eslint-enable */
|
|
495
505
|
|
|
@@ -498,21 +508,21 @@ class Appium extends Webdriver {
|
|
|
498
508
|
for (const key in caps) {
|
|
499
509
|
// skip if capabilities do not match
|
|
500
510
|
if (this.config.desiredCapabilities[key] !== caps[key]) {
|
|
501
|
-
return
|
|
511
|
+
return
|
|
502
512
|
}
|
|
503
513
|
}
|
|
504
514
|
}
|
|
505
515
|
if (typeof caps === 'function') {
|
|
506
516
|
if (!fn) {
|
|
507
|
-
fn = caps
|
|
517
|
+
fn = caps
|
|
508
518
|
} else {
|
|
509
519
|
// skip if capabilities are checked inside a function
|
|
510
|
-
const enabled = caps(this.config.desiredCapabilities)
|
|
511
|
-
if (!enabled) return
|
|
520
|
+
const enabled = caps(this.config.desiredCapabilities)
|
|
521
|
+
if (!enabled) return
|
|
512
522
|
}
|
|
513
523
|
}
|
|
514
524
|
|
|
515
|
-
fn()
|
|
525
|
+
fn()
|
|
516
526
|
}
|
|
517
527
|
|
|
518
528
|
/**
|
|
@@ -528,9 +538,9 @@ class Appium extends Webdriver {
|
|
|
528
538
|
* Appium: support only Android
|
|
529
539
|
*/
|
|
530
540
|
async checkIfAppIsInstalled(bundleId) {
|
|
531
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
541
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
532
542
|
|
|
533
|
-
return this.browser.isAppInstalled(bundleId)
|
|
543
|
+
return this.browser.isAppInstalled(bundleId)
|
|
534
544
|
}
|
|
535
545
|
|
|
536
546
|
/**
|
|
@@ -546,9 +556,9 @@ class Appium extends Webdriver {
|
|
|
546
556
|
* Appium: support only Android
|
|
547
557
|
*/
|
|
548
558
|
async seeAppIsInstalled(bundleId) {
|
|
549
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
550
|
-
const res = await this.browser.isAppInstalled(bundleId)
|
|
551
|
-
return truth(`app ${bundleId}`, 'to be installed').assert(res)
|
|
559
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
560
|
+
const res = await this.browser.isAppInstalled(bundleId)
|
|
561
|
+
return truth(`app ${bundleId}`, 'to be installed').assert(res)
|
|
552
562
|
}
|
|
553
563
|
|
|
554
564
|
/**
|
|
@@ -564,9 +574,9 @@ class Appium extends Webdriver {
|
|
|
564
574
|
* Appium: support only Android
|
|
565
575
|
*/
|
|
566
576
|
async seeAppIsNotInstalled(bundleId) {
|
|
567
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
568
|
-
const res = await this.browser.isAppInstalled(bundleId)
|
|
569
|
-
return truth(`app ${bundleId}`, 'not to be installed').negate(res)
|
|
577
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
578
|
+
const res = await this.browser.isAppInstalled(bundleId)
|
|
579
|
+
return truth(`app ${bundleId}`, 'not to be installed').negate(res)
|
|
570
580
|
}
|
|
571
581
|
|
|
572
582
|
/**
|
|
@@ -581,8 +591,8 @@ class Appium extends Webdriver {
|
|
|
581
591
|
* Appium: support only Android
|
|
582
592
|
*/
|
|
583
593
|
async installApp(path) {
|
|
584
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
585
|
-
return this.browser.installApp(path)
|
|
594
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
595
|
+
return this.browser.installApp(path)
|
|
586
596
|
}
|
|
587
597
|
|
|
588
598
|
/**
|
|
@@ -598,13 +608,13 @@ class Appium extends Webdriver {
|
|
|
598
608
|
* @param {string} [bundleId] ID of bundle
|
|
599
609
|
*/
|
|
600
610
|
async removeApp(appId, bundleId) {
|
|
601
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
611
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
602
612
|
|
|
603
613
|
return this.axios({
|
|
604
614
|
method: 'post',
|
|
605
615
|
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/appium/device/remove_app`,
|
|
606
616
|
data: { appId, bundleId },
|
|
607
|
-
})
|
|
617
|
+
})
|
|
608
618
|
}
|
|
609
619
|
|
|
610
620
|
/**
|
|
@@ -616,11 +626,11 @@ class Appium extends Webdriver {
|
|
|
616
626
|
*
|
|
617
627
|
*/
|
|
618
628
|
async resetApp() {
|
|
619
|
-
onlyForApps.call(this)
|
|
629
|
+
onlyForApps.call(this)
|
|
620
630
|
return this.axios({
|
|
621
631
|
method: 'post',
|
|
622
632
|
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/appium/app/reset`,
|
|
623
|
-
})
|
|
633
|
+
})
|
|
624
634
|
}
|
|
625
635
|
|
|
626
636
|
/**
|
|
@@ -635,9 +645,9 @@ class Appium extends Webdriver {
|
|
|
635
645
|
* Appium: support only Android
|
|
636
646
|
*/
|
|
637
647
|
async seeCurrentActivityIs(currentActivity) {
|
|
638
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
639
|
-
const res = await this.browser.getCurrentActivity()
|
|
640
|
-
return truth('current activity', `to be ${currentActivity}`).assert(res === currentActivity)
|
|
648
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
649
|
+
const res = await this.browser.getCurrentActivity()
|
|
650
|
+
return truth('current activity', `to be ${currentActivity}`).assert(res === currentActivity)
|
|
641
651
|
}
|
|
642
652
|
|
|
643
653
|
/**
|
|
@@ -652,9 +662,9 @@ class Appium extends Webdriver {
|
|
|
652
662
|
* Appium: support only Android
|
|
653
663
|
*/
|
|
654
664
|
async seeDeviceIsLocked() {
|
|
655
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
656
|
-
const res = await this.browser.isLocked()
|
|
657
|
-
return truth('device', 'to be locked').assert(res)
|
|
665
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
666
|
+
const res = await this.browser.isLocked()
|
|
667
|
+
return truth('device', 'to be locked').assert(res)
|
|
658
668
|
}
|
|
659
669
|
|
|
660
670
|
/**
|
|
@@ -669,9 +679,9 @@ class Appium extends Webdriver {
|
|
|
669
679
|
* Appium: support only Android
|
|
670
680
|
*/
|
|
671
681
|
async seeDeviceIsUnlocked() {
|
|
672
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
673
|
-
const res = await this.browser.isLocked()
|
|
674
|
-
return truth('device', 'to be locked').negate(res)
|
|
682
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
683
|
+
const res = await this.browser.isLocked()
|
|
684
|
+
return truth('device', 'to be locked').negate(res)
|
|
675
685
|
}
|
|
676
686
|
|
|
677
687
|
/**
|
|
@@ -689,15 +699,15 @@ class Appium extends Webdriver {
|
|
|
689
699
|
* Appium: support Android and iOS
|
|
690
700
|
*/
|
|
691
701
|
async seeOrientationIs(orientation) {
|
|
692
|
-
onlyForApps.call(this)
|
|
702
|
+
onlyForApps.call(this)
|
|
693
703
|
|
|
694
704
|
const res = await this.axios({
|
|
695
705
|
method: 'get',
|
|
696
706
|
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/orientation`,
|
|
697
|
-
})
|
|
707
|
+
})
|
|
698
708
|
|
|
699
|
-
const currentOrientation = res.data.value
|
|
700
|
-
return truth('orientation', `to be ${orientation}`).assert(currentOrientation === orientation)
|
|
709
|
+
const currentOrientation = res.data.value
|
|
710
|
+
return truth('orientation', `to be ${orientation}`).assert(currentOrientation === orientation)
|
|
701
711
|
}
|
|
702
712
|
|
|
703
713
|
/**
|
|
@@ -713,13 +723,13 @@ class Appium extends Webdriver {
|
|
|
713
723
|
* Appium: support Android and iOS
|
|
714
724
|
*/
|
|
715
725
|
async setOrientation(orientation) {
|
|
716
|
-
onlyForApps.call(this)
|
|
726
|
+
onlyForApps.call(this)
|
|
717
727
|
|
|
718
728
|
return this.axios({
|
|
719
729
|
method: 'post',
|
|
720
730
|
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/orientation`,
|
|
721
731
|
data: { orientation },
|
|
722
|
-
})
|
|
732
|
+
})
|
|
723
733
|
}
|
|
724
734
|
|
|
725
735
|
/**
|
|
@@ -734,8 +744,8 @@ class Appium extends Webdriver {
|
|
|
734
744
|
* Appium: support Android and iOS
|
|
735
745
|
*/
|
|
736
746
|
async grabAllContexts() {
|
|
737
|
-
onlyForApps.call(this)
|
|
738
|
-
return this.browser.getContexts()
|
|
747
|
+
onlyForApps.call(this)
|
|
748
|
+
return this.browser.getContexts()
|
|
739
749
|
}
|
|
740
750
|
|
|
741
751
|
/**
|
|
@@ -750,8 +760,8 @@ class Appium extends Webdriver {
|
|
|
750
760
|
* Appium: support Android and iOS
|
|
751
761
|
*/
|
|
752
762
|
async grabContext() {
|
|
753
|
-
onlyForApps.call(this)
|
|
754
|
-
return this.browser.getContext()
|
|
763
|
+
onlyForApps.call(this)
|
|
764
|
+
return this.browser.getContext()
|
|
755
765
|
}
|
|
756
766
|
|
|
757
767
|
/**
|
|
@@ -766,8 +776,8 @@ class Appium extends Webdriver {
|
|
|
766
776
|
* Appium: support only Android
|
|
767
777
|
*/
|
|
768
778
|
async grabCurrentActivity() {
|
|
769
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
770
|
-
return this.browser.getCurrentActivity()
|
|
779
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
780
|
+
return this.browser.getCurrentActivity()
|
|
771
781
|
}
|
|
772
782
|
|
|
773
783
|
/**
|
|
@@ -784,14 +794,14 @@ class Appium extends Webdriver {
|
|
|
784
794
|
* Appium: support only Android
|
|
785
795
|
*/
|
|
786
796
|
async grabNetworkConnection() {
|
|
787
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
788
|
-
const res = await this.browser.getNetworkConnection()
|
|
797
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
798
|
+
const res = await this.browser.getNetworkConnection()
|
|
789
799
|
return {
|
|
790
800
|
value: res,
|
|
791
801
|
inAirplaneMode: res.inAirplaneMode,
|
|
792
802
|
hasWifi: res.hasWifi,
|
|
793
803
|
hasData: res.hasData,
|
|
794
|
-
}
|
|
804
|
+
}
|
|
795
805
|
}
|
|
796
806
|
|
|
797
807
|
/**
|
|
@@ -806,10 +816,10 @@ class Appium extends Webdriver {
|
|
|
806
816
|
* Appium: support Android and iOS
|
|
807
817
|
*/
|
|
808
818
|
async grabOrientation() {
|
|
809
|
-
onlyForApps.call(this)
|
|
810
|
-
const res = await this.browser.orientation()
|
|
811
|
-
this.debugSection('Orientation', res)
|
|
812
|
-
return res
|
|
819
|
+
onlyForApps.call(this)
|
|
820
|
+
const res = await this.browser.orientation()
|
|
821
|
+
this.debugSection('Orientation', res)
|
|
822
|
+
return res
|
|
813
823
|
}
|
|
814
824
|
|
|
815
825
|
/**
|
|
@@ -824,10 +834,10 @@ class Appium extends Webdriver {
|
|
|
824
834
|
* Appium: support Android and iOS
|
|
825
835
|
*/
|
|
826
836
|
async grabSettings() {
|
|
827
|
-
onlyForApps.call(this)
|
|
828
|
-
const res = await this.browser.getSettings()
|
|
829
|
-
this.debugSection('Settings', JSON.stringify(res))
|
|
830
|
-
return res
|
|
837
|
+
onlyForApps.call(this)
|
|
838
|
+
const res = await this.browser.getSettings()
|
|
839
|
+
this.debugSection('Settings', JSON.stringify(res))
|
|
840
|
+
return res
|
|
831
841
|
}
|
|
832
842
|
|
|
833
843
|
/**
|
|
@@ -836,7 +846,7 @@ class Appium extends Webdriver {
|
|
|
836
846
|
* @param {*} context the context to switch to
|
|
837
847
|
*/
|
|
838
848
|
async switchToContext(context) {
|
|
839
|
-
return this.browser.switchContext(context)
|
|
849
|
+
return this.browser.switchContext(context)
|
|
840
850
|
}
|
|
841
851
|
|
|
842
852
|
/**
|
|
@@ -856,17 +866,17 @@ class Appium extends Webdriver {
|
|
|
856
866
|
* @param {string} [context]
|
|
857
867
|
*/
|
|
858
868
|
async switchToWeb(context) {
|
|
859
|
-
this.isWeb = true
|
|
860
|
-
this.defaultContext = 'body'
|
|
869
|
+
this.isWeb = true
|
|
870
|
+
this.defaultContext = 'body'
|
|
861
871
|
|
|
862
|
-
if (context) return this.switchToContext(context)
|
|
863
|
-
const contexts = await this.grabAllContexts()
|
|
864
|
-
this.debugSection('Contexts', contexts.toString())
|
|
872
|
+
if (context) return this.switchToContext(context)
|
|
873
|
+
const contexts = await this.grabAllContexts()
|
|
874
|
+
this.debugSection('Contexts', contexts.toString())
|
|
865
875
|
for (const idx in contexts) {
|
|
866
|
-
if (contexts[idx].match(/^WEBVIEW/)) return this.switchToContext(contexts[idx])
|
|
876
|
+
if (contexts[idx].match(/^WEBVIEW/)) return this.switchToContext(contexts[idx])
|
|
867
877
|
}
|
|
868
878
|
|
|
869
|
-
throw new Error('No WEBVIEW could be guessed, please specify one in params')
|
|
879
|
+
throw new Error('No WEBVIEW could be guessed, please specify one in params')
|
|
870
880
|
}
|
|
871
881
|
|
|
872
882
|
/**
|
|
@@ -883,11 +893,11 @@ class Appium extends Webdriver {
|
|
|
883
893
|
* @return {Promise<void>}
|
|
884
894
|
*/
|
|
885
895
|
async switchToNative(context = null) {
|
|
886
|
-
this.isWeb = false
|
|
887
|
-
this.defaultContext = '//*'
|
|
896
|
+
this.isWeb = false
|
|
897
|
+
this.defaultContext = '//*'
|
|
888
898
|
|
|
889
|
-
if (context) return this.switchToContext(context)
|
|
890
|
-
return this.switchToContext('NATIVE_APP')
|
|
899
|
+
if (context) return this.switchToContext(context)
|
|
900
|
+
return this.switchToContext('NATIVE_APP')
|
|
891
901
|
}
|
|
892
902
|
|
|
893
903
|
/**
|
|
@@ -904,8 +914,8 @@ class Appium extends Webdriver {
|
|
|
904
914
|
* @return {Promise<void>}
|
|
905
915
|
*/
|
|
906
916
|
async startActivity(appPackage, appActivity) {
|
|
907
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
908
|
-
return this.browser.startActivity(appPackage, appActivity)
|
|
917
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
918
|
+
return this.browser.startActivity(appPackage, appActivity)
|
|
909
919
|
}
|
|
910
920
|
|
|
911
921
|
/**
|
|
@@ -930,8 +940,8 @@ class Appium extends Webdriver {
|
|
|
930
940
|
* @return {Promise<number>}
|
|
931
941
|
*/
|
|
932
942
|
async setNetworkConnection(value) {
|
|
933
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
934
|
-
return this.browser.setNetworkConnection(value)
|
|
943
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
944
|
+
return this.browser.setNetworkConnection(value)
|
|
935
945
|
}
|
|
936
946
|
|
|
937
947
|
/**
|
|
@@ -946,8 +956,8 @@ class Appium extends Webdriver {
|
|
|
946
956
|
* Appium: support Android and iOS
|
|
947
957
|
*/
|
|
948
958
|
async setSettings(settings) {
|
|
949
|
-
onlyForApps.call(this)
|
|
950
|
-
return this.browser.settings(settings)
|
|
959
|
+
onlyForApps.call(this)
|
|
960
|
+
return this.browser.settings(settings)
|
|
951
961
|
}
|
|
952
962
|
|
|
953
963
|
/**
|
|
@@ -968,9 +978,9 @@ class Appium extends Webdriver {
|
|
|
968
978
|
* @param {string} [key] Optional key
|
|
969
979
|
*/
|
|
970
980
|
async hideDeviceKeyboard(strategy, key) {
|
|
971
|
-
onlyForApps.call(this)
|
|
972
|
-
strategy = strategy || 'tapOutside'
|
|
973
|
-
return this.browser.hideKeyboard(strategy, key)
|
|
981
|
+
onlyForApps.call(this)
|
|
982
|
+
strategy = strategy || 'tapOutside'
|
|
983
|
+
return this.browser.hideKeyboard(strategy, key)
|
|
974
984
|
}
|
|
975
985
|
|
|
976
986
|
/**
|
|
@@ -987,8 +997,8 @@ class Appium extends Webdriver {
|
|
|
987
997
|
* Appium: support only Android
|
|
988
998
|
*/
|
|
989
999
|
async sendDeviceKeyEvent(keyValue) {
|
|
990
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
991
|
-
return this.browser.pressKeyCode(keyValue)
|
|
1000
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
1001
|
+
return this.browser.pressKeyCode(keyValue)
|
|
992
1002
|
}
|
|
993
1003
|
|
|
994
1004
|
/**
|
|
@@ -1003,8 +1013,8 @@ class Appium extends Webdriver {
|
|
|
1003
1013
|
* Appium: support only Android
|
|
1004
1014
|
*/
|
|
1005
1015
|
async openNotifications() {
|
|
1006
|
-
onlyForApps.call(this, supportedPlatform.android)
|
|
1007
|
-
return this.browser.openNotifications()
|
|
1016
|
+
onlyForApps.call(this, supportedPlatform.android)
|
|
1017
|
+
return this.browser.openNotifications()
|
|
1008
1018
|
}
|
|
1009
1019
|
|
|
1010
1020
|
/**
|
|
@@ -1023,13 +1033,13 @@ class Appium extends Webdriver {
|
|
|
1023
1033
|
* Appium: support Android and iOS
|
|
1024
1034
|
*/
|
|
1025
1035
|
async makeTouchAction(locator, action) {
|
|
1026
|
-
onlyForApps.call(this)
|
|
1027
|
-
const element = await this.browser.$(parseLocator.call(this, locator))
|
|
1036
|
+
onlyForApps.call(this)
|
|
1037
|
+
const element = await this.browser.$(parseLocator.call(this, locator))
|
|
1028
1038
|
|
|
1029
1039
|
return this.browser.touchAction({
|
|
1030
1040
|
action,
|
|
1031
1041
|
element,
|
|
1032
|
-
})
|
|
1042
|
+
})
|
|
1033
1043
|
}
|
|
1034
1044
|
|
|
1035
1045
|
/**
|
|
@@ -1046,7 +1056,7 @@ class Appium extends Webdriver {
|
|
|
1046
1056
|
* @param {*} locator
|
|
1047
1057
|
*/
|
|
1048
1058
|
async tap(locator) {
|
|
1049
|
-
return this.makeTouchAction(locator, 'tap')
|
|
1059
|
+
return this.makeTouchAction(locator, 'tap')
|
|
1050
1060
|
}
|
|
1051
1061
|
|
|
1052
1062
|
/**
|
|
@@ -1069,10 +1079,13 @@ class Appium extends Webdriver {
|
|
|
1069
1079
|
*/
|
|
1070
1080
|
/* eslint-disable */
|
|
1071
1081
|
async swipe(locator, xoffset, yoffset, speed = 1000) {
|
|
1072
|
-
onlyForApps.call(this)
|
|
1073
|
-
const res = await this.browser.$(parseLocator.call(this, locator))
|
|
1082
|
+
onlyForApps.call(this)
|
|
1083
|
+
const res = await this.browser.$(parseLocator.call(this, locator))
|
|
1074
1084
|
// if (!res.length) throw new ElementNotFound(locator, 'was not found in UI');
|
|
1075
|
-
return this.performSwipe(await res.getLocation(), {
|
|
1085
|
+
return this.performSwipe(await res.getLocation(), {
|
|
1086
|
+
x: (await res.getLocation()).x + xoffset,
|
|
1087
|
+
y: (await res.getLocation()).y + yoffset,
|
|
1088
|
+
})
|
|
1076
1089
|
}
|
|
1077
1090
|
/* eslint-enable */
|
|
1078
1091
|
|
|
@@ -1089,42 +1102,44 @@ class Appium extends Webdriver {
|
|
|
1089
1102
|
* Appium: support Android and iOS
|
|
1090
1103
|
*/
|
|
1091
1104
|
async performSwipe(from, to) {
|
|
1092
|
-
await this.browser.performActions([
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
actions: [
|
|
1099
|
-
{
|
|
1100
|
-
duration: 0,
|
|
1101
|
-
x: from.x,
|
|
1102
|
-
y: from.y,
|
|
1103
|
-
type: 'pointerMove',
|
|
1104
|
-
origin: 'viewport',
|
|
1105
|
-
},
|
|
1106
|
-
{
|
|
1107
|
-
button: 1,
|
|
1108
|
-
type: 'pointerDown',
|
|
1109
|
-
},
|
|
1110
|
-
{
|
|
1111
|
-
duration: 200,
|
|
1112
|
-
type: 'pause',
|
|
1113
|
-
},
|
|
1114
|
-
{
|
|
1115
|
-
duration: 600,
|
|
1116
|
-
x: to.x,
|
|
1117
|
-
y: to.y,
|
|
1118
|
-
type: 'pointerMove',
|
|
1119
|
-
origin: 'viewport',
|
|
1120
|
-
},
|
|
1121
|
-
{
|
|
1122
|
-
button: 1,
|
|
1123
|
-
type: 'pointerUp',
|
|
1105
|
+
await this.browser.performActions([
|
|
1106
|
+
{
|
|
1107
|
+
id: uuidv4(),
|
|
1108
|
+
type: 'pointer',
|
|
1109
|
+
parameters: {
|
|
1110
|
+
pointerType: 'touch',
|
|
1124
1111
|
},
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1112
|
+
actions: [
|
|
1113
|
+
{
|
|
1114
|
+
duration: 0,
|
|
1115
|
+
x: from.x,
|
|
1116
|
+
y: from.y,
|
|
1117
|
+
type: 'pointerMove',
|
|
1118
|
+
origin: 'viewport',
|
|
1119
|
+
},
|
|
1120
|
+
{
|
|
1121
|
+
button: 1,
|
|
1122
|
+
type: 'pointerDown',
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
duration: 200,
|
|
1126
|
+
type: 'pause',
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
duration: 600,
|
|
1130
|
+
x: to.x,
|
|
1131
|
+
y: to.y,
|
|
1132
|
+
type: 'pointerMove',
|
|
1133
|
+
origin: 'viewport',
|
|
1134
|
+
},
|
|
1135
|
+
{
|
|
1136
|
+
button: 1,
|
|
1137
|
+
type: 'pointerUp',
|
|
1138
|
+
},
|
|
1139
|
+
],
|
|
1140
|
+
},
|
|
1141
|
+
])
|
|
1142
|
+
await this.browser.pause(1000)
|
|
1128
1143
|
}
|
|
1129
1144
|
|
|
1130
1145
|
/**
|
|
@@ -1145,14 +1160,14 @@ class Appium extends Webdriver {
|
|
|
1145
1160
|
* Appium: support Android and iOS
|
|
1146
1161
|
*/
|
|
1147
1162
|
async swipeDown(locator, yoffset = 1000, speed) {
|
|
1148
|
-
onlyForApps.call(this)
|
|
1163
|
+
onlyForApps.call(this)
|
|
1149
1164
|
|
|
1150
1165
|
if (!speed) {
|
|
1151
|
-
speed = yoffset
|
|
1152
|
-
yoffset = 100
|
|
1166
|
+
speed = yoffset
|
|
1167
|
+
yoffset = 100
|
|
1153
1168
|
}
|
|
1154
1169
|
|
|
1155
|
-
return this.swipe(parseLocator.call(this, locator), 0, yoffset, speed)
|
|
1170
|
+
return this.swipe(parseLocator.call(this, locator), 0, yoffset, speed)
|
|
1156
1171
|
}
|
|
1157
1172
|
|
|
1158
1173
|
/**
|
|
@@ -1174,13 +1189,13 @@ class Appium extends Webdriver {
|
|
|
1174
1189
|
* Appium: support Android and iOS
|
|
1175
1190
|
*/
|
|
1176
1191
|
async swipeLeft(locator, xoffset = 1000, speed) {
|
|
1177
|
-
onlyForApps.call(this)
|
|
1192
|
+
onlyForApps.call(this)
|
|
1178
1193
|
if (!speed) {
|
|
1179
|
-
speed = xoffset
|
|
1180
|
-
xoffset = 100
|
|
1194
|
+
speed = xoffset
|
|
1195
|
+
xoffset = 100
|
|
1181
1196
|
}
|
|
1182
1197
|
|
|
1183
|
-
return this.swipe(parseLocator.call(this, locator), -xoffset, 0, speed)
|
|
1198
|
+
return this.swipe(parseLocator.call(this, locator), -xoffset, 0, speed)
|
|
1184
1199
|
}
|
|
1185
1200
|
|
|
1186
1201
|
/**
|
|
@@ -1201,13 +1216,13 @@ class Appium extends Webdriver {
|
|
|
1201
1216
|
* Appium: support Android and iOS
|
|
1202
1217
|
*/
|
|
1203
1218
|
async swipeRight(locator, xoffset = 1000, speed) {
|
|
1204
|
-
onlyForApps.call(this)
|
|
1219
|
+
onlyForApps.call(this)
|
|
1205
1220
|
if (!speed) {
|
|
1206
|
-
speed = xoffset
|
|
1207
|
-
xoffset = 100
|
|
1221
|
+
speed = xoffset
|
|
1222
|
+
xoffset = 100
|
|
1208
1223
|
}
|
|
1209
1224
|
|
|
1210
|
-
return this.swipe(parseLocator.call(this, locator), xoffset, 0, speed)
|
|
1225
|
+
return this.swipe(parseLocator.call(this, locator), xoffset, 0, speed)
|
|
1211
1226
|
}
|
|
1212
1227
|
|
|
1213
1228
|
/**
|
|
@@ -1228,14 +1243,14 @@ class Appium extends Webdriver {
|
|
|
1228
1243
|
* Appium: support Android and iOS
|
|
1229
1244
|
*/
|
|
1230
1245
|
async swipeUp(locator, yoffset = 1000, speed) {
|
|
1231
|
-
onlyForApps.call(this)
|
|
1246
|
+
onlyForApps.call(this)
|
|
1232
1247
|
|
|
1233
1248
|
if (!speed) {
|
|
1234
|
-
speed = yoffset
|
|
1235
|
-
yoffset = 100
|
|
1249
|
+
speed = yoffset
|
|
1250
|
+
yoffset = 100
|
|
1236
1251
|
}
|
|
1237
1252
|
|
|
1238
|
-
return this.swipe(parseLocator.call(this, locator), 0, -yoffset, speed)
|
|
1253
|
+
return this.swipe(parseLocator.call(this, locator), 0, -yoffset, speed)
|
|
1239
1254
|
}
|
|
1240
1255
|
|
|
1241
1256
|
/**
|
|
@@ -1262,55 +1277,66 @@ class Appium extends Webdriver {
|
|
|
1262
1277
|
* Appium: support Android and iOS
|
|
1263
1278
|
*/
|
|
1264
1279
|
async swipeTo(searchableLocator, scrollLocator, direction, timeout, offset, speed) {
|
|
1265
|
-
onlyForApps.call(this)
|
|
1266
|
-
direction = direction || 'down'
|
|
1280
|
+
onlyForApps.call(this)
|
|
1281
|
+
direction = direction || 'down'
|
|
1267
1282
|
switch (direction) {
|
|
1268
1283
|
case 'down':
|
|
1269
|
-
direction = 'swipeDown'
|
|
1270
|
-
break
|
|
1284
|
+
direction = 'swipeDown'
|
|
1285
|
+
break
|
|
1271
1286
|
case 'up':
|
|
1272
|
-
direction = 'swipeUp'
|
|
1273
|
-
break
|
|
1287
|
+
direction = 'swipeUp'
|
|
1288
|
+
break
|
|
1274
1289
|
case 'left':
|
|
1275
|
-
direction = 'swipeLeft'
|
|
1276
|
-
break
|
|
1290
|
+
direction = 'swipeLeft'
|
|
1291
|
+
break
|
|
1277
1292
|
case 'right':
|
|
1278
|
-
direction = 'swipeRight'
|
|
1279
|
-
break
|
|
1293
|
+
direction = 'swipeRight'
|
|
1294
|
+
break
|
|
1280
1295
|
}
|
|
1281
|
-
timeout = timeout || this.options.waitForTimeoutInSeconds
|
|
1282
|
-
|
|
1283
|
-
const errorMsg = `element ("${searchableLocator}") still not visible after ${timeout}seconds
|
|
1284
|
-
const browser = this.browser
|
|
1285
|
-
let err = false
|
|
1286
|
-
let currentSource
|
|
1287
|
-
return browser
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
.then(els => els.length && els[0].isDisplayed())
|
|
1293
|
-
.then((res) => {
|
|
1294
|
-
if (res) {
|
|
1295
|
-
return true;
|
|
1296
|
+
timeout = timeout || this.options.waitForTimeoutInSeconds
|
|
1297
|
+
|
|
1298
|
+
const errorMsg = `element ("${searchableLocator}") still not visible after ${timeout}seconds`
|
|
1299
|
+
const browser = this.browser
|
|
1300
|
+
let err = false
|
|
1301
|
+
let currentSource
|
|
1302
|
+
return browser
|
|
1303
|
+
.waitUntil(
|
|
1304
|
+
() => {
|
|
1305
|
+
if (err) {
|
|
1306
|
+
return new Error(`Scroll to the end and element ${searchableLocator} was not found`)
|
|
1296
1307
|
}
|
|
1297
|
-
return
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1308
|
+
return browser
|
|
1309
|
+
.$$(parseLocator.call(this, searchableLocator))
|
|
1310
|
+
.then((els) => els.length && els[0].isDisplayed())
|
|
1311
|
+
.then((res) => {
|
|
1312
|
+
if (res) {
|
|
1313
|
+
return true
|
|
1314
|
+
}
|
|
1315
|
+
return this[direction](scrollLocator, offset, speed)
|
|
1316
|
+
.getSource()
|
|
1317
|
+
.then((source) => {
|
|
1318
|
+
if (source === currentSource) {
|
|
1319
|
+
err = true
|
|
1320
|
+
} else {
|
|
1321
|
+
currentSource = source
|
|
1322
|
+
return false
|
|
1323
|
+
}
|
|
1324
|
+
})
|
|
1325
|
+
})
|
|
1326
|
+
},
|
|
1327
|
+
timeout * 1000,
|
|
1328
|
+
errorMsg,
|
|
1329
|
+
)
|
|
1307
1330
|
.catch((e) => {
|
|
1308
1331
|
if (e.message.indexOf('timeout') && e.type !== 'NoSuchElement') {
|
|
1309
|
-
throw new AssertionFailedError(
|
|
1332
|
+
throw new AssertionFailedError(
|
|
1333
|
+
{ customMessage: `Scroll to the end and element ${searchableLocator} was not found` },
|
|
1334
|
+
'',
|
|
1335
|
+
)
|
|
1310
1336
|
} else {
|
|
1311
|
-
throw e
|
|
1337
|
+
throw e
|
|
1312
1338
|
}
|
|
1313
|
-
})
|
|
1339
|
+
})
|
|
1314
1340
|
}
|
|
1315
1341
|
|
|
1316
1342
|
/**
|
|
@@ -1342,8 +1368,8 @@ class Appium extends Webdriver {
|
|
|
1342
1368
|
* @param {Array} actions Array of touch actions
|
|
1343
1369
|
*/
|
|
1344
1370
|
async touchPerform(actions) {
|
|
1345
|
-
onlyForApps.call(this)
|
|
1346
|
-
return this.browser.touchPerform(actions)
|
|
1371
|
+
onlyForApps.call(this)
|
|
1372
|
+
return this.browser.touchPerform(actions)
|
|
1347
1373
|
}
|
|
1348
1374
|
|
|
1349
1375
|
/**
|
|
@@ -1362,13 +1388,15 @@ class Appium extends Webdriver {
|
|
|
1362
1388
|
* Appium: support Android and iOS
|
|
1363
1389
|
*/
|
|
1364
1390
|
async pullFile(path, dest) {
|
|
1365
|
-
onlyForApps.call(this)
|
|
1366
|
-
return this.browser.pullFile(path).then(
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1391
|
+
onlyForApps.call(this)
|
|
1392
|
+
return this.browser.pullFile(path).then((res) =>
|
|
1393
|
+
fs.writeFile(dest, Buffer.from(res, 'base64'), (err) => {
|
|
1394
|
+
if (err) {
|
|
1395
|
+
return false
|
|
1396
|
+
}
|
|
1397
|
+
return true
|
|
1398
|
+
}),
|
|
1399
|
+
)
|
|
1372
1400
|
}
|
|
1373
1401
|
|
|
1374
1402
|
/**
|
|
@@ -1383,8 +1411,8 @@ class Appium extends Webdriver {
|
|
|
1383
1411
|
* Appium: support only iOS
|
|
1384
1412
|
*/
|
|
1385
1413
|
async shakeDevice() {
|
|
1386
|
-
onlyForApps.call(this, 'iOS')
|
|
1387
|
-
return this.browser.shake()
|
|
1414
|
+
onlyForApps.call(this, 'iOS')
|
|
1415
|
+
return this.browser.shake()
|
|
1388
1416
|
}
|
|
1389
1417
|
|
|
1390
1418
|
/**
|
|
@@ -1401,8 +1429,8 @@ class Appium extends Webdriver {
|
|
|
1401
1429
|
* Appium: support only iOS
|
|
1402
1430
|
*/
|
|
1403
1431
|
async rotate(x, y, duration, radius, rotation, touchCount) {
|
|
1404
|
-
onlyForApps.call(this, 'iOS')
|
|
1405
|
-
return this.browser.rotate(x, y, duration, radius, rotation, touchCount)
|
|
1432
|
+
onlyForApps.call(this, 'iOS')
|
|
1433
|
+
return this.browser.rotate(x, y, duration, radius, rotation, touchCount)
|
|
1406
1434
|
}
|
|
1407
1435
|
|
|
1408
1436
|
/**
|
|
@@ -1415,8 +1443,8 @@ class Appium extends Webdriver {
|
|
|
1415
1443
|
* Appium: support only iOS
|
|
1416
1444
|
*/
|
|
1417
1445
|
async setImmediateValue(id, value) {
|
|
1418
|
-
onlyForApps.call(this, 'iOS')
|
|
1419
|
-
return this.browser.setImmediateValue(id, value)
|
|
1446
|
+
onlyForApps.call(this, 'iOS')
|
|
1447
|
+
return this.browser.setImmediateValue(id, value)
|
|
1420
1448
|
}
|
|
1421
1449
|
|
|
1422
1450
|
/**
|
|
@@ -1434,9 +1462,9 @@ class Appium extends Webdriver {
|
|
|
1434
1462
|
* TODO: not tested
|
|
1435
1463
|
*/
|
|
1436
1464
|
async simulateTouchId(match) {
|
|
1437
|
-
onlyForApps.call(this, 'iOS')
|
|
1438
|
-
match = match || true
|
|
1439
|
-
return this.browser.touchId(match)
|
|
1465
|
+
onlyForApps.call(this, 'iOS')
|
|
1466
|
+
match = match || true
|
|
1467
|
+
return this.browser.touchId(match)
|
|
1440
1468
|
}
|
|
1441
1469
|
|
|
1442
1470
|
/**
|
|
@@ -1451,8 +1479,8 @@ class Appium extends Webdriver {
|
|
|
1451
1479
|
* Appium: support both Android and iOS
|
|
1452
1480
|
*/
|
|
1453
1481
|
async closeApp() {
|
|
1454
|
-
onlyForApps.call(this)
|
|
1455
|
-
return this.browser.closeApp()
|
|
1482
|
+
onlyForApps.call(this)
|
|
1483
|
+
return this.browser.closeApp()
|
|
1456
1484
|
}
|
|
1457
1485
|
|
|
1458
1486
|
/**
|
|
@@ -1460,8 +1488,8 @@ class Appium extends Webdriver {
|
|
|
1460
1488
|
*
|
|
1461
1489
|
*/
|
|
1462
1490
|
async appendField(field, value) {
|
|
1463
|
-
if (this.isWeb) return super.appendField(field, value)
|
|
1464
|
-
return super.appendField(parseLocator.call(this, field), value)
|
|
1491
|
+
if (this.isWeb) return super.appendField(field, value)
|
|
1492
|
+
return super.appendField(parseLocator.call(this, field), value)
|
|
1465
1493
|
}
|
|
1466
1494
|
|
|
1467
1495
|
/**
|
|
@@ -1469,8 +1497,8 @@ class Appium extends Webdriver {
|
|
|
1469
1497
|
*
|
|
1470
1498
|
*/
|
|
1471
1499
|
async checkOption(field) {
|
|
1472
|
-
if (this.isWeb) return super.checkOption(field)
|
|
1473
|
-
return super.checkOption(parseLocator.call(this, field))
|
|
1500
|
+
if (this.isWeb) return super.checkOption(field)
|
|
1501
|
+
return super.checkOption(parseLocator.call(this, field))
|
|
1474
1502
|
}
|
|
1475
1503
|
|
|
1476
1504
|
/**
|
|
@@ -1478,8 +1506,8 @@ class Appium extends Webdriver {
|
|
|
1478
1506
|
*
|
|
1479
1507
|
*/
|
|
1480
1508
|
async click(locator, context) {
|
|
1481
|
-
if (this.isWeb) return super.click(locator, context)
|
|
1482
|
-
return super.click(parseLocator.call(this, locator), parseLocator.call(this, context))
|
|
1509
|
+
if (this.isWeb) return super.click(locator, context)
|
|
1510
|
+
return super.click(parseLocator.call(this, locator), parseLocator.call(this, context))
|
|
1483
1511
|
}
|
|
1484
1512
|
|
|
1485
1513
|
/**
|
|
@@ -1487,16 +1515,16 @@ class Appium extends Webdriver {
|
|
|
1487
1515
|
*
|
|
1488
1516
|
*/
|
|
1489
1517
|
async dontSeeCheckboxIsChecked(field) {
|
|
1490
|
-
if (this.isWeb) return super.dontSeeCheckboxIsChecked(field)
|
|
1491
|
-
return super.dontSeeCheckboxIsChecked(parseLocator.call(this, field))
|
|
1518
|
+
if (this.isWeb) return super.dontSeeCheckboxIsChecked(field)
|
|
1519
|
+
return super.dontSeeCheckboxIsChecked(parseLocator.call(this, field))
|
|
1492
1520
|
}
|
|
1493
1521
|
|
|
1494
1522
|
/**
|
|
1495
1523
|
* {{> dontSeeElement }}
|
|
1496
1524
|
*/
|
|
1497
1525
|
async dontSeeElement(locator) {
|
|
1498
|
-
if (this.isWeb) return super.dontSeeElement(locator)
|
|
1499
|
-
return super.dontSeeElement(parseLocator.call(this, locator))
|
|
1526
|
+
if (this.isWeb) return super.dontSeeElement(locator)
|
|
1527
|
+
return super.dontSeeElement(parseLocator.call(this, locator))
|
|
1500
1528
|
}
|
|
1501
1529
|
|
|
1502
1530
|
/**
|
|
@@ -1504,17 +1532,17 @@ class Appium extends Webdriver {
|
|
|
1504
1532
|
*
|
|
1505
1533
|
*/
|
|
1506
1534
|
async dontSeeInField(field, value) {
|
|
1507
|
-
const _value =
|
|
1508
|
-
if (this.isWeb) return super.dontSeeInField(field, _value)
|
|
1509
|
-
return super.dontSeeInField(parseLocator.call(this, field), _value)
|
|
1535
|
+
const _value = typeof value === 'boolean' ? value : value.toString()
|
|
1536
|
+
if (this.isWeb) return super.dontSeeInField(field, _value)
|
|
1537
|
+
return super.dontSeeInField(parseLocator.call(this, field), _value)
|
|
1510
1538
|
}
|
|
1511
1539
|
|
|
1512
1540
|
/**
|
|
1513
1541
|
* {{> dontSee }}
|
|
1514
1542
|
*/
|
|
1515
1543
|
async dontSee(text, context = null) {
|
|
1516
|
-
if (this.isWeb) return super.dontSee(text, context)
|
|
1517
|
-
return super.dontSee(text, parseLocator.call(this, context))
|
|
1544
|
+
if (this.isWeb) return super.dontSee(text, context)
|
|
1545
|
+
return super.dontSee(text, parseLocator.call(this, context))
|
|
1518
1546
|
}
|
|
1519
1547
|
|
|
1520
1548
|
/**
|
|
@@ -1522,9 +1550,9 @@ class Appium extends Webdriver {
|
|
|
1522
1550
|
*
|
|
1523
1551
|
*/
|
|
1524
1552
|
async fillField(field, value) {
|
|
1525
|
-
value = value.toString()
|
|
1526
|
-
if (this.isWeb) return super.fillField(field, value)
|
|
1527
|
-
return super.fillField(parseLocator.call(this, field), value)
|
|
1553
|
+
value = value.toString()
|
|
1554
|
+
if (this.isWeb) return super.fillField(field, value)
|
|
1555
|
+
return super.fillField(parseLocator.call(this, field), value)
|
|
1528
1556
|
}
|
|
1529
1557
|
|
|
1530
1558
|
/**
|
|
@@ -1532,8 +1560,8 @@ class Appium extends Webdriver {
|
|
|
1532
1560
|
*
|
|
1533
1561
|
*/
|
|
1534
1562
|
async grabTextFromAll(locator) {
|
|
1535
|
-
if (this.isWeb) return super.grabTextFromAll(locator)
|
|
1536
|
-
return super.grabTextFromAll(parseLocator.call(this, locator))
|
|
1563
|
+
if (this.isWeb) return super.grabTextFromAll(locator)
|
|
1564
|
+
return super.grabTextFromAll(parseLocator.call(this, locator))
|
|
1537
1565
|
}
|
|
1538
1566
|
|
|
1539
1567
|
/**
|
|
@@ -1541,16 +1569,16 @@ class Appium extends Webdriver {
|
|
|
1541
1569
|
*
|
|
1542
1570
|
*/
|
|
1543
1571
|
async grabTextFrom(locator) {
|
|
1544
|
-
if (this.isWeb) return super.grabTextFrom(locator)
|
|
1545
|
-
return super.grabTextFrom(parseLocator.call(this, locator))
|
|
1572
|
+
if (this.isWeb) return super.grabTextFrom(locator)
|
|
1573
|
+
return super.grabTextFrom(parseLocator.call(this, locator))
|
|
1546
1574
|
}
|
|
1547
1575
|
|
|
1548
1576
|
/**
|
|
1549
1577
|
* {{> grabNumberOfVisibleElements }}
|
|
1550
1578
|
*/
|
|
1551
1579
|
async grabNumberOfVisibleElements(locator) {
|
|
1552
|
-
if (this.isWeb) return super.grabNumberOfVisibleElements(locator)
|
|
1553
|
-
return super.grabNumberOfVisibleElements(parseLocator.call(this, locator))
|
|
1580
|
+
if (this.isWeb) return super.grabNumberOfVisibleElements(locator)
|
|
1581
|
+
return super.grabNumberOfVisibleElements(parseLocator.call(this, locator))
|
|
1554
1582
|
}
|
|
1555
1583
|
|
|
1556
1584
|
/**
|
|
@@ -1559,8 +1587,8 @@ class Appium extends Webdriver {
|
|
|
1559
1587
|
* {{> grabAttributeFrom }}
|
|
1560
1588
|
*/
|
|
1561
1589
|
async grabAttributeFrom(locator, attr) {
|
|
1562
|
-
if (this.isWeb) return super.grabAttributeFrom(locator, attr)
|
|
1563
|
-
return super.grabAttributeFrom(parseLocator.call(this, locator), attr)
|
|
1590
|
+
if (this.isWeb) return super.grabAttributeFrom(locator, attr)
|
|
1591
|
+
return super.grabAttributeFrom(parseLocator.call(this, locator), attr)
|
|
1564
1592
|
}
|
|
1565
1593
|
|
|
1566
1594
|
/**
|
|
@@ -1568,8 +1596,8 @@ class Appium extends Webdriver {
|
|
|
1568
1596
|
* {{> grabAttributeFromAll }}
|
|
1569
1597
|
*/
|
|
1570
1598
|
async grabAttributeFromAll(locator, attr) {
|
|
1571
|
-
if (this.isWeb) return super.grabAttributeFromAll(locator, attr)
|
|
1572
|
-
return super.grabAttributeFromAll(parseLocator.call(this, locator), attr)
|
|
1599
|
+
if (this.isWeb) return super.grabAttributeFromAll(locator, attr)
|
|
1600
|
+
return super.grabAttributeFromAll(parseLocator.call(this, locator), attr)
|
|
1573
1601
|
}
|
|
1574
1602
|
|
|
1575
1603
|
/**
|
|
@@ -1577,8 +1605,8 @@ class Appium extends Webdriver {
|
|
|
1577
1605
|
*
|
|
1578
1606
|
*/
|
|
1579
1607
|
async grabValueFromAll(locator) {
|
|
1580
|
-
if (this.isWeb) return super.grabValueFromAll(locator)
|
|
1581
|
-
return super.grabValueFromAll(parseLocator.call(this, locator))
|
|
1608
|
+
if (this.isWeb) return super.grabValueFromAll(locator)
|
|
1609
|
+
return super.grabValueFromAll(parseLocator.call(this, locator))
|
|
1582
1610
|
}
|
|
1583
1611
|
|
|
1584
1612
|
/**
|
|
@@ -1586,8 +1614,8 @@ class Appium extends Webdriver {
|
|
|
1586
1614
|
*
|
|
1587
1615
|
*/
|
|
1588
1616
|
async grabValueFrom(locator) {
|
|
1589
|
-
if (this.isWeb) return super.grabValueFrom(locator)
|
|
1590
|
-
return super.grabValueFrom(parseLocator.call(this, locator))
|
|
1617
|
+
if (this.isWeb) return super.grabValueFrom(locator)
|
|
1618
|
+
return super.grabValueFrom(parseLocator.call(this, locator))
|
|
1591
1619
|
}
|
|
1592
1620
|
|
|
1593
1621
|
/**
|
|
@@ -1602,7 +1630,7 @@ class Appium extends Webdriver {
|
|
|
1602
1630
|
* @return {Promise<void>}
|
|
1603
1631
|
*/
|
|
1604
1632
|
async saveScreenshot(fileName) {
|
|
1605
|
-
return super.saveScreenshot(fileName, false)
|
|
1633
|
+
return super.saveScreenshot(fileName, false)
|
|
1606
1634
|
}
|
|
1607
1635
|
|
|
1608
1636
|
/**
|
|
@@ -1611,7 +1639,7 @@ class Appium extends Webdriver {
|
|
|
1611
1639
|
* Supported only for web testing
|
|
1612
1640
|
*/
|
|
1613
1641
|
async scrollIntoView(locator, scrollIntoViewOptions) {
|
|
1614
|
-
if (this.isWeb) return super.scrollIntoView(locator, scrollIntoViewOptions)
|
|
1642
|
+
if (this.isWeb) return super.scrollIntoView(locator, scrollIntoViewOptions)
|
|
1615
1643
|
}
|
|
1616
1644
|
|
|
1617
1645
|
/**
|
|
@@ -1619,8 +1647,8 @@ class Appium extends Webdriver {
|
|
|
1619
1647
|
*
|
|
1620
1648
|
*/
|
|
1621
1649
|
async seeCheckboxIsChecked(field) {
|
|
1622
|
-
if (this.isWeb) return super.seeCheckboxIsChecked(field)
|
|
1623
|
-
return super.seeCheckboxIsChecked(parseLocator.call(this, field))
|
|
1650
|
+
if (this.isWeb) return super.seeCheckboxIsChecked(field)
|
|
1651
|
+
return super.seeCheckboxIsChecked(parseLocator.call(this, field))
|
|
1624
1652
|
}
|
|
1625
1653
|
|
|
1626
1654
|
/**
|
|
@@ -1628,8 +1656,8 @@ class Appium extends Webdriver {
|
|
|
1628
1656
|
*
|
|
1629
1657
|
*/
|
|
1630
1658
|
async seeElement(locator) {
|
|
1631
|
-
if (this.isWeb) return super.seeElement(locator)
|
|
1632
|
-
return super.seeElement(parseLocator.call(this, locator))
|
|
1659
|
+
if (this.isWeb) return super.seeElement(locator)
|
|
1660
|
+
return super.seeElement(parseLocator.call(this, locator))
|
|
1633
1661
|
}
|
|
1634
1662
|
|
|
1635
1663
|
/**
|
|
@@ -1637,9 +1665,9 @@ class Appium extends Webdriver {
|
|
|
1637
1665
|
*
|
|
1638
1666
|
*/
|
|
1639
1667
|
async seeInField(field, value) {
|
|
1640
|
-
const _value =
|
|
1641
|
-
if (this.isWeb) return super.seeInField(field, _value)
|
|
1642
|
-
return super.seeInField(parseLocator.call(this, field), _value)
|
|
1668
|
+
const _value = typeof value === 'boolean' ? value : value.toString()
|
|
1669
|
+
if (this.isWeb) return super.seeInField(field, _value)
|
|
1670
|
+
return super.seeInField(parseLocator.call(this, field), _value)
|
|
1643
1671
|
}
|
|
1644
1672
|
|
|
1645
1673
|
/**
|
|
@@ -1647,8 +1675,8 @@ class Appium extends Webdriver {
|
|
|
1647
1675
|
*
|
|
1648
1676
|
*/
|
|
1649
1677
|
async see(text, context) {
|
|
1650
|
-
if (this.isWeb) return super.see(text, context)
|
|
1651
|
-
return super.see(text, parseLocator.call(this, context))
|
|
1678
|
+
if (this.isWeb) return super.see(text, context)
|
|
1679
|
+
return super.see(text, parseLocator.call(this, context))
|
|
1652
1680
|
}
|
|
1653
1681
|
|
|
1654
1682
|
/**
|
|
@@ -1657,8 +1685,8 @@ class Appium extends Webdriver {
|
|
|
1657
1685
|
* Supported only for web testing
|
|
1658
1686
|
*/
|
|
1659
1687
|
async selectOption(select, option) {
|
|
1660
|
-
if (this.isWeb) return super.selectOption(select, option)
|
|
1661
|
-
throw new Error(
|
|
1688
|
+
if (this.isWeb) return super.selectOption(select, option)
|
|
1689
|
+
throw new Error("Should be used only in Web context. In native context use 'click' method instead")
|
|
1662
1690
|
}
|
|
1663
1691
|
|
|
1664
1692
|
/**
|
|
@@ -1666,8 +1694,8 @@ class Appium extends Webdriver {
|
|
|
1666
1694
|
*
|
|
1667
1695
|
*/
|
|
1668
1696
|
async waitForElement(locator, sec = null) {
|
|
1669
|
-
if (this.isWeb) return super.waitForElement(locator, sec)
|
|
1670
|
-
return super.waitForElement(parseLocator.call(this, locator), sec)
|
|
1697
|
+
if (this.isWeb) return super.waitForElement(locator, sec)
|
|
1698
|
+
return super.waitForElement(parseLocator.call(this, locator), sec)
|
|
1671
1699
|
}
|
|
1672
1700
|
|
|
1673
1701
|
/**
|
|
@@ -1675,8 +1703,8 @@ class Appium extends Webdriver {
|
|
|
1675
1703
|
*
|
|
1676
1704
|
*/
|
|
1677
1705
|
async waitForVisible(locator, sec = null) {
|
|
1678
|
-
if (this.isWeb) return super.waitForVisible(locator, sec)
|
|
1679
|
-
return super.waitForVisible(parseLocator.call(this, locator), sec)
|
|
1706
|
+
if (this.isWeb) return super.waitForVisible(locator, sec)
|
|
1707
|
+
return super.waitForVisible(parseLocator.call(this, locator), sec)
|
|
1680
1708
|
}
|
|
1681
1709
|
|
|
1682
1710
|
/**
|
|
@@ -1684,8 +1712,8 @@ class Appium extends Webdriver {
|
|
|
1684
1712
|
*
|
|
1685
1713
|
*/
|
|
1686
1714
|
async waitForInvisible(locator, sec = null) {
|
|
1687
|
-
if (this.isWeb) return super.waitForInvisible(locator, sec)
|
|
1688
|
-
return super.waitForInvisible(parseLocator.call(this, locator), sec)
|
|
1715
|
+
if (this.isWeb) return super.waitForInvisible(locator, sec)
|
|
1716
|
+
return super.waitForInvisible(parseLocator.call(this, locator), sec)
|
|
1689
1717
|
}
|
|
1690
1718
|
|
|
1691
1719
|
/**
|
|
@@ -1693,74 +1721,76 @@ class Appium extends Webdriver {
|
|
|
1693
1721
|
*
|
|
1694
1722
|
*/
|
|
1695
1723
|
async waitForText(text, sec = null, context = null) {
|
|
1696
|
-
if (this.isWeb) return super.waitForText(text, sec, context)
|
|
1697
|
-
return super.waitForText(text, sec, parseLocator.call(this, context))
|
|
1724
|
+
if (this.isWeb) return super.waitForText(text, sec, context)
|
|
1725
|
+
return super.waitForText(text, sec, parseLocator.call(this, context))
|
|
1698
1726
|
}
|
|
1699
1727
|
}
|
|
1700
1728
|
|
|
1701
1729
|
function parseLocator(locator) {
|
|
1702
|
-
if (!locator) return null
|
|
1730
|
+
if (!locator) return null
|
|
1703
1731
|
|
|
1704
1732
|
if (typeof locator === 'object') {
|
|
1705
1733
|
if (locator.web && this.isWeb) {
|
|
1706
|
-
return parseLocator.call(this, locator.web)
|
|
1734
|
+
return parseLocator.call(this, locator.web)
|
|
1707
1735
|
}
|
|
1708
1736
|
|
|
1709
1737
|
if (locator.android && this.platform === 'android') {
|
|
1710
1738
|
if (typeof locator.android === 'string') {
|
|
1711
|
-
return parseLocator.call(this, locator.android)
|
|
1739
|
+
return parseLocator.call(this, locator.android)
|
|
1712
1740
|
}
|
|
1713
1741
|
// The locator is an Android DataMatcher or ViewMatcher locator so return as is
|
|
1714
|
-
return locator.android
|
|
1742
|
+
return locator.android
|
|
1715
1743
|
}
|
|
1716
1744
|
|
|
1717
1745
|
if (locator.ios && this.platform === 'ios') {
|
|
1718
|
-
return parseLocator.call(this, locator.ios)
|
|
1746
|
+
return parseLocator.call(this, locator.ios)
|
|
1719
1747
|
}
|
|
1720
1748
|
}
|
|
1721
1749
|
|
|
1722
1750
|
if (typeof locator === 'string') {
|
|
1723
|
-
if (locator[0] === '~') return locator
|
|
1724
|
-
if (locator.substr(0, 2) === '//') return locator
|
|
1751
|
+
if (locator[0] === '~') return locator
|
|
1752
|
+
if (locator.substr(0, 2) === '//') return locator
|
|
1725
1753
|
if (locator[0] === '#' && !this.isWeb) {
|
|
1726
1754
|
// hook before webdriverio supports native # locators
|
|
1727
|
-
return parseLocator.call(this, { id: locator.slice(1) })
|
|
1755
|
+
return parseLocator.call(this, { id: locator.slice(1) })
|
|
1728
1756
|
}
|
|
1729
1757
|
|
|
1730
1758
|
if (this.platform === 'android' && !this.isWeb) {
|
|
1731
|
-
const isNativeLocator = /^\-?android=?/.exec(locator)
|
|
1732
|
-
return isNativeLocator
|
|
1733
|
-
? locator
|
|
1734
|
-
: `android=new UiSelector().text("${locator}")`;
|
|
1759
|
+
const isNativeLocator = /^\-?android=?/.exec(locator)
|
|
1760
|
+
return isNativeLocator ? locator : `android=new UiSelector().text("${locator}")`
|
|
1735
1761
|
}
|
|
1736
1762
|
}
|
|
1737
1763
|
|
|
1738
|
-
locator = new Locator(locator, 'xpath')
|
|
1739
|
-
if (locator.type === 'css' && !this.isWeb)
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1764
|
+
locator = new Locator(locator, 'xpath')
|
|
1765
|
+
if (locator.type === 'css' && !this.isWeb)
|
|
1766
|
+
throw new Error(
|
|
1767
|
+
'Unable to use css locators in apps. Locator strategies for this request: xpath, id, class name or accessibility id',
|
|
1768
|
+
)
|
|
1769
|
+
if (locator.type === 'name' && !this.isWeb)
|
|
1770
|
+
throw new Error("Can't locate element by name in Native context. Use either ID, class name or accessibility id")
|
|
1771
|
+
if (locator.type === 'id' && !this.isWeb && this.platform === 'android') return `//*[@resource-id='${locator.value}']`
|
|
1772
|
+
return locator.simplify()
|
|
1743
1773
|
}
|
|
1744
1774
|
|
|
1745
1775
|
// in the end of a file
|
|
1746
1776
|
function onlyForApps(expectedPlatform) {
|
|
1747
|
-
const stack = new Error().stack || ''
|
|
1748
|
-
const re = /Appium.(\w+)/g
|
|
1749
|
-
const caller = stack.split('\n')[2].trim()
|
|
1750
|
-
const m = re.exec(caller)
|
|
1777
|
+
const stack = new Error().stack || ''
|
|
1778
|
+
const re = /Appium.(\w+)/g
|
|
1779
|
+
const caller = stack.split('\n')[2].trim()
|
|
1780
|
+
const m = re.exec(caller)
|
|
1751
1781
|
|
|
1752
1782
|
if (!m) {
|
|
1753
|
-
throw new Error(`Invalid caller ${caller}`)
|
|
1783
|
+
throw new Error(`Invalid caller ${caller}`)
|
|
1754
1784
|
}
|
|
1755
1785
|
|
|
1756
|
-
const callerName = m[1] || m[2]
|
|
1786
|
+
const callerName = m[1] || m[2]
|
|
1757
1787
|
if (!expectedPlatform) {
|
|
1758
1788
|
if (!this.platform) {
|
|
1759
|
-
throw new Error(`${callerName} method can be used only with apps`)
|
|
1789
|
+
throw new Error(`${callerName} method can be used only with apps`)
|
|
1760
1790
|
}
|
|
1761
1791
|
} else if (this.platform !== expectedPlatform.toLowerCase()) {
|
|
1762
|
-
throw new Error(`${callerName} method can be used only with ${expectedPlatform} apps`)
|
|
1792
|
+
throw new Error(`${callerName} method can be used only with ${expectedPlatform} apps`)
|
|
1763
1793
|
}
|
|
1764
1794
|
}
|
|
1765
1795
|
|
|
1766
|
-
module.exports = Appium
|
|
1796
|
+
module.exports = Appium
|