Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit ecc50ee

Browse files
committed
Rewrite the second test using page objects.
1 parent 0e7abc2 commit ecc50ee

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

test/e2e.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,38 @@ class Page {
2222
}
2323

2424
get job() {
25-
return new Job(this.client.element(".job"));
25+
return new Job(this.client, this.client.element(".job"));
2626
}
2727
}
2828

29-
class Job {
30-
constructor(private job: WebdriverIO.Client<WebdriverIO.RawResult<WebdriverIO.Element>> & WebdriverIO.RawResult<WebdriverIO.Element>) {}
29+
abstract class Block {
30+
constructor(
31+
protected client: SpectronClient,
32+
protected selector: WebdriverIO.Client<WebdriverIO.RawResult<WebdriverIO.Element>> & WebdriverIO.RawResult<WebdriverIO.Element>
33+
) {}
34+
}
3135

36+
class Job extends Block {
3237
get output() {
33-
return this.job.element(".output");
38+
return this.selector.element(".output");
39+
}
40+
41+
get menu() {
42+
return new JobMenu(this.client, this.selector.element(".jobMenu"));
43+
}
44+
}
45+
46+
class JobMenu extends Block {
47+
get sigkillItem() {
48+
return this.client.element(".floatingMenuItem:first-of-type");
49+
}
50+
51+
get sigtermItem() {
52+
return this.client.element(".floatingMenuItem:last-of-type");
53+
}
54+
55+
open() {
56+
return this.selector.click();
3457
}
3558
}
3659

@@ -43,7 +66,7 @@ describe("application launch", function () {
4366
beforeEach(async () => {
4467
app = new Application({path: "node_modules/.bin/electron", args: ["."]});
4568
await app.start();
46-
app.client.waitUntilWindowLoaded();
69+
await app.client.waitUntilWindowLoaded();
4770
page = new Page(app.client);
4871
return page.waitTillLoaded();
4972
});
@@ -56,25 +79,21 @@ describe("application launch", function () {
5679

5780
it("can execute a command", async () => {
5881
await page.executeCommand("echo expected-text");
59-
const text = await page.job.output.getText();
82+
const output = await page.job.output.getText();
6083

61-
expect(text).to.contain("expected-text");
84+
expect(output).to.contain("expected-text");
6285
});
6386

64-
it("send signals via button", async () => {
87+
it.only("send signals via button", async () => {
6588
await page.executeCommand(`node ${join(__dirname, "test_files", "print_on_sigterm.js")}`);
6689

67-
return app.client.waitForExist(".jobMenu", timeout).
68-
click(".jobMenu").
69-
waitForExist(".floatingMenuItem").
70-
click(".floatingMenuItem:last-of-type").
71-
click(".jobMenu").
72-
waitForExist(".floatingMenuItem").
73-
click(".floatingMenuItem:first-of-type").
74-
waitForExist(".prompt").
75-
getText(".job .output").
76-
then(output => {
77-
expect(output).to.eql("Received SIGTERM");
78-
});
90+
await page.job.menu.open();
91+
await page.job.menu.sigtermItem.click();
92+
93+
await page.job.menu.open();
94+
await page.job.menu.sigkillItem.click();
95+
96+
const output = await page.job.output.getText();
97+
expect(output).to.eql("Received SIGTERM");
7998
});
8099
});

0 commit comments

Comments
 (0)