-
Notifications
You must be signed in to change notification settings - Fork 48
/
e2e.js
109 lines (84 loc) · 3.21 KB
/
e2e.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import path from 'path';
import chromedriver from 'chromedriver';
import webdriver from 'selenium-webdriver';
import { expect } from 'chai';
import electronPath from 'electron-prebuilt';
import homeStyles from '../app/components/Home.module.css';
import counterStyles from '../app/components/Counter.module.css';
chromedriver.start(); // on port 9515
process.on('exit', chromedriver.stop);
const delay = time => new Promise(resolve => setTimeout(resolve, time));
describe('main window', function spec() {
this.timeout(5000);
before(async () => {
await delay(1000); // wait chromedriver start time
this.driver = new webdriver.Builder()
.usingServer('http://localhost:9515')
.withCapabilities({
chromeOptions: {
binary: electronPath,
args: ['app=' + path.resolve()]
}
})
.forBrowser('electron')
.build();
});
after(async () => {
await this.driver.quit();
});
const findCounter = () => {
return this.driver.findElement(webdriver.By.className(counterStyles.counter));
};
const findButtons = () => {
return this.driver.findElements(webdriver.By.className(counterStyles.btn));
};
it('should open window', async () => {
const title = await this.driver.getTitle();
expect(title).to.equal('Hello Electron React!');
});
it('should to Counter with click "to Counter" link', async () => {
const link = await this.driver.findElement(webdriver.By.css(`.${homeStyles.container} > a`));
link.click();
const counter = await findCounter();
expect(await counter.getText()).to.equal('0');
});
it('should display updated count after increment button click', async () => {
const buttons = await findButtons();
buttons[0].click();
const counter = await findCounter();
expect(await counter.getText()).to.equal('1');
});
it('should display updated count after descrement button click', async () => {
const buttons = await findButtons();
const counter = await findCounter();
buttons[1].click(); // -
expect(await counter.getText()).to.equal('0');
});
it('shouldnt change if even and if odd button clicked', async () => {
const buttons = await findButtons();
const counter = await findCounter();
buttons[2].click(); // odd
expect(await counter.getText()).to.equal('0');
});
it('should change if odd and if odd button clicked', async () => {
const buttons = await findButtons();
const counter = await findCounter();
buttons[0].click(); // +
buttons[2].click(); // odd
expect(await counter.getText()).to.equal('2');
});
it('should change if async button clicked and a second later', async () => {
const buttons = await findButtons();
const counter = await findCounter();
buttons[3].click(); // async
expect(await counter.getText()).to.equal('2');
await this.driver.wait(() =>
counter.getText().then(text => text === '3')
, 1000, 'count not as expected');
});
it('should back to home if back button clicked', async () => {
const link = await this.driver.findElement(webdriver.By.css(`.${counterStyles.backButton} > a`));
link.click();
await this.driver.findElement(webdriver.By.className(homeStyles.container));
});
});