Skip to content

Commit 7724b81

Browse files
author
DavertMik
committed
synchronized with docs
1 parent 9df364d commit 7724b81

37 files changed

Lines changed: 4358 additions & 4234 deletions

docs/ai.md

Lines changed: 213 additions & 95 deletions
Large diffs are not rendered by default.

docs/basics.md

Lines changed: 218 additions & 208 deletions
Large diffs are not rendered by default.

docs/build/AI.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ const ora = require('ora-classic')
33
const fs = require('fs')
44
const path = require('path')
55
const ai = require('../ai')
6-
const standardActingHelpers = require('../plugin/standardActingHelpers')
76
const Container = require('../container')
87
const { splitByChunks, minifyHtml } = require('../html')
98
const { beautify } = require('../utils')
109
const output = require('../output')
1110
const { registerVariable } = require('../pause')
1211

12+
const standardActingHelpers = Container.STANDARD_ACTING_HELPERS
13+
1314
const gtpRole = {
1415
user: 'user',
1516
}

docs/build/ApiDataFactory.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class ApiDataFactory extends Helper {
217217
}
218218

219219
this.created = {}
220-
Object.keys(this.factories).forEach((f) => (this.created[f] = []))
220+
Object.keys(this.factories).forEach(f => (this.created[f] = []))
221221
}
222222

223223
static _checkRequirements() {
@@ -357,7 +357,7 @@ Current file error: ${err.message}`)
357357

358358
request.baseURL = this.config.endpoint
359359

360-
return this.restHelper._executeRequest(request).then((resp) => {
360+
return this.restHelper._executeRequest(request).then(resp => {
361361
const id = this._fetchId(resp.data, factory)
362362
this.created[factory].push(id)
363363
this.debugSection('Created', `Id: ${id}`)
@@ -391,10 +391,7 @@ Current file error: ${err.message}`)
391391
request.baseURL = this.config.endpoint
392392

393393
if (request.url.match(/^undefined/)) {
394-
return this.debugSection(
395-
'Please configure the delete request in your ApiDataFactory helper',
396-
"delete: () => ({ method: 'DELETE', url: '/api/users' })",
397-
)
394+
return this.debugSection('Please configure the delete request in your ApiDataFactory helper', "delete: () => ({ method: 'DELETE', url: '/api/users' })")
398395
}
399396

