This repository was archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhelpers.test.js
More file actions
129 lines (102 loc) · 4.44 KB
/
helpers.test.js
File metadata and controls
129 lines (102 loc) · 4.44 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { Element, Helpers } from "test-juggler";
import helpers from "../../framework/helpers";
const fs = require("fs");
describe("Helpers", () => {
beforeEach(async () => {
console.log("Running test: " + jasmine["currentTest"].fullName);
});
it("should take screenshot, save to logs folder and return filepath", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/");
const fileName = Date.now();
const expectedFilePath = `./logs/Helpers/should take screenshot, save to logs folder and return filepath/${fileName}.png`;
//Act
const actualFilePath = await Helpers.takeScreenshot(fileName);
//Assert
expect(actualFilePath).toBe(expectedFilePath);
expect(fs.existsSync(actualFilePath)).toBeTruthy();
});
it("should use date now for screenshot file name when none is provided", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/");
//Act
const actualFilePath = await Helpers.takeScreenshot();
//Assert
expect(actualFilePath).toContain(Date.now().toString().slice(0, -6));
});
it("should retry until action have succeeded", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/dynamic_loading/2");
const startButton = new Element("div#start>button");
const elementToLoad = new Element("div#finish");
//Act
await startButton.click();
await Helpers.retry(async () => {
await elementToLoad.click();
});
//Assert
await expect(elementToLoad.exists()).resolves.toBeTruthy();
});
it("should enter iFrame and get text", async () => {
//Arrange
const iFrameSelector = "#mce_0_ifr";
const textFrameSelector = "#tinymce p";
await page.goto("http://the-internet.herokuapp.com/iframe");
//Act
const frame = await Helpers.getFrame(iFrameSelector);
const textContent = await frame.$eval(textFrameSelector, element => element.textContent);
//Assert
expect(textContent).toEqual("Your content goes here.");
});
it("should setup new page", async () => {
//Arrange
const config = require(process.cwd() + "/test-juggler.config");
const newPage = await browser.newPage();
//Act
await Helpers.pageSetup(newPage);
//Assert
expect(newPage._timeoutSettings.timeout({})).toEqual(config.defaultTimeout);
});
it("should generate random text with no characters specified", async () => {
//Arrange, Act
const text = await Helpers.generateRandomText(10);
const regex = /^[A-Za-z0-9]+$/;
//Assert
expect(regex.test(text)).toBeTruthy();
expect(text.length).toEqual(10);
});
it("should generate random text with custom characters list", async () => {
//Arrange
const chars = "0123456789";
const regex = /^[0-9]+$/;
//Act
const text = await Helpers.generateRandomText(8, chars);
//Assert
expect(regex.test(text)).toBeTruthy();
expect(text.length).toEqual(8);
});
it("should accept opened alerts", async () => {
//Arrange
const pageWithAcceptAlertsSetup = await browser.newPage();
await Helpers.acceptPopupsOnPage(pageWithAcceptAlertsSetup);
const resultElement = new Element("#result", pageWithAcceptAlertsSetup);
//Act
await pageWithAcceptAlertsSetup.goto("http://the-internet.herokuapp.com/javascript_alerts");
await pageWithAcceptAlertsSetup.click("button[onclick='jsAlert()']");
const resultElementText = await resultElement.text();
//Assert
expect(resultElementText).toMatch("You successfully clicked an alert");
});
it("should close opened alerts", async () => {
//Arrange
const pageWithDismissAlertsSetup = await browser.newPage();
await Helpers.dismissPopupsOnPage(pageWithDismissAlertsSetup);
const resultElement = new Element("#result", pageWithDismissAlertsSetup);
//Act
await pageWithDismissAlertsSetup.goto("http://the-internet.herokuapp.com/javascript_alerts");
await pageWithDismissAlertsSetup.click("button[onclick='jsAlert()']");
const resultElementText = await resultElement.text();
//Assert
expect(resultElementText).toMatch("You successfully clicked an alert");
});
});