-
Notifications
You must be signed in to change notification settings - Fork 531
/
Copy pathsetSearchBoxValue.ts
35 lines (30 loc) · 1.18 KB
/
setSearchBoxValue.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
declare namespace WebdriverIOAsync {
interface Browser {
setSearchBoxValue: (value: string) => Promise<void>;
}
}
browser.addCommand('setSearchBoxValue', async (value: string) => {
const oldUrl = await browser.getUrl();
const searchBox = await browser.$('.ais-SearchBox [type=search]');
const resetButton = await browser.$('.ais-SearchBox [type=reset]');
// Assures us that the element is in the viewport
await searchBox.scrollIntoView();
// Click the reset button to clear the input
if (await resetButton.isDisplayed()) {
// The reset button is invisible when nothing to reset
await resetButton.click();
}
// In Internet Explorer the input must be focused before updating its value
await searchBox.click();
await searchBox.setValue(value);
// Changing the URL will also change the page element IDs in Internet Explorer
// Not waiting for the URL to be properly updated before continuing can make the next tests fail
await browser.waitUntil(
async () => {
const newUrl = await browser.getUrl();
return newUrl !== oldUrl && newUrl.includes(value);
},
undefined,
`URL was not updated after setting searchbox value to "${value}"`
);
});