Skip to content

Commit d0901d8

Browse files
authored
fix: locator builder returns error when class name contains hyphen (#4024)
1 parent 8d8d9f9 commit d0901d8

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

Diff for: lib/locator.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const cssToXPath = require('css-to-xpath');
1+
const cssToXPath = require('convert-cssxpath');
22
const { sprintf } = require('sprintf-js');
33

44
const { xpathLocator } = require('./utils');
@@ -162,7 +162,7 @@ class Locator {
162162
*/
163163
toXPath() {
164164
if (this.isXPath()) return this.value;
165-
if (this.isCSS()) return cssToXPath(this.value);
165+
if (this.isCSS()) return cssToXPath.convert(this.value);
166166

167167
throw new Error('Can\'t be converted to XPath');
168168
}

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
"chai-string": "^1.5.0",
8181
"chalk": "4.1.2",
8282
"commander": "11.0.0",
83+
"convert-cssxpath": "1.0.2",
8384
"cross-spawn": "7.0.3",
84-
"css-to-xpath": "0.1.0",
8585
"envinfo": "7.11.0",
8686
"escape-string-regexp": "4.0.0",
8787
"figures": "3.2.0",

Diff for: test/unit/locator_test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const xml = `<body>
4949
<input name="name1" label="Выберите услугу" type="text" value=""/>
5050
</div>
5151
</fieldset>
52-
<label>Hello<a href="#">Please click</a></label>
52+
<label class="n-1">Hello<a href="#">Please click</a></label>
5353
</div>
5454
<input type="hidden" name="return_url" value="" id="return_url" />
5555
</body>`;
@@ -205,6 +205,12 @@ describe('Locator', () => {
205205
}).to.throw('round brackets');
206206
});
207207

208+
it('should find element with class name contains hyphen', () => {
209+
const l = Locator.build('').find('.n-1').first();
210+
const nodes = xpath.select(l.toXPath(), doc);
211+
expect(nodes).to.have.length(1, l.toXPath());
212+
});
213+
208214
it('should throw an error when locator with specific position is nested', () => {
209215
expect(() => {
210216
Locator.build('tr').withChild(Locator.build('td').first());

0 commit comments

Comments
 (0)