Skip to content

Commit 84cbb17

Browse files
authored
fix(webdriverio): allow waitForClickable in native context if browserName is present (#15045)
1 parent 7d541be commit 84cbb17

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

packages/webdriverio/src/commands/element/waitForClickable.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ export async function waitForClickable (
4444
}: WaitForOptions = {}
4545
) {
4646
const browser = getBrowserObject(this)
47-
if (browser.isMobile && browser.isNativeContext) {
47+
if (
48+
browser.isMobile &&
49+
browser.isNativeContext &&
50+
!browser.capabilities?.browserName
51+
) {
4852
throw new Error('The `waitForClickable` command is only available for desktop and mobile browsers.')
4953
}
5054

packages/webdriverio/tests/commands/element/waitForClickable.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,31 @@ describe('waitForClickable', () => {
174174

175175
await expect(elem.waitForClickable()).rejects.toThrow('The `waitForClickable` command is only available for desktop and mobile browsers.')
176176
})
177+
178+
it('should not throw an error if in native context but has browserName capability', async () => {
179+
const browser = await remote({
180+
baseUrl: 'http://foobar.com',
181+
capabilities: {
182+
platformName: 'Android',
183+
browserName: 'samsung',
184+
mobileMode: true,
185+
nativeAppMode: true,
186+
} as any
187+
})
188+
// Force capabilities to ensure test logic works regardless of remote mock implementation
189+
Object.assign(browser.capabilities, { browserName: 'samsung' })
190+
191+
const tmpElem = await browser.$('#foo')
192+
const elem = {
193+
selector : '#foo',
194+
waitForClickable : tmpElem.waitForClickable,
195+
elementId : 123,
196+
waitUntil : vi.fn().mockResolvedValue(true),
197+
isClickable : vi.fn().mockResolvedValue(true),
198+
options : { waitforTimeout : 500 },
199+
parent: browser
200+
} as unknown as WebdriverIO.Element
201+
202+
await expect(elem.waitForClickable()).resolves.toBe(true)
203+
})
177204
})

0 commit comments

Comments
 (0)