Skip to content

Commit cb88dfb

Browse files
committed
test: fix timeout tests
1 parent b61b3b7 commit cb88dfb

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

test/helpers/selenium-helper.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ class SeleniumHelper {
129129
.then(elements => elements.length > 0);
130130
}
131131

132-
notExistsByXpath (xpath) {
133-
return this.driver.findElements(By.xpath(xpath))
134-
.then(elements => elements.length === 0 || elements.every(i => !i.isDisplayed()));
132+
notExistsByXpath (xpath, timeoutMessage = `notExistsByXpath timed out for path: ${xpath}`) {
133+
return this.driver.wait(() => this.driver.findElements(By.xpath(xpath))
134+
.then(elements => elements.length === 0 || elements.every(i => !i.isDisplayed())),
135+
DEFAULT_TIMEOUT_MILLISECONDS, timeoutMessage);
135136
}
136137

137138
loadUri (uri) {
Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import path from 'path';
21
import SeleniumHelper from '../helpers/selenium-helper';
32

43
const {
@@ -7,12 +6,10 @@ const {
76
findByXpath,
87
notExistsByXpath,
98
getDriver,
10-
getLogs,
11-
loadUri
9+
loadUri,
10+
urlFor
1211
} = new SeleniumHelper();
1312

14-
const uri = path.resolve(__dirname, '../../build/index.html');
15-
1613
let driver;
1714

1815
const trademarkNames = [
@@ -37,40 +34,28 @@ describe('Removed trademarks (ex: Scratch Cat)', () => {
3734
});
3835

3936
test('Removed trademark sprites', async () => {
40-
await loadUri(uri);
37+
await loadUri(urlFor('/'));
4138
await clickXpath('//button[@aria-label="Choose a Sprite"]');
42-
await driver.sleep(5000);
4339
const searchElement = await findByXpath("//input[@placeholder='Search']");
4440

4541
for (const name of trademarkNames) {
46-
searchElement.clear();
47-
await driver.sleep(500);
4842
await searchElement.sendKeys(name);
49-
await driver.sleep(500);
5043
expect(await notExistsByXpath(`//*[span[text()="${name}"]]`)).toBeTruthy();
44+
searchElement.clear();
5145
}
52-
53-
const logs = await getLogs();
54-
await expect(logs).toEqual([]);
55-
});
46+
}, 60 * 1000);
5647

5748
test('Removed trademark costumes', async () => {
58-
await loadUri(uri);
49+
await loadUri(urlFor('/'));
5950
await clickText('Costumes');
6051
await clickXpath('//button[@aria-label="Choose a Costume"]');
61-
await driver.sleep(5000);
6252
const searchElement = await findByXpath("//input[@placeholder='Search']");
6353

6454
for (const name of trademarkNames) {
65-
searchElement.clear();
66-
await driver.sleep(500);
6755
const costumePrefix = `${name}-`;
6856
await searchElement.sendKeys(costumePrefix);
69-
await driver.sleep(500);
7057
expect(await notExistsByXpath(`//*[span[contains(text(), "${costumePrefix}")]]`)).toBeTruthy();
58+
searchElement.clear();
7159
}
72-
73-
const logs = await getLogs();
74-
await expect(logs).toEqual([]);
75-
});
60+
}, 60 * 1000);
7661
});

0 commit comments

Comments
 (0)