-
Notifications
You must be signed in to change notification settings - Fork 451
Expand file tree
/
Copy pathclick.test.js
More file actions
199 lines (186 loc) · 6.17 KB
/
click.test.js
File metadata and controls
199 lines (186 loc) · 6.17 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
const chai = require("chai");
const expect = chai.expect;
const chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
const {
openBrowser,
click,
closeBrowser,
goto,
text,
button,
below,
setConfig,
accept,
alert,
evaluate,
} = require("../../lib/taiko");
const {
createHtml,
removeFile,
openBrowserArgs,
resetConfig,
} = require("./test-util");
const test_name = "Click";
describe(test_name, () => {
let filePath;
before(async () => {
const innerHtml = `
<span>Click with proximity</span>
<div>
<span id='something' onclick="displayText('Click works with text nodes.')">Click on text node</span>
<span>Click with proximity</span>
</div>
<div>
<input type="checkbox" onclick="displayText('Click works with ghost element covering text.')"
style="
opacity:0.01;
width:400px;
height:20px;
position: absolute
"
/>
<span class='b'>Click ghost element covering text.</span>
</div>
</div>
<span>Proximity marker</span>
<input onclick="displayText('Click works with text as value.')" value="Text as value"/><br/>
<input onclick="displayText('Click works with text as type.')" type="Text as type"/><br/>
<span onclick="displayText('Click works with proximity selector.')">Click with proximity</span>
<div onclick="displayText('Click works with text accross element.')">
Text <span>accross</span> elements
</div>
<script type="text/javascript">
function displayText(text) {
document.getElementById('root').innerText = text
}
</script>
<div id="root" style="background:red;"></div>
<span onclick="displayText('Click works with auto scroll.')">Show Message</span>
<style>
.overlayContainer{
position:relative;
}
.overlay {
position: absolute;
top:0;
left:0;
width:100%;
height:100%;
text-align:center;
}
</style>
<div class="overlayContainer">
<div class='a'>Click Element covered</div>
<span class='overlay'></span>
</div>
<button type="button" disabled>Click Me!</button>
<script>
class ShadowButton extends HTMLElement {
constructor() {
super();
var shadow = this.attachShadow({mode: 'open'});
var button = document.createElement('input');
button.setAttribute('type', 'button');
button.setAttribute('value', 'Shadow Click');
button.addEventListener("click", event => {
alert("Hello from the shadows");
});
shadow.appendChild(button);
}
}
customElements.define('shadow-button', ShadowButton);
</script>
<shadow-button>
`;
filePath = createHtml(innerHtml, test_name);
await openBrowser(openBrowserArgs);
await goto(filePath);
setConfig({
waitForNavigation: false,
retryTimeout: 10,
retryInterval: 10,
});
});
after(async () => {
resetConfig();
await closeBrowser();
removeFile(filePath);
});
describe("scroll to click", () => {
it("test if auto scrolls to element before clicking", async () => {
await click("Show Message");
expect(await text("Click works with auto scroll.").exists()).to.be.true;
});
});
describe("With text nodes", () => {
it("should click", async () => {
await click("on text");
expect(await text("Click works with text nodes.").exists()).to.be.true;
});
it("element click with coordinates", async () => {
const { x, y } = await evaluate(() => {
const { x, y } = document
.querySelector("#something")
.getBoundingClientRect();
return { x, y };
});
await click({ x, y });
expect(await text("Click works with text nodes.").exists()).to.be.true;
});
});
describe("element inside shadow dom", () => {
it("should click", async () => {
alert("Hello from the shadows", async () => {
await accept();
});
await click(button("Shadow Click"));
});
});
describe("With proximity selector", () => {
it("should click", async () => {
await click("Click with proximity", below("Proximity marker"));
expect(await text("Click works with proximity selector.").exists()).to.be
.true;
});
});
describe("Text accross element", () => {
it("should click", async () => {
await click("Text accross elements");
expect(await text("Click works with text accross element.").exists()).to
.be.true;
});
});
describe("Text as value", () => {
it("should click", async () => {
await click("Text as value");
expect(await text("Click works with text as value.").exists()).to.be.true;
});
});
describe("With ghost element", () => {
it("should click the ghost element", async () => {
await click("Click ghost element covering text");
expect(
await text("Click works with ghost element covering text.").exists(),
).to.be.true;
});
describe("With element covered by an overlay", () => {
it("should throw error", async () => {
await expect(click("Click Element covered")).to.be.rejectedWith(
'Element matching text "Click Element covered" is covered by other element',
);
});
});
describe("With element disabled", () => {
it("should throw error if element is disabled", async () => {
await expect(click(button("Click me"))).to.be.rejectedWith(
"Button with label Click me is disabled",
);
});
it("should click when forced", async () => {
await expect(click(button("Click me"), { force: true })).eventually
.fulfilled;
});
});
});
});