Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/helper/errors/ElementNotFound.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ElementNotFound extends Error {
try {
const { default: Container } = await import('../../container.js')
const helper = Object.values(Container.helpers()).find(h => h && typeof h.executeScript === 'function')
if (!helper) return null
if (!helper || helper.isWeb === false) return null
const timeout = new Promise(resolve => {
timer = setTimeout(() => resolve(null), 500)
})
Expand Down
9 changes: 9 additions & 0 deletions test/unit/helper/element_not_found_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ describe('ElementNotFound error', () => {
expect(err.stack).to.include('similar on page: #email')
})

it('should not run the page script in a native app context', async () => {
let called = false
Container.append({ helpers: { Appium: { isWeb: false, executeScript: async () => { called = true } } } })
const err = new ElementNotFound('Sign in')
await err.explain()
expect(called).to.equal(false)
expect(err.message).to.equal('Element "Sign in" was not found by text|CSS|XPath')
})

it('should keep the message when the page script fails', async () => {
Container.append({ helpers: { web: { executeScript: async () => { throw new Error('page closed') } } } })
const err = new ElementNotFound('Sign in')
Expand Down
Loading