sebv / node-wd-sync Goto Github PK
View Code? Open in Web Editor NEWsync version of wd
License: MIT License
sync version of wd
License: MIT License
Hi,
I'm trying to execute some javascrpt on the page during test, for example remove element or set some attributes. Javascript is execute successfully but I can't see that in browser.
Am I doing something wrong?
Hey :)
I may just be retarded here, but I'm going a bit loco with this problem of mine. I'm trying to manipulate a DOM element in the browser with .execute('my code', [myElement]) and failing miserably with wd-sync.
Working code with vanilla wd:
browser.elementByCssSelector('h1', function (e, elem) {
console.log(elem);
browser.execute('arguments[0].className += " hidden"', [elem]);
});
Equivalent non-working wd-sync code:
var elem = browser.elementByCssSelector('h1');
console.log(elem);
browser.execute('arguments[0].className += " hidden"', [elem]);
The vanilla wd code adds the class as suspected, while the wd-sync code halts execution without errors (equivalent to a process.exit()) without doing anything with the DOM.
I can do browser.execute('console.log(arguments)', [3, 'nice', 'arguments']);
with wd-sync, but as soon as I try to pass an element along, it breaks down.
I note that the console.log(el)
output is significantly different between the two. Vanilla wd:
{ value: '0',
browser:
EventEmitter {
domain:
Domain {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
members: [] },
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
configUrl:
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: '127.0.0.1:4444',
port: '4444',
hostname: '127.0.0.1',
hash: null,
search: '',
query: {},
pathname: '/wd/hub',
path: '/wd/hub',
href: 'http://127.0.0.1:4444/wd/hub' },
sauceRestRoot: 'https://saucelabs.com/rest/v1',
noAuthConfigUrl:
Url {
protocol: 'http:',
slashes: true,
host: '127.0.0.1:4444',
port: '4444',
hostname: '127.0.0.1',
hash: null,
search: null,
query: null,
pathname: '/wd/hub',
path: '/wd/hub',
href: 'http://127.0.0.1:4444/wd/hub' },
defaultCapabilities:
{ browserName: 'firefox',
version: '',
javascriptEnabled: true,
platform: 'ANY' },
_httpConfig:
{ timeout: undefined,
retries: 3,
retryDelay: 15,
baseUrl: undefined,
proxy: undefined },
sessionID: '80a45e74-0bc9-4b89-b62e-210724d93b74' } }
And wd-sync:
{ emit: [Function],
toString: [Function],
toJSON: [Function],
type: [Function],
keys: [Function],
sendKeys: [Function],
click: [Function],
tap: [Function],
doubleclick: [Function],
doubleClick: [Function],
moveTo: [Function],
flick: [Function],
text: [Function],
textPresent: [Function],
getAttribute: [Function],
getTagName: [Function],
isDisplayed: [Function],
displayed: [Function],
isSelected: [Function],
selected: [Function],
isEnabled: [Function],
enabled: [Function],
isVisible: [Function],
getLocation: [Function],
getLocationInView: [Function],
getSize: [Function],
getValue: [Function],
getComputedCss: [Function],
getComputedCSS: [Function],
clear: [Function],
submit: [Function],
elementByClassName: [Function],
elementsByClassName: [Function],
elementByCssSelector: [Function],
elementsByCssSelector: [Function],
elementById: [Function],
elementsById: [Function],
elementByName: [Function],
elementsByName: [Function],
elementByLinkText: [Function],
elementsByLinkText: [Function],
elementByPartialLinkText: [Function],
elementsByPartialLinkText: [Function],
elementByTagName: [Function],
elementsByTagName: [Function],
elementByXPath: [Function],
elementsByXPath: [Function],
elementByCss: [Function],
elementsByCss: [Function],
elementByIosUIAutomation: [Function],
elementsByIosUIAutomation: [Function],
elementByAndroidUIAutomator: [Function],
elementsByAndroidUIAutomator: [Function],
elementByAccessibilityId: [Function],
elementsByAccessibilityId: [Function],
element: [Function],
elements: [Function],
equals: [Function],
sleep: [Function],
noop: [Function],
performTouch: [Function],
performTouchAction: [Function],
performMultiTouch: [Function],
performMultiTouchAction: [Function],
rotate: [Function],
setImmediateValueInApp: [Function],
setImmediateValue: [Function] }
What's going wrong here?
Thanks :)
FYI: When using vanilla wd I'm using the module that is pulled in by wd-sync's package.json, so it's the same underlying code.
@sebv, since you went through all the trouble of porting wd to a synchronous API, I figured you must have had a good reason. :)
For someone just starting out with integration testing using Selenium, do you find it easier to create end-to-end tests using a synchronous vs. async API?
I've been playing around with your promise-chain API over on the main project, and I have been struggling a bit with understanding the "magic" of how objects/elements returned from one function in the chain are passed to the next. I'm curious if the sync API might be more "intuitive". On the other hand, I imagine there are cases where the sync API is limited in what it can express (for instance, waiting for two different async functions to complete before moving on in the chain, like you demonstrate using Q.all
in the other project).
Just wanted to get your insight about these two approaches. Do each excel at different problems? Is one usually better for "large scale end to end testing"?
Thanks for any advice.
I'm wondering if it's possible to re-use the browser across multiple tests, so that I don't have to wait for a browser to open for every test. I'm using the Mocha BDD style for tests right now, but if there is a testing framework better suited to wd-sync, I'm happy to change frameworks. Here is a gist showing what I'm doing now: https://gist.github.com/3490535
Ideally, I could browser.init() just once, before the tests run, but I run into errors like "needs a fiber". Do you have any suggestions? Thank you!
Hi,
Thanks for a great library! I've started to use the js version of the library and find it really useful. I'm trying to implement a click on an tag, load and verify the page title on the new page is correct.
I've tried to do something like this:
browser.waitForElementById("signin").click();
var var3 = "My Page Title";
var var4 = browser.title();
assert.equal(var3, var4, 'Assertion error on the page title: Expected: ' + var3 + ', got: ' + var4);
However, I don't always see the correct value at of the page title when I run this code, and sometimes see the old title, and sometimes the new one.
What is the best way to wait for the page to load before doing a check on something in the newly loaded page? I saw that there is a waitFor method in the API, but wasn't sure how to use it.
Thanks!
Hello,
I can't load my Selenium tests since I upgraded my wd-sync to the latest version.
Here is a sample of the code:
wdSync = require 'wd-sync'
should = require 'should'
browser = null
wrap = wdSync.wrap
with: -> browser
pre: -> @timeout 45000
website = (name, body) ->
describe name, ->
before (done) ->
{browser} = wdSync.remote "192.168.56.102", 4444
browser.findImage = (name) ->
@setWaitTimeout 3000
image = @elementByCssIfExists name
image
browser.findBanner = (id) ->
@setWaitTimeout 20000
console.log "finding banner #{id}"
banner = @elementByCssIfExists id
should.exist(banner)
banner
done()
body()
page = (name, fn) ->
it name, wrap ->
@init
browserName: "ie"
try fn.apply(@)
finally @quit()
website "Test website", ->
if true
page "Go to Google", ->
@get "http://google.com"
queryField = @elementByName 'q'
@type queryField, "Philips"
@type queryField, "\n"
@findBanner '#kelkoo-widget'
The test starts and navigates to the Google URL but then nothing happens - it's unable to locate the "q" text field.
I've tried to downgrade wd-sync to previous versions but I still can't complete any of my tests.
Could you please check this?
Thank you for your attention!
Best Regards,
Georgi
I am still seeing this issue reported in #6 that the element in elements is not properly wrapped the same way. For instance if I console.log @elementsByCssSelector('ul li')[0]
and @elementByCssSelector('ul li')
the objects are different. In the element way, the object has the prototypes showing like toJSON, doubleclick, etc, while the element in elements just has value, and browser.
For example, when I execute:
browser.elementByCssSelector(bogusSelector);
Sauce Labs correctly reports: "The element could not be found". Also wd-sync fails with:
Error: Error response status: 7.
at EventEmitter.webdriver._newError (/Users/alindsay/projects/insight-ui/node_modules/wd-sync/node_modules/wd/lib/webdriver.js:53:13)
at /Users/alindsay/projects/insight-ui/node_modules/wd-sync/node_modules/wd/lib/webdriver.js:123:25
at Request._callback (/Users/alindsay/projects/insight-ui/node_modules/wd-sync/node_modules/wd/lib/webdriver.js:330:5)
at Request.self.callback (/Users/alindsay/projects/insight-ui/node_modules/wd-sync/node_modules/wd/node_modules/request/index.js:142:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request.<anonymous> (/Users/alindsay/projects/insight-ui/node_modules/wd-sync/node_modules/wd/node_modules/request/index.js:856:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage.<anonymous> (/Users/alindsay/projects/insight-ui/node_modules/wd-sync/node_modules/wd/node_modules/request/index.js:808:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:872:14
How can I trap this? I can't figure it out.
The current version of "wd" used by wd-sync is "~0.2.7". Can you please update the version of wd to latest one so that we can use TouchActions() function ?
Hi Sebastian,
Thank you for developing this library!
I noticed that if one changed the browserName
from firefox
to chrome
the session's id webdriver.remote.sessionid
is undefined and I need the ID to report the status of the test back to Sauce Labs.
See: teameh@de18dfd
Hi,
My instance is very slow, I am using wd-sync for testing but I am facing a lot of time delay issues. When I repeat my test again without any change in code, it provides new type of error.
Errors like..
Error response status: 7
Error response status: 11
Error response status: 28
Element didn't become visible
How can I solve these type of issues, could you help me out?
I'm trying to use wd-sync with mocha v1.0.1 but it seems test failures are not triggered correctly:
// case_test.js
/* global describe, it */
/* jshint expr:true */
var assert = require('assert');
var wdSync = require('wd-sync');
var client = wdSync.remote();
var browser = client.browser;
var sync = client.sync;
describe("test case", function() {
it("should pass this test", function(done) {
this.timeout(10000); // browser start time
sync(function() {
browser.init({browserName: 'firefox'});
browser.get('http://google.com/');
assert(false);
browser.quit();
done();
});
});
});
Gives:
$ mocha test/functional/case_test.js
AssertionError: false == true
at Object.<anonymous> (/path/to/project/test/functional/case_test.js:16:7)
at _sync (/path/to/project/node_modules/wd-sync/lib/wd-sync.js:95:21)
at sync (/path/to/project/node_modules/wd-sync/node_modules/make-sync/lib/make-sync.js:133:14)
As you can see the error is caught and processed by the sync function while it should be by mocha itself.
A working workaround is to patch mocha's it()
function:
function _it(description, cb) {
return it(description, function(done) {
var context = this;
sync(function() {
try {
cb.call(context, done);
} catch (err) {
if (!done)
throw err;
browser.quit();
done.call(context, err);
}
});
});
}
describe("test case", function() {
_it("should pass this test", function(done) {
this.timeout(10000); // browser start time
browser.init({browserName: 'firefox'});
browser.get('http://google.com/');
assert(false);
browser.quit();
done();
});
});
which gives:
$ mocha test/functional/case_test.js
․
✖ 1 of 1 test failed:
1) test case should pass this test:
AssertionError: false == true
at Context.<anonymous> (/Users/niko/Sites/talkilla/test/functional/case_test.js:32:5)
at Object.<anonymous> (/Users/niko/Sites/talkilla/test/functional/case_test.js:15:12)
at _sync (/Users/niko/Sites/talkilla/node_modules/wd-sync/lib/wd-sync.js:95:21)
at sync (/Users/niko/Sites/talkilla/node_modules/wd-sync/node_modules/make-sync/lib/make-sync.js:133:14)
Though I'm finding the hook quite unpleasant and fragile.
Dear Sir,
Sometimes the script throws an error when I use ghostdriver of phantomjs
phantomjs.exe --webdriver=4444 &
C:\Users\user\workspace\node_modules\wd-sync\node_modules\fibers\futur
e.js:173
throw(ex);
^
Error: Error response status: 13.
at Webdriver._newError (C:\Users\user\workspace\node_modules\wd-sy
nc\node_modules\wd\lib\webdriver.js:80:13)
at C:\Users\user\workspace\node_modules\wd-sync\node_modules\wd\li
b\webdriver.js:119:29
at C:\Users\user\workspace\node_modules\wd-sync\node_modules\wd\li
b\webdriver.js:391:5
at Request._callback (C:\Users\user\workspace\node_modules\wd-sync
\node_modules\wd\lib\webdriver.js:281:7)
at Request.self.callback (C:\Users\user\workspace\node_modules\wd-
sync\node_modules\wd\node_modules\request\index.js:148:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request. (C:\Users\user\workspace\node_modules\wd-sy
nc\node_modules\wd\node_modules\request\index.js:876:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage. (C:\Users\user\workspace\node_modul
es\wd-sync\node_modules\wd\node_modules\request\index.js:827:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)
Thank you for your attention
Best Regards
Alternatively, element.click() works just fine but browser.clickElement(element) kills the script with no error message of any sort.
First of all, thank you for making this wonderful module. Our tests are immensely nicer thanks to your efforts.
I notice that the timeout argument of waitForElementByCss
is ignored; the browser's timeout is used instead. So this code will wait for 30 seconds, rather than 1 second, before throwing "Error: Element didn't appear":
browser.setWaitTimeout(30*1000);
browser.waitForElementByCss('#non-existent-element', 1000);
sync() is called, but any references to browser (or this) from within sync() result in a crash.
Console output:
C:\Users\Seth\node_modules\wd-sync\examples\js>node 1-wd-simple.js
(null):0
(null)
I strongly suspect the issue is with fibers on windows, and is probably a "WONTFIX", but reporting the issue anyway ;-)
Looks really cool! I wanna give it a try but from javascript land.
admc
Docs refer to these paths, but they are not part of the distribution -- what are they?
/node_modules/.bin/install_selenium
./node_modules/.bin/install_chromedriver
./node_modules/.bin/start_selenium_with_chromedriver
I did an npm install node, tried to run the sample test, and got an error about wd-zombie being undefined. Maybe wd-zombie needs to be in 'dependencies'?
wdSync.sleep
throws Fiber is undefined
error
https://github.com/sebv/node-wd-sync/blob/master/lib/wd-sync.coffee#L88
I have fixed this by using fiber.constructor.yield()
Another option is exporting Fiber from make-sync
and using it, but that's not the best way.
Hi,
I'm trying to emit an error to allow my tests to carry on without issuing an error log and canceling the current test but it's not working, could you help me out?
Here is the error log I'm getting if it's of any use:
Error: Error response status.
at EventEmitter.webdriver._newError (/Users/Shared/git/node-webdriver-tests/node_modules/wd-sync/node_modules/wd/lib/webdriver.js:47:13)
at IncomingMessage.webdriver._callbackWithDataBase (/Users/Shared/git/node-webdriver-tests/node_modules/wd-sync/node_modules/wd/lib/webdriver.js:162:25)
at IncomingMessage.EventEmitter.emit (events.js:115:20)
at IncomingMessage._emitEnd (http.js:366:10)
at HTTPParser.parserOnMessageComplete as onMessageComplete (http.js:149:23)
at Socket.socketOnData as ondata (http.js:1356:20)
at TCP.onread (net.js:404:27)
Regards,
Will.
All of "@elementsByXXX" methods just return something like this (based on the number of matches). I've no idea how to fix this 😟
[ { value: '0',
browser:
{ sessionID: '61988c81-afcb-405a-8671-4a6f68025eda',
username: undefined,
accessKey: undefined,
basePath: '/wd/hub',
https: false,
options: [Object],
defaultCapabilities: [Object] } },
{ value: '1',
browser:
{ sessionID: '61988c81-afcb-405a-8671-4a6f68025eda',
username: undefined,
accessKey: undefined,
basePath: '/wd/hub',
https: false,
options: [Object],
defaultCapabilities: [Object] } },
{ value: '2',
browser:
{ sessionID: '61988c81-afcb-405a-8671-4a6f68025eda',
username: undefined,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.