Skip to content

Commit 4f86c34

Browse files
author
DavertMik
committed
fixed unit tests
1 parent be2a3f9 commit 4f86c34

File tree

2 files changed

+130
-2
lines changed

2 files changed

+130
-2
lines changed

lib/helper/errors/ElementNotFound.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import Locator from '../../locator.js'
55
*/
66
class ElementNotFound {
77
constructor(locator, prefixMessage = 'Element', postfixMessage = 'was not found by text|CSS|XPath') {
8+
let locatorStr
89
if (typeof locator === 'object') {
9-
locator = JSON.stringify(locator)
10+
locatorStr = JSON.stringify(locator)
11+
} else {
12+
locatorStr = new Locator(locator).toString()
1013
}
11-
throw new Error(`${prefixMessage} "${new Locator(locator)}" ${postfixMessage}`)
14+
throw new Error(`${prefixMessage} "${locatorStr}" ${postfixMessage}`)
1215
}
1316
}
1417

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Shadow DOM Test</title>
5+
<style>
6+
body { font-family: Arial, sans-serif; padding: 20px; }
7+
.result { margin-top: 20px; padding: 10px; background: #f5f5f5; border-radius: 4px; }
8+
</style>
9+
</head>
10+
<body>
11+
<h1>Shadow DOM Test Page</h1>
12+
13+
<p>This page contains Web Components with Shadow DOM for testing.</p>
14+
15+
<!-- Simple shadow DOM component -->
16+
<my-button id="simple-component"></my-button>
17+
18+
<!-- Nested shadow DOM components -->
19+
<my-app id="nested-component"></my-app>
20+
21+
<div class="result">
22+
<p>Clicked: <span id="clicked-element">none</span></p>
23+
<p>Input value: <span id="input-value">empty</span></p>
24+
</div>
25+
26+
<script>
27+
// Simple button component
28+
class MyButton extends HTMLElement {
29+
constructor() {
30+
super();
31+
const shadow = this.attachShadow({ mode: 'open' });
32+
shadow.innerHTML = `
33+
<style>
34+
button {
35+
padding: 10px 20px;
36+
background: #007bff;
37+
color: white;
38+
border: none;
39+
border-radius: 4px;
40+
cursor: pointer;
41+
}
42+
button:hover { background: #0056b3; }
43+
</style>
44+
<button class="shadow-button">Click Me (Shadow)</button>
45+
`;
46+
47+
shadow.querySelector('button').addEventListener('click', () => {
48+
document.getElementById('clicked-element').textContent = 'my-button > button';
49+
});
50+
}
51+
}
52+
customElements.define('my-button', MyButton);
53+
54+
// Container component
55+
class MyApp extends HTMLElement {
56+
constructor() {
57+
super();
58+
const shadow = this.attachShadow({ mode: 'open' });
59+
shadow.innerHTML = `
60+
<style>
61+
.app-container {
62+
padding: 20px;
63+
border: 2px solid #333;
64+
border-radius: 8px;
65+
margin: 10px 0;
66+
}
67+
h2 { margin-top: 0; }
68+
</style>
69+
<div class="app-container">
70+
<h2>My App (Shadow Root)</h2>
71+
<my-form></my-form>
72+
</div>
73+
`;
74+
}
75+
}
76+
customElements.define('my-app', MyApp);
77+
78+
// Form component (nested inside my-app)
79+
class MyForm extends HTMLElement {
80+
constructor() {
81+
super();
82+
const shadow = this.attachShadow({ mode: 'open' });
83+
shadow.innerHTML = `
84+
<style>
85+
.form-group { margin: 10px 0; }
86+
label { display: block; margin-bottom: 5px; font-weight: bold; }
87+
input {
88+
padding: 8px;
89+
border: 1px solid #ccc;
90+
border-radius: 4px;
91+
width: 200px;
92+
}
93+
button {
94+
padding: 8px 16px;
95+
background: #28a745;
96+
color: white;
97+
border: none;
98+
border-radius: 4px;
99+
cursor: pointer;
100+
margin-top: 10px;
101+
}
102+
</style>
103+
<div class="form-group">
104+
<label for="shadow-input">Name</label>
105+
<input type="text" id="shadow-input" class="shadow-input" placeholder="Enter name">
106+
</div>
107+
<button class="submit-btn">Submit</button>
108+
`;
109+
110+
const input = shadow.querySelector('input');
111+
const submitBtn = shadow.querySelector('button');
112+
113+
input.addEventListener('input', () => {
114+
document.getElementById('input-value').textContent = input.value || 'empty';
115+
});
116+
117+
submitBtn.addEventListener('click', () => {
118+
document.getElementById('clicked-element').textContent = 'my-app > my-form > button';
119+
});
120+
}
121+
}
122+
customElements.define('my-form', MyForm);
123+
</script>
124+
</body>
125+
</html>

0 commit comments

Comments
 (0)