From c726fe409cbd89afff7c836b904c6b0f6c80e701 Mon Sep 17 00:00:00 2001 From: Vorobeyko Date: Mon, 4 Mar 2019 15:57:55 +0300 Subject: [PATCH 1/4] fix --- lib/locator.js | 4 ++-- test/unit/locator_test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/locator.js b/lib/locator.js index 8629feaa9..f38c42742 100644 --- a/lib/locator.js +++ b/lib/locator.js @@ -116,12 +116,12 @@ class Locator { } withChild(locator) { - const xpath = sprintf('%s//child::%s', this.toXPath(), removePrefix((new Locator(locator, 'css')).toXPath())); + const xpath = sprintf('%s[./child::%s]', this.toXPath(), removePrefix((new Locator(locator, 'css')).toXPath())); return new Locator({ xpath }); } withDescendant(locator) { - const xpath = sprintf('%s//descendant::%s', this.toXPath(), removePrefix((new Locator(locator, 'css')).toXPath())); + const xpath = sprintf('%s[./descendant::%s]', this.toXPath(), removePrefix((new Locator(locator, 'css')).toXPath())); return new Locator({ xpath }); } diff --git a/test/unit/locator_test.js b/test/unit/locator_test.js index 9b5d818f4..78625e439 100644 --- a/test/unit/locator_test.js +++ b/test/unit/locator_test.js @@ -123,9 +123,9 @@ describe('Locator', () => { it('should select element by siblings', () => { const l = Locator.build('//table') - .withChild('td') - .withText('Also Edit') - .first(); + .withChild(Locator.build('tr') + .withChild('td') + .withText('Also Edit')); const nodes = xpath.select(l.toXPath(), doc); expect(nodes).to.have.length(1, l.toXPath()); }); From 34092281e7b0d3da2c6b2b88c6bcaeb7ac355c22 Mon Sep 17 00:00:00 2001 From: Vorobeyko Date: Mon, 4 Mar 2019 16:02:38 +0300 Subject: [PATCH 2/4] Add negative test --- test/unit/locator_test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/unit/locator_test.js b/test/unit/locator_test.js index 78625e439..138f2f96c 100644 --- a/test/unit/locator_test.js +++ b/test/unit/locator_test.js @@ -130,6 +130,13 @@ describe('Locator', () => { expect(nodes).to.have.length(1, l.toXPath()); }); + it.only('should not select element by siblings', () => { + const l = Locator.build('//table') + .withChild('td'); + const nodes = xpath.select(l.toXPath(), doc); + expect(nodes).to.have.length(0, l.toXPath()); + }); + it('should select element by siblings', () => { const l = Locator.build('//table') .find('td') From 9dab659c6dfd90e70d990437dfb5dce4afdeb6c9 Mon Sep 17 00:00:00 2001 From: Vorobeyko Date: Mon, 4 Mar 2019 16:23:23 +0300 Subject: [PATCH 3/4] remove only --- test/unit/locator_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/locator_test.js b/test/unit/locator_test.js index 138f2f96c..7634ee7e1 100644 --- a/test/unit/locator_test.js +++ b/test/unit/locator_test.js @@ -130,7 +130,7 @@ describe('Locator', () => { expect(nodes).to.have.length(1, l.toXPath()); }); - it.only('should not select element by siblings', () => { + it('should not select element by siblings', () => { const l = Locator.build('//table') .withChild('td'); const nodes = xpath.select(l.toXPath(), doc); From ff201c20a4f723b6d069efd7654f45c1d328681d Mon Sep 17 00:00:00 2001 From: Vorobeyko Date: Mon, 4 Mar 2019 16:24:49 +0300 Subject: [PATCH 4/4] fix name test --- test/unit/locator_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/locator_test.js b/test/unit/locator_test.js index 7634ee7e1..e4b774e51 100644 --- a/test/unit/locator_test.js +++ b/test/unit/locator_test.js @@ -130,7 +130,7 @@ describe('Locator', () => { expect(nodes).to.have.length(1, l.toXPath()); }); - it('should not select element by siblings', () => { + it('should not select element by deep nested siblings', () => { const l = Locator.build('//table') .withChild('td'); const nodes = xpath.select(l.toXPath(), doc);