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 pathelementActions.test.js
More file actions
252 lines (197 loc) · 8.29 KB
/
elementActions.test.js
File metadata and controls
252 lines (197 loc) · 8.29 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*global page*/
import { Element } from "test-juggler";
describe("Element Actions", () => {
beforeEach(async () => {
console.log("Running test: " + jasmine["currentTest"].fullName);
});
it("should get element selector", async () => {
//Arrange
const element = new Element("some.selector");
//Act and Assert
expect(element.selector).toMatch("some.selector");
});
it("should get child element by XPath selector", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/");
//Act
const element = new Element("//div[@id='content']");
const childElement = element.newChildElement("//h1");
//Assert
await expect(childElement.isVisible()).resolves.toBeTruthy();
});
it("should wait for an element", 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 elementToLoad.wait();
//Assert
await expect(elementToLoad.exists()).resolves.toBeTruthy();
});
it("should wait for element to be visible", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/dynamic_loading/1");
const startButton = new Element("div#start>button");
const elementToLoad = new Element("div#finish");
//Act
await startButton.click();
await elementToLoad.waitUntilVisible();
//Assert
await expect(elementToLoad.isVisible()).resolves.toBeTruthy();
});
it("should wait for element to be invisible", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/dynamic_loading/1");
const startButton = new Element("div#start>button");
const loader = new Element("div#loading");
const elementToLoad = new Element("div#finish");
//Act
await startButton.click();
await loader.waitUntilInvisible();
//Assert
await expect(loader.isVisible()).resolves.toBeFalsy();
await expect(elementToLoad.isVisible()).resolves.toBeTruthy();
});
it("should click an element", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/add_remove_elements/");
const addElementButton = new Element("button[onclick='addElement()']");
const deleteButton = new Element("button[onclick='deleteElement()']");
//Act
await addElementButton.click();
//Assert
await expect(deleteButton.exists()).resolves.toBeTruthy();
});
it("should double click an element", async () => {
//Arrange
await page.goto("http://demo.guru99.com/test/simple_context_menu.html");
const doubleClickButton = new Element("#authentication > button");
var alertIsShown = false;
page.on("dialog", async dialog => {
alertIsShown = true;
await dialog.dismiss();
});
//Act
await doubleClickButton.doubleClick();
//Assert
expect(alertIsShown).toBeTruthy();
});
it("should right click an element", async () => {
//Arrange
await page.goto("http://demo.guru99.com/test/simple_context_menu.html");
const rightClickButton = new Element("span.context-menu-one");
const contextMenu = new Element("#context-menu-layer");
//Act
await rightClickButton.rightClick();
//Assert
await expect(contextMenu.exists()).resolves.toBeTruthy();
});
it("should check if element exist", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/");
const headerText = new Element(".heading");
//Act
const elementExists = await headerText.exists();
//Assert
expect(elementExists).toBeTruthy();
});
it("should check if element is visible", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/");
const headerText = new Element(".heading");
//Act
const elementIsVisible = await headerText.isVisible();
//Assert
expect(elementIsVisible).toBeTruthy();
});
//TODO: Unxit when issue is resolved in Puppeteer: https://github.com/puppeteer/puppeteer/issues/4562
xit("should Drag and Drop one element on to another", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/drag_and_drop");
const firstBox = new Element("#column-a");
const secondBox = new Element("#column-b");
const firstBoxInitialHeader = await firstBox.text();
console.log("First box initial header is: " + firstBoxInitialHeader);
const secondBoxInitialHeader = await secondBox.text();
console.log("Second box initial header is: " + secondBoxInitialHeader);
//Act
await firstBox.dragAndDrop(secondBox);
//Assert
const firstBoxResultHeader = await firstBox.text();
console.log("First box header after drag and drop is: " + firstBoxInitialHeader);
const secondBoxResultHeader = await secondBox.text();
console.log("Second box header after drag and drop is: " + secondBoxInitialHeader);
expect(firstBoxResultHeader).toMatch(secondBoxInitialHeader);
expect(secondBoxResultHeader).toMatch(firstBoxInitialHeader);
});
it("should get inner text of an element", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/");
const headerText = new Element(".heading");
//Act
const actualText = await headerText.text();
//Assert
expect(actualText).toMatch("Welcome to the-internet");
});
it("should get value of style attribute text-align of an element", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/inputs");
const element = new Element("#page-footer > div > div");
//Act
const actualTextAlignValue = await element.getStyleAttributeValue("text-align");
//Assert
expect(actualTextAlignValue).toMatch("center");
});
it("should hover on an element", async () => {
//Arrange
await page.goto("http://demo.guru99.com/test/tooltip.html");
const downloadButton = new Element("#download_now");
const tooltip = new Element("div.tooltip");
//Act
await downloadButton.hover();
//Assert
await expect(tooltip.isVisible()).resolves.toBeTruthy();
});
it("should get DOM element", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/");
const headerText = new Element(".heading");
//Act
const headerTextDomElement = await headerText.wait();
//Assert
await expect(headerTextDomElement.evaluate(domElement => domElement.textContent)).resolves.toMatch("Welcome to the-internet");
});
it("should get element's value", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/inputs");
const inputElement = new Element("input[type=number]");
const inputNumber = "123";
//Act
await page.type(inputElement.selector, inputNumber);
//Assert
expect(await inputElement.value()).toEqual(inputNumber);
});
it("should get element's attribute value", async () => {
//Arrange, Act
await page.goto("http://the-internet.herokuapp.com/login");
const formElement = new Element("#login");
const attributeName = "action";
//Assert
expect(await formElement.getAttributeValue(attributeName)).toEqual("/authenticate");
});
it("should type element's text value", async () => {
//Arrange
await page.goto("http://the-internet.herokuapp.com/inputs");
const inputElement = new Element("input[type=number]");
const inputNumber = "456";
//Act
await inputElement.enterText(inputNumber);
//Assert
expect(await inputElement.value()).toEqual(inputNumber);
});
xit("should cover element", async () => {
//TODO: Test should be added and unxit`ed when DTAF-78 is implemented.
});
});