400397
return this.restHelper._executeRequest(request).then(() => {

docs/build/Appium.js

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const vendorPrefix = {
4444
*
4545
* This helper should be configured in codecept.conf.ts or codecept.conf.js
4646
*
47-
* * `appiumV2`: set this to true if you want to run tests with AppiumV2. See more how to setup [here](https://codecept.io/mobile/#setting-up)
47+
* * `appiumV2`: by default is true, set this to false if you want to run tests with AppiumV1. See more how to setup [here](https://codecept.io/mobile/#setting-up)
4848
* * `app`: Application path. Local path or remote URL to an .ipa or .apk file, or a .zip containing one of these. Alias to desiredCapabilities.appPackage
4949
* * `host`: (default: 'localhost') Appium host
5050
* * `port`: (default: '4723') Appium port
@@ -124,7 +124,7 @@ const vendorPrefix = {
124124
* {
125125
* helpers: {
126126
* Appium: {
127-
* appiumV2: true,
127+
* appiumV2: true, // By default is true, set to false if you want to run against Appium v1
128128
* host: "hub-cloud.browserstack.com",
129129
* port: 4444,
130130
* user: process.env.BROWSERSTACK_USER,
@@ -178,16 +178,12 @@ class Appium extends Webdriver {
178178
super(config)
179179

180180
this.isRunning = false
181-
if (config.appiumV2 === true) {
182-
this.appiumV2 = true
183-
}
181+
this.appiumV2 = config.appiumV2 || true
184182
this.axios = axios.create()
185183

186184
webdriverio = require('webdriverio')
187185
if (!config.appiumV2) {
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-
)
186+
console.log('The Appium core team does not maintain Appium 1.x anymore since the 1st of January 2022. Appium 2.x is used by default.')
191187
console.log('More info: https://bit.ly/appium-v2-migration')
192188
console.log('This Appium 1.x support will be removed in next major release.')
193189
}
@@ -234,20 +230,14 @@ class Appium extends Webdriver {
234230

235231
config.baseUrl = config.url || config.baseUrl
236232
if (config.desiredCapabilities && Object.keys(config.desiredCapabilities).length) {
237-
config.capabilities =
238-
this.appiumV2 === true ? this._convertAppiumV2Caps(config.desiredCapabilities) : config.desiredCapabilities
233+
config.capabilities = this.appiumV2 === true ? this._convertAppiumV2Caps(config.desiredCapabilities) : config.desiredCapabilities
239234
}
240235

241236
if (this.appiumV2) {
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
237+
config.capabilities[`${vendorPrefix.appium}:deviceName`] = config[`${vendorPrefix.appium}:device`] || config.capabilities[`${vendorPrefix.appium}:deviceName`]
238+
config.capabilities[`${vendorPrefix.appium}:browserName`] = config[`${vendorPrefix.appium}:browser`] || config.capabilities[`${vendorPrefix.appium}:browserName`]
239+
config.capabilities[`${vendorPrefix.appium}:app`] = config[`${vendorPrefix.appium}:app`] || config.capabilities[`${vendorPrefix.appium}:app`]
240+
config.capabilities[`${vendorPrefix.appium}:tunnelIdentifier`] = config[`${vendorPrefix.appium}:tunnelIdentifier`] || config.capabilities[`${vendorPrefix.appium}:tunnelIdentifier`] // Adding the code to connect to sauce labs via sauce tunnel
251241
} else {
252242
config.capabilities.deviceName = config.device || config.capabilities.deviceName
253243
config.capabilities.browserName = config.browser || config.capabilities.browserName
@@ -394,7 +384,7 @@ class Appium extends Webdriver {
394384
_buildAppiumEndpoint() {
395385
const { protocol, port, hostname, path } = this.browser.options
396386
// Build path to Appium REST API endpoint
397-
return `${protocol}://${hostname}:${port}${path}`
387+
return `${protocol}://${hostname}:${port}${path}/session/${this.browser.sessionId}`
398388
}
399389

400390
/**
@@ -610,7 +600,7 @@ class Appium extends Webdriver {
610600

611601
return this.axios({
612602
method: 'post',
613-
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/appium/device/remove_app`,
603+
url: `${this._buildAppiumEndpoint()}/appium/device/remove_app`,
614604
data: { appId, bundleId },
615605
})
616606
}
@@ -627,7 +617,7 @@ class Appium extends Webdriver {
627617
onlyForApps.call(this)
628618
return this.axios({
629619
method: 'post',
630-
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/appium/app/reset`,
620+
url: `${this._buildAppiumEndpoint()}/appium/app/reset`,
631621
})
632622
}
633623

@@ -701,7 +691,7 @@ class Appium extends Webdriver {
701691

702692
const res = await this.axios({
703693
method: 'get',
704-
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/orientation`,
694+
url: `${this._buildAppiumEndpoint()}/orientation`,
705695
})
706696

707697
const currentOrientation = res.data.value
@@ -725,7 +715,7 @@ class Appium extends Webdriver {
725715

726716
return this.axios({
727717
method: 'post',
728-
url: `${this._buildAppiumEndpoint()}/session/${this.browser.sessionId}/orientation`,
718+
url: `${this._buildAppiumEndpoint()}/orientation`,
729719
data: { orientation },
730720
})
731721
}
@@ -964,21 +954,19 @@ class Appium extends Webdriver {
964954
* ```js
965955
* // taps outside to hide keyboard per default
966956
* I.hideDeviceKeyboard();
967-
* I.hideDeviceKeyboard('tapOutside');
968-
*
969-
* // or by pressing key
970-
* I.hideDeviceKeyboard('pressKey', 'Done');
971957
* ```
972958
*
973959
* Appium: support Android and iOS
974960
*
975-
* @param {'tapOutside' | 'pressKey'} [strategy] Desired strategy to close keyboard (‘tapOutside’ or ‘pressKey’)
976-
* @param {string} [key] Optional key
977961
*/
978-
async hideDeviceKeyboard(strategy, key) {
962+
async hideDeviceKeyboard() {
979963
onlyForApps.call(this)
980-
strategy = strategy || 'tapOutside'
981-
return this.browser.hideKeyboard(strategy, key)
964+
965+
return this.axios({
966+
method: 'post',
967+
url: `${this._buildAppiumEndpoint()}/appium/device/hide_keyboard`,
968+
data: {},
969+
})
982970
}
983971

984972
/**
@@ -1054,7 +1042,13 @@ class Appium extends Webdriver {
10541042
* @param {*} locator
10551043
*/
10561044
async tap(locator) {
1057-
return this.makeTouchAction(locator, 'tap')
1045+
const { elementId } = await this.browser.$(parseLocator.call(this, locator))
1046+
1047+
return this.axios({
1048+
method: 'post',
1049+
url: `${this._buildAppiumEndpoint()}/element/${elementId}/click`,
1050+
data: {},
1051+
})
10581052
}
10591053

10601054
/**
@@ -1304,14 +1298,14 @@ class Appium extends Webdriver {
13041298
}
13051299
return browser
13061300
.$$(parseLocator.call(this, searchableLocator))
1307-
.then((els) => els.length && els[0].isDisplayed())
1308-
.then((res) => {
1301+
.then(els => els.length && els[0].isDisplayed())
1302+
.then(res => {
13091303
if (res) {
13101304
return true
13111305
}
13121306
return this[direction](scrollLocator, offset, speed)
13131307
.getSource()
1314-
.then((source) => {
1308+
.then(source => {
13151309
if (source === currentSource) {
13161310
err = true
13171311
} else {
@@ -1324,12 +1318,9 @@ class Appium extends Webdriver {
13241318
timeout * 1000,
13251319
errorMsg,
13261320
)
1327-
.catch((e) => {
1321+
.catch(e => {
13281322
if (e.message.indexOf('timeout') && e.type !== 'NoSuchElement') {
1329-
throw new AssertionFailedError(
1330-
{ customMessage: `Scroll to the end and element ${searchableLocator} was not found` },
1331-
'',
1332-
)
1323+
throw new AssertionFailedError({ customMessage: `Scroll to the end and element ${searchableLocator} was not found` }, '')
13331324
} else {
13341325
throw e
13351326
}
@@ -1386,8 +1377,8 @@ class Appium extends Webdriver {
13861377
*/
13871378
async pullFile(path, dest) {
13881379
onlyForApps.call(this)
1389-
return this.browser.pullFile(path).then((res) =>
1390-
fs.writeFile(dest, Buffer.from(res, 'base64'), (err) => {
1380+
return this.browser.pullFile(path).then(res =>
1381+
fs.writeFile(dest, Buffer.from(res, 'base64'), err => {
13911382
if (err) {
13921383
return false
13931384
}
@@ -1553,7 +1544,14 @@ class Appium extends Webdriver {
15531544
*/
15541545
async click(locator, context) {
15551546
if (this.isWeb) return super.click(locator, context)
1556-
return super.click(parseLocator.call(this, locator), parseLocator.call(this, context))
1547+
1548+
const { elementId } = await this.browser.$(parseLocator.call(this, locator), parseLocator.call(this, context))
1549+
1550+
return this.axios({
1551+
method: 'post',
1552+
url: `${this._buildAppiumEndpoint()}/element/${elementId}/click`,
1553+
data: {},
1554+
})
15571555
}
15581556

15591557
/**
@@ -2044,12 +2042,8 @@ function parseLocator(locator) {
20442042
}
20452043

20462044
locator = new Locator(locator, 'xpath')
2047-
if (locator.type === 'css' && !this.isWeb)
2048-
throw new Error(
2049-
'Unable to use css locators in apps. Locator strategies for this request: xpath, id, class name or accessibility id',
2050-
)
2051-
if (locator.type === 'name' && !this.isWeb)
2052-
throw new Error("Can't locate element by name in Native context. Use either ID, class name or accessibility id")
2045+
if (locator.type === 'css' && !this.isWeb) throw new Error('Unable to use css locators in apps. Locator strategies for this request: xpath, id, class name or accessibility id')
2046+
if (locator.type === 'name' && !this.isWeb) throw new Error("Can't locate element by name in Native context. Use either ID, class name or accessibility id")
20532047
if (locator.type === 'id' && !this.isWeb && this.platform === 'android') return `//*[@resource-id='${locator.value}']`
20542048
return locator.simplify()
20552049
}

docs/build/FileSystem.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class FileSystem extends Helper {
105105
*/
106106
seeFileNameMatching(text) {
107107
assert.ok(
108-
this.grabFileNames().some((file) => file.includes(text)),
108+
this.grabFileNames().some(file => file.includes(text)),
109109
`File name which contains ${text} not found in ${this.dir}`,
110110
)
111111
}
@@ -175,7 +175,7 @@ class FileSystem extends Helper {
175175
* ```
176176
*/
177177
grabFileNames() {
178-
return fs.readdirSync(this.dir).filter((item) => !fs.lstatSync(path.join(this.dir, item)).isDirectory())
178+
return fs.readdirSync(this.dir).filter(item => !fs.lstatSync(path.join(this.dir, item)).isDirectory())
179179
}
180180
}
181181

@@ -216,7 +216,7 @@ function isFileExists(file, timeout) {
216216
}
217217
})
218218

219-
fs.access(file, fs.constants.R_OK, (err) => {
219+
fs.access(file, fs.constants.R_OK, err => {
220220
if (!err) {
221221
clearTimeout(timer)
222222
watcher.close()

docs/build/GraphQLDataFactory.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class GraphQLDataFactory extends Helper {
170170
this.factories = this.config.factories
171171

172172
this.created = {}
173-
Object.keys(this.factories).forEach((f) => (this.created[f] = []))
173+
Object.keys(this.factories).forEach(f => (this.created[f] = []))
174174
}
175175

176176
static _checkRequirements() {
@@ -278,7 +278,7 @@ class GraphQLDataFactory extends Helper {
278278
*/
279279
_requestCreate(operation, variables) {
280280
const { query } = this.factories[operation]
281-
return this.graphqlHelper.sendMutation(query, variables).then((response) => {
281+
return this.graphqlHelper.sendMutation(query, variables).then(response => {
282282
const data = response.data.data[operation]
283283
this.created[operation].push(data)
284284
this.debugSection('Created', `record: ${data}`)
@@ -297,7 +297,7 @@ class GraphQLDataFactory extends Helper {
297297
const deleteOperation = this.factories[operation].revert(data)
298298
const { query, variables } = deleteOperation
299299

300-
return this.graphqlHelper.sendMutation(query, variables).then((response) => {
300+
return this.graphqlHelper.sendMutation(query, variables).then(response => {
301301
const idx = this.created[operation].indexOf(data)
302302
this.debugSection('Deleted', `record: ${response.data.data}`)
303303
this.created[operation].splice(idx, 1)

0 commit comments

Comments
 (0)