-
Notifications
You must be signed in to change notification settings - Fork 35
Allows the usage of XPath selectors to target elements #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Tests apparently fail on IE, I suppose that IE still doesn't support XPath. I don't know if you are comfortable with it, but we could add a shim: https://github.com/google/wicked-good-xpath It is not important for my use case, but I assume if we put this feature, we should also add this. |
It makes sense. But I think we should export a new API such as Could you split codes for XPaths to the new API? |
Sure, will do that within the next 24 hours :) |
I separated the API. However I couldn't get wgxpath to work, am not familiar with TypeScript. |
.assert.containsText('#result', 'OK') | ||
.end(); | ||
}, | ||
'Drag and Drop with Nightwatch using XPath': function(browser) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test case should split to another file.
In my understanding, the official document of Nightwatch.js said that we should call browser.end()
only once on a file:
Remember always to call the .end() method when you want to close your test, in order for the Selenium session to be properly closed.
But browser.end()
is unexpectedly called twice in the file.
So It will cause a test failure like:
Running: Drag and Drop with Nightwatch using CSS selectors
✔ Testing if element <#result> contains text: "NG".
✔ Testing if element <#result> contains text: "OK".
No assertions ran.
Running: Drag and Drop with Nightwatch using XPath
✖ Testing if element <#result> contains text: "NG". Element could not be located. - expected "NG" but got: null
Thank you! 😄
I think a polyfill of |
I confirmed that following steps can make test pass on IE9:
diff --git a/test/e2e/selenium-webdriver/index.js b/test/e2e/selenium-webdriver/index.js
index c4705fa..be464be 100755
--- a/test/e2e/selenium-webdriver/index.js
+++ b/test/e2e/selenium-webdriver/index.js
@@ -116,6 +116,8 @@ describe('html-dnd', function() {
it('should can drag and drop', function() {
driver.get(TEST_PAGE_URL);
+ useXPathPolyfill(driver);
+
return webdriver.promise
.all([
driver.executeScript(
@@ -138,3 +140,13 @@ describe('html-dnd', function() {
});
});
});
+
+
+var Fs = require('fs');
+var Path = require('path');
+
+function useXPathPolyfill(driver) {
+ var WGXPATH_INSTALLER_PATH = Path.resolve(__dirname, '../asset/wgxpath.install.v1.3.0.js');
+ driver.executeScript(Fs.readFileSync(WGXPATH_INSTALLER_PATH, 'utf8'));
+ driver.executeScript('wgxpath.install();');
+} |
Alright! I had also thought of the possibility of letting the user polyfill when required by his project, but then I thought maybe html-dnd wanted to be an all-in-one solution. Ok then, will update the PR between today and tomorrow. |
Wgxpath is used to polyfill browsers which don't have a spec-compliant implementation of `document.evaluate`. @see https://github.com/google/wicked-good-xpath
ea01954
to
ff4ad63
Compare
All checks have passed! 🎉 |
LGTM 👍 |
Thank you @sunyatasattva 🙏 |
お疲れ様でした @Kuniwak 🙇 |
I have added an optional parameter
useXPath
which, iftrue
, allows for XPath selectors to be passed to the the drag and drop function, for those cases in which CSS selectors just don't cut it.