From d0901d89920074f2dc0b6db736517c53b56a27c6 Mon Sep 17 00:00:00 2001 From: KobeNguyenT <7845001+kobenguyent@users.noreply.github.com> Date: Wed, 29 Nov 2023 07:09:10 +0100 Subject: [PATCH] fix: locator builder returns error when class name contains hyphen (#4024) --- lib/locator.js | 4 ++-- package.json | 2 +- test/unit/locator_test.js | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/locator.js b/lib/locator.js index 85aa29009..ab7db428e 100644 --- a/lib/locator.js +++ b/lib/locator.js @@ -1,4 +1,4 @@ -const cssToXPath = require('css-to-xpath'); +const cssToXPath = require('convert-cssxpath'); const { sprintf } = require('sprintf-js'); const { xpathLocator } = require('./utils'); @@ -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'); } diff --git a/package.json b/package.json index 74fff3197..81cd23a70 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/unit/locator_test.js b/test/unit/locator_test.js index 9520555e0..44e6ccbc2 100644 --- a/test/unit/locator_test.js +++ b/test/unit/locator_test.js @@ -49,7 +49,7 @@ const xml = ` - + `; @@ -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());