Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/appium_Android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- 4.x
- appium-esm-migration
pull_request:
branches:
- 4.x

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down
11 changes: 7 additions & 4 deletions lib/element/WebElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class WebElement {
_detectHelperType(helper) {
if (!helper) return 'unknown'

const className = helper.constructor.name
if (className === 'Playwright') return 'playwright'
if (className === 'WebDriver') return 'webdriver'
if (className === 'Puppeteer') return 'puppeteer'
let ctor = helper.constructor
while (ctor && ctor.name) {
if (ctor.name === 'Playwright') return 'playwright'
if (ctor.name === 'WebDriver') return 'webdriver'
if (ctor.name === 'Puppeteer') return 'puppeteer'
ctor = Object.getPrototypeOf(ctor)
}

return 'unknown'
}
Expand Down
29 changes: 25 additions & 4 deletions lib/helper/Appium.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ class Appium extends Webdriver {
super(config)

this.isRunning = false
this.appiumV2 = config.appiumV2 || true
this.appiumV2 = config.appiumV2 !== false
this.axios = axios.create()

if (!config.appiumV2) {
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.')
if (this.appiumV2 === false) {
console.log('Appium 1.x is no longer maintained by the Appium team (since 2022-01-01).')
console.log('More info: https://bit.ly/appium-v2-migration')
console.log('This Appium 1.x support will be removed in next major release.')
console.log('Appium 1.x support will be removed in the next major CodeceptJS release.')
}
}

Expand Down Expand Up @@ -220,6 +220,9 @@ class Appium extends Webdriver {
deprecationWarnings: false,
restart: true,
manualStart: false,
// Mobile emulator/device cold starts (esp. on cloud grids like Sauce Labs)
// routinely exceed webdriverio's 2-minute default. Bump to 5 min.
connectionRetryTimeout: 300000, // ms
timeouts: {
script: 0, // ms
},
Expand Down Expand Up @@ -331,6 +334,24 @@ class Appium extends Webdriver {
}
this.$$ = this.browser.$$.bind(this.browser)

// wdio v9 implements `element.isDisplayed()` for non-mobile contexts by
// injecting a JS visibility check via POST /execute/sync. Appium's native
// context cannot execute JS, so each call logs an ugly
// "Method is not implemented" ERROR before the existing catch swallows it.
// Short-circuit isDisplayed to `true` while in native context so the
// request is never issued (matches existing _isDisplayedSafe semantics).
const helper = this
if (typeof this.browser.overwriteCommand === 'function') {
this.browser.overwriteCommand(
'isDisplayed',
async function (origFn, ...args) {
if (helper.isWeb) return origFn.call(this, ...args)
return true
},
true,
)
}

this.isRunning = true
if (this.options.timeouts && this.isWeb) {
await this.defineTimeout(this.options.timeouts)
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ class WebDriver extends Helper {
const elem = selectElement(res, field, this)
highlightActiveElement.call(this, elem)

if (await fillRichEditor(this, elem, value)) {
if (this.isWeb !== false && await fillRichEditor(this, elem, value)) {
return
}

Expand Down
2 changes: 1 addition & 1 deletion test/helper/Appium_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const apk_path = 'storage:filename=selendroid-test-app-0.17.0.apk'
const smallWait = 3

describe('Appium', function () {
// this.retries(1);
this.retries(1)
this.timeout(0)

before(async () => {
Expand Down
16 changes: 16 additions & 0 deletions test/unit/WebElement_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ describe('WebElement', () => {

expect(webElement.helperType).to.equal('unknown')
})

it('should detect Appium as webdriver via prototype chain', () => {
class WebDriver {}
class Appium extends WebDriver {}
const webElement = new WebElement({}, new Appium())

expect(webElement.helperType).to.equal('webdriver')
})

it('should detect subclasses of Playwright as playwright', () => {
class Playwright {}
class CustomPlaywright extends Playwright {}
const webElement = new WebElement({}, new CustomPlaywright())

expect(webElement.helperType).to.equal('playwright')
})
})

describe('getText()', () => {
Expand Down