|
1 | 1 | import {
|
2 |
| - assert, |
3 |
| - centerOf, |
4 |
| - down, |
5 |
| - Key, |
6 |
| - keyboard, |
7 |
| - mouse, |
8 |
| - Region, |
9 |
| - right, |
10 |
| - screen, |
11 |
| - sleep, |
12 |
| - straightTo, |
| 2 | + assert, |
| 3 | + centerOf, |
| 4 | + down, imageResource, |
| 5 | + Key, |
| 6 | + keyboard, |
| 7 | + mouse, |
| 8 | + Region, |
| 9 | + right, |
| 10 | + screen, |
| 11 | + sleep, |
| 12 | + straightTo, |
13 | 13 | } from "@nut-tree/nut-js";
|
14 | 14 |
|
15 | 15 | import "@nut-tree/template-matcher";
|
16 | 16 |
|
17 | 17 | jest.setTimeout(60000);
|
18 | 18 |
|
19 | 19 | const openXfceMenu = async () => {
|
20 |
| - await mouse.move(straightTo(centerOf(screen.find("menu.png")))); |
21 |
| - await mouse.leftClick(); |
22 |
| - await mouse.leftClick(); |
| 20 | + await mouse.move(straightTo(centerOf(screen.find(imageResource("menu.png"))))); |
| 21 | + await mouse.leftClick(); |
| 22 | + await mouse.leftClick(); |
23 | 23 | };
|
24 | 24 |
|
25 | 25 | const run = async (cmd: string) => {
|
26 |
| - await keyboard.type(Key.LeftAlt, Key.F2); |
27 |
| - await keyboard.type(cmd); |
28 |
| - await keyboard.type(Key.Enter); |
| 26 | + await keyboard.type(Key.LeftAlt, Key.F2); |
| 27 | + await keyboard.type(cmd); |
| 28 | + await keyboard.type(Key.Enter); |
29 | 29 | };
|
30 | 30 |
|
31 | 31 | const calculate = async () => {
|
32 |
| - await mouse.move(straightTo(centerOf(screen.find("plus.png")))); |
33 |
| - await mouse.leftClick(); |
34 |
| - await mouse.move(straightTo(centerOf(screen.find("one.png")))); |
35 |
| - await mouse.leftClick(); |
36 |
| - await mouse.move(straightTo(centerOf(screen.find("zero.png")))); |
37 |
| - await mouse.leftClick(); |
38 |
| - await mouse.leftClick(); |
39 |
| - await mouse.move(straightTo(centerOf(screen.find("equals.png")))); |
40 |
| - await mouse.leftClick(); |
| 32 | + await mouse.move(straightTo(centerOf(screen.find(imageResource("plus.png"))))); |
| 33 | + await mouse.leftClick(); |
| 34 | + await mouse.move(straightTo(centerOf(screen.find(imageResource("one.png"))))); |
| 35 | + await mouse.leftClick(); |
| 36 | + await mouse.move(straightTo(centerOf(screen.find(imageResource("zero.png"))))); |
| 37 | + await mouse.leftClick(); |
| 38 | + await mouse.leftClick(); |
| 39 | + await mouse.move(straightTo(centerOf(screen.find(imageResource("equals.png"))))); |
| 40 | + await mouse.leftClick(); |
41 | 41 | };
|
42 | 42 |
|
43 | 43 | const close = async () => {
|
44 |
| - await mouse.move(straightTo(centerOf(screen.find("close.png")))); |
45 |
| - await mouse.leftClick(); |
| 44 | + await mouse.move(straightTo(centerOf(screen.find(imageResource("close.png"))))); |
| 45 | + await mouse.leftClick(); |
46 | 46 | };
|
47 | 47 |
|
48 | 48 | describe("E2E tests", () => {
|
49 |
| - afterEach(async () => { |
50 |
| - await keyboard.type(Key.LeftControl, Key.LeftAlt, Key.Left); |
51 |
| - }); |
| 49 | + afterEach(async () => { |
| 50 | + await keyboard.type(Key.LeftControl, Key.LeftAlt, Key.Left); |
| 51 | + }); |
52 | 52 |
|
53 |
| - it("should throw on invalid images", async () => { |
54 |
| - await expect(screen.find("mouse.png")).rejects.toContain("Failed to load image"); |
55 |
| - }); |
| 53 | + it("should throw on invalid images", async () => { |
| 54 | + await expect(screen.find(imageResource("mouse.png"))).rejects.toContain("Failed to load image"); |
| 55 | + }); |
56 | 56 |
|
57 |
| - it("should perform some calculations", async () => { |
58 |
| - screen.config.resourceDirectory = "./e2e/assets"; |
59 |
| - await assert.isVisible("mouse.png"); |
60 |
| - await assert.isVisible("desktop.png"); |
61 |
| - await openXfceMenu(); |
62 |
| - await run("gnome-calculator"); |
63 |
| - await sleep(1500); |
64 |
| - await assert.isVisible("calculator.png"); |
65 |
| - await keyboard.type("525"); |
66 |
| - await calculate(); |
67 |
| - await screen.waitFor("result.png"); |
68 |
| - await close(); |
69 |
| - }); |
| 57 | + it("should perform some calculations", async () => { |
| 58 | + screen.config.resourceDirectory = "./e2e/assets"; |
| 59 | + await assert.isVisible(imageResource("mouse.png")); |
| 60 | + await assert.isVisible(imageResource("desktop.png")); |
| 61 | + await openXfceMenu(); |
| 62 | + await run("gnome-calculator"); |
| 63 | + await sleep(1500); |
| 64 | + await assert.isVisible(imageResource("calculator.png")); |
| 65 | + await keyboard.type("525"); |
| 66 | + await calculate(); |
| 67 | + await screen.waitFor(imageResource("result.png")); |
| 68 | + await close(); |
| 69 | + }); |
70 | 70 |
|
71 |
| - it("drag & drop", async () => { |
72 |
| - screen.config.resourceDirectory = "./e2e/assets"; |
| 71 | + it("drag & drop", async () => { |
| 72 | + screen.config.resourceDirectory = "./e2e/assets"; |
73 | 73 |
|
74 |
| - const expected = new Region(38, 585, 70, 86); |
75 |
| - const maxDiff = 1; |
| 74 | + const expected = new Region(34, 574, 75, 107); |
| 75 | + const maxDiff = 1; |
76 | 76 |
|
77 |
| - await assert.isVisible("trash.png"); |
78 |
| - await mouse.move(straightTo(centerOf(screen.find("trash.png")))); |
79 |
| - await mouse.drag(down(500)); |
80 |
| - await mouse.move(right(100)); |
81 |
| - await mouse.leftClick(); |
82 |
| - const dest = await screen.waitFor("moved_trash.png"); |
83 |
| - expect(Math.abs(dest.left - expected.left)).toBeLessThanOrEqual(maxDiff); |
84 |
| - expect(Math.abs(dest.top - expected.top)).toBeLessThanOrEqual(maxDiff); |
85 |
| - expect(Math.abs(dest.width - expected.width)).toBeLessThanOrEqual(maxDiff); |
86 |
| - expect(Math.abs(dest.height - expected.height)).toBeLessThanOrEqual(maxDiff); |
87 |
| - }); |
| 77 | + await assert.isVisible(imageResource("trash.png")); |
| 78 | + await mouse.move(straightTo(centerOf(screen.find(imageResource("trash.png"))))); |
| 79 | + await mouse.drag(down(500)); |
| 80 | + await mouse.move(right(100)); |
| 81 | + await mouse.leftClick(); |
| 82 | + const dest = await screen.waitFor(imageResource("moved_trash.png")); |
| 83 | + expect(Math.abs(dest.left - expected.left)).toBeLessThanOrEqual(maxDiff); |
| 84 | + expect(Math.abs(dest.top - expected.top)).toBeLessThanOrEqual(maxDiff); |
| 85 | + expect(Math.abs(dest.width - expected.width)).toBeLessThanOrEqual(maxDiff); |
| 86 | + expect(Math.abs(dest.height - expected.height)).toBeLessThanOrEqual(maxDiff); |
| 87 | + }); |
88 | 88 | });
|
0 commit comments