diff --git a/lib/helper/errors/ElementNotFound.js b/lib/helper/errors/ElementNotFound.js index 6c175acba..ae8c651f6 100644 --- a/lib/helper/errors/ElementNotFound.js +++ b/lib/helper/errors/ElementNotFound.js @@ -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) }) diff --git a/test/unit/helper/element_not_found_test.js b/test/unit/helper/element_not_found_test.js index 78e028150..e9fdd594a 100644 --- a/test/unit/helper/element_not_found_test.js +++ b/test/unit/helper/element_not_found_test.js @@ -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')