Skip to content

Commit

Permalink
fix: locator builder returns error when class name contains hyphen (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Nov 29, 2023
1 parent 8d8d9f9 commit d0901d8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/locator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cssToXPath = require('css-to-xpath');
const cssToXPath = require('convert-cssxpath');
const { sprintf } = require('sprintf-js');

const { xpathLocator } = require('./utils');
Expand Down Expand Up @@ -162,7 +162,7 @@ class Locator {
*/
toXPath() {
if (this.isXPath()) return this.value;
if (this.isCSS()) return cssToXPath(this.value);
if (this.isCSS()) return cssToXPath.convert(this.value);

throw new Error('Can\'t be converted to XPath');
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
"chai-string": "^1.5.0",
"chalk": "4.1.2",
"commander": "11.0.0",
"convert-cssxpath": "1.0.2",
"cross-spawn": "7.0.3",
"css-to-xpath": "0.1.0",
"envinfo": "7.11.0",
"escape-string-regexp": "4.0.0",
"figures": "3.2.0",
Expand Down
8 changes: 7 additions & 1 deletion test/unit/locator_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const xml = `<body>
<input name="name1" label="Выберите услугу" type="text" value=""/>
</div>
</fieldset>
<label>Hello<a href="#">Please click</a></label>
<label class="n-1">Hello<a href="#">Please click</a></label>
</div>
<input type="hidden" name="return_url" value="" id="return_url" />
</body>`;
Expand Down Expand Up @@ -205,6 +205,12 @@ describe('Locator', () => {
}).to.throw('round brackets');
});

it('should find element with class name contains hyphen', () => {
const l = Locator.build('').find('.n-1').first();
const nodes = xpath.select(l.toXPath(), doc);
expect(nodes).to.have.length(1, l.toXPath());
});

it('should throw an error when locator with specific position is nested', () => {
expect(() => {
Locator.build('tr').withChild(Locator.build('td').first());
Expand Down

0 comments on commit d0901d8

Please sign in to comment.