Skip to content

Commit b5b420f

Browse files
committed
fix: appium tests
1 parent 5826298 commit b5b420f

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

.github/workflows/appium_Android.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- 3.x
7+
- 5228-fix-appium-tests
78

89
env:
910
CI: true

lib/helper/Appium.js

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,39 @@ class Appium extends Webdriver {
15231523
*/
15241524
async dontSeeElement(locator) {
15251525
if (this.isWeb) return super.dontSeeElement(locator)
1526-
return super.dontSeeElement(parseLocator.call(this, locator))
1526+
1527+
// For mobile native apps, handle isDisplayed error gracefully
1528+
const parsedLocator = parseLocator.call(this, locator)
1529+
const res = await this._locate(parsedLocator, false)
1530+
const { truth } = require('../assert/truth')
1531+
const Locator = require('../locator')
1532+
1533+
if (!res || res.length === 0) {
1534+
return truth(`elements of ${new Locator(parsedLocator)}`, 'to be seen').negate(false)
1535+
}
1536+
1537+
const selected = []
1538+
for (const el of res) {
1539+
try {
1540+
const displayed = await el.isDisplayed()
1541+
if (displayed) selected.push(true)
1542+
} catch (err) {
1543+
// If isDisplayed fails due to execute/sync not being supported,
1544+
// fall back to checking if element exists (which we already verified)
1545+
if (err.message && err.message.includes('Method is not implemented')) {
1546+
// Element exists, assume it's displayed
1547+
selected.push(true)
1548+
} else {
1549+
throw err
1550+
}
1551+
}
1552+
}
1553+
1554+
try {
1555+
return truth(`elements of ${new Locator(parsedLocator)}`, 'to be seen').negate(selected)
1556+
} catch (err) {
1557+
throw err
1558+
}
15271559
}
15281560

15291561
/**
@@ -1656,7 +1688,43 @@ class Appium extends Webdriver {
16561688
*/
16571689
async seeElement(locator) {
16581690
if (this.isWeb) return super.seeElement(locator)
1659-
return super.seeElement(parseLocator.call(this, locator))
1691+
1692+
// For mobile native apps, we need to handle isDisplayed differently
1693+
// because webdriverio's isDisplayed() tries to execute JavaScript which isn't supported
1694+
const parsedLocator = parseLocator.call(this, locator)
1695+
const res = await this._locate(parsedLocator, true)
1696+
const ElementNotFound = require('./errors/ElementNotFound')
1697+
const { truth } = require('../assert/truth')
1698+
const { dontSeeElementError } = require('./errors/ElementAssertion')
1699+
const Locator = require('../locator')
1700+
1701+
if (!res || res.length === 0) {
1702+
throw new ElementNotFound(parsedLocator)
1703+
}
1704+
1705+
// Use a safer approach for mobile: check if element exists and try isDisplayed with error handling
1706+
const selected = []
1707+
for (const el of res) {
1708+
try {
1709+
const displayed = await el.isDisplayed()
1710+
if (displayed) selected.push(true)
1711+
} catch (err) {
1712+
// If isDisplayed fails due to execute/sync not being supported,
1713+
// fall back to checking if element exists (which we already verified)
1714+
if (err.message && err.message.includes('Method is not implemented')) {
1715+
// Element exists, assume it's displayed since we found it
1716+
selected.push(true)
1717+
} else {
1718+
throw err
1719+
}
1720+
}
1721+
}
1722+
1723+
try {
1724+
return truth(`elements of ${new Locator(parsedLocator)}`, 'to be seen').assert(selected)
1725+
} catch (e) {
1726+
dontSeeElementError(parsedLocator)
1727+
}
16601728
}
16611729

16621730
/**

test/helper/Appium_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('Appium', function () {
3131
platformName: 'Android',
3232
platformVersion: '7.0',
3333
deviceName: 'Android GoogleAPI Emulator',
34+
automationName: 'UiAutomator2',
3435
androidInstallTimeout: 90000,
3536
appWaitDuration: 300000,
3637
},

0 commit comments

Comments
 (0)