Skip to content

Commit 2f45497

Browse files
committed
Added e2e test suits
1 parent dd3e05a commit 2f45497

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

index.e2e.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { assert, Key, keyboard, Location, mouse, movement, screen } from "./index";
2+
3+
const openXfceMenu = async () => {
4+
const menu = await screen.find("menu.png");
5+
await mouse.move(await movement.straightTo(Location.centerOf(menu)));
6+
await mouse.leftClick();
7+
await mouse.leftClick();
8+
};
9+
10+
const run = async (cmd: string) => {
11+
await keyboard.type(Key.LeftAlt, Key.F2);
12+
await keyboard.type(cmd);
13+
await keyboard.type(Key.Enter);
14+
};
15+
16+
const calculate = async () => {
17+
const plus = await screen.find("plus.png");
18+
await mouse.move(await movement.straightTo(Location.centerOf(plus)));
19+
await mouse.leftClick();
20+
const one = await screen.find("one.png");
21+
await mouse.move(await movement.straightTo(Location.centerOf(one)));
22+
await mouse.leftClick();
23+
const zero = await screen.find("zero.png");
24+
await mouse.move(await movement.straightTo(Location.centerOf(zero)));
25+
await mouse.leftClick();
26+
await mouse.leftClick();
27+
await keyboard.type(Key.Enter);
28+
};
29+
30+
const close = async () => {
31+
const x = await screen.find("close.png");
32+
await mouse.move(await movement.straightTo(Location.centerOf(x)));
33+
await mouse.leftClick();
34+
};
35+
36+
describe("E2E demo", () => {
37+
it("should run without throwing", async () => {
38+
jest.setTimeout(30000);
39+
screen.config.resourceDirectory = "./e2e/assets";
40+
await assert.isVisible("mouse.png");
41+
await assert.isVisible("desktop.png");
42+
await openXfceMenu();
43+
await run("gnome-calculator");
44+
await assert.isVisible("calculator.png");
45+
await keyboard.type("525");
46+
await calculate();
47+
await assert.isVisible("result.png");
48+
await close();
49+
});
50+
});

lib/keyboard.class.e2e.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { jestMatchers, Key, keyboard, screen } from "../index";
2+
3+
expect.extend(jestMatchers);
4+
5+
const run = async (cmd: string) => {
6+
await keyboard.type(Key.LeftAlt, Key.F2);
7+
await keyboard.type(cmd);
8+
await keyboard.type(Key.Enter);
9+
};
10+
11+
const confirm = async () => {
12+
await keyboard.type(Key.Enter);
13+
};
14+
15+
const close = async () => {
16+
await keyboard.type(Key.LeftAlt, Key.F4);
17+
};
18+
19+
describe("Keyboard e2e class", () => {
20+
it("should paste copied input from system clipboard.", async () => {
21+
// GIVEN
22+
jest.setTimeout(30000);
23+
screen.config.resourceDirectory = "./e2e/assets";
24+
await run("gnome-calculator");
25+
await confirm();
26+
27+
// WHEN
28+
29+
// THEN
30+
await expect(screen).toShow("calculator.png");
31+
await close();
32+
});
33+
});

0 commit comments

Comments
 (0)