webdriverjs vs selenium-wedriverjs (question)
dmitrym0 opened this issue · comments
Hello everyone,
I apologize in advance if I'm asking stupid questions.
First, this project is in fact different from selenium-wedriver-js is that correct? The name threw me off for a little while :(
Secondly, how does webdriverio compare to selenium-webdriverjs? selenium-webdriverjs looks very java-y to me, on the other hand I can't quite fiigure out how webdriverio (yours) does async stuff.
I basically need help choosing one or the other. Thanks!
hi @dmitrym0
that is not a stupid question in fact often asked! I answer that a lot. Basically both have the same purpose. There is also a library called WD.js which is also a selenium runner for node. They all do quiet the same but have a different level of development and a different syntax.
I've never used one of the other libraries before so I can just tell you about this one. We're trying to provide a selenium runner which is easy to use, highly extendable and compatible with all common JavaScript test frameworks. It uses an own chain API to execute all async commands in right order. The specialty of this library is that we wrap all JSONWire protocol commands in useful actions commands. So you don't have to care about to get an element first and then call the click command; you just execute the click with a selector as parameter. Here is a simplified example:
driver.get('http://www.google.com');
driver.findElement(webdriver.By.id('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.id('btnG')).click();
browser
.get("http://www.google.com")
.elementById('q')
.sendKeys('webdriver')
.elementById('btnG')
.click()
Now in this library:
client
.url('http://google.com')
.setValue('#q','webdriver')
.click('#btnG')
WebdriverIO has also almost all protocol commands implemented, so you can do the same with the standard JSONWire protocol commands.
client
.url('http://google.com')
.element('#q', function(err,res) {
client.elementIdValue(res.value.ELEMENT, 'webdriver');
})
.element('#btnG', function(err,res) {
client.elementIdClick(res.value.ELEMENT);
});
Each one has its own flavor, you need to decide which one fits most to you. I hope this clarifies it a bit. I'ld like to help you if you have any problems setting up your tests. But I thing it should be pretty easy and straight forward. You can find a list of example tests here.
cheers
Very nice answert @christian-bromann I think this should be linked in the readme.md now.
@christian-bromann, thank you very much for explaining this to me. It helps very much.
If I can ask for some more of your time. I've written a script in selenium-webdriverjs that illustrates my current use case nicely.
It:
- opens up a wikipedia page
- finds all of the text paragraphs on the page
- clicks on the first and the 5th paragraph to select them
I would like to reproduce this in webdriverio, however I can't seem to figure out how to select text. Can you help me with that? Thanks!
Text of my current selenium-webdriverjs is below:
var assert = require('assert'),
test = require('selenium-webdriver/testing'),
webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
usingServer("http://localhost:9515").
withCapabilities(webdriver.Capabilities.chrome()).
build();
test.describe('selection', function() {
test.it('should be able to select two paragraphs', function() {
console.log("Request URL");
driver.get("http://en.wikipedia.org/wiki/Computer_programming");
var startParagraph, endParagraph;
driver.sleep(500).then(function() {
console.log("Getting all paragraphs");
var allPs = driver.findElements({tagName: 'p'}).then();
allPs.then(function(allParagraphs){
console.log("Got paragraphs.");
allParagraphs[1].then(function(startParagraphvalue){
startParagraph = startParagraphvalue
console.log("Resolved paragraph 1")
});
allParagraphs[5].then(function(endParagraphvalue){
endParagraph = endParagraphvalue
console.log("Resolved paragrpah 2" + endParagraphvalue);
});
});
}).then(function() {
console.log("Trying to select stuff now");
new webdriver.ActionSequence(driver).
keyDown(webdriver.Key.SHIFT).
click(startParagraph).
click(endParagraph).
keyUp(webdriver.Key.SHIFT).
perform().then(function(){
console.log("Done selection?");
});
});
});
});
With WebdriverIO it is a bit shorter ;-)
var assert = require('assert'),
client = require('webdriverjs').remote({desiredCapabilities:{browserName:'chrome'}});
client
.init()
.url('http://en.wikipedia.org/wiki/Computer_programming')
.elements('tag name','p',function(err,res) {
client
// move to first paragraph to the upper left corner (0,0)
.moveTo(res.value[0].ELEMENT, 0, 0)
// press shift key
.keys('Shift')
// do left click
.buttonPress('left')
// move to 5th paragraph to the lower right corner (1,1)
.moveTo(res.value[5].ELEMENT,1,1)
// do left click
.buttonPress('left')
// pause for 5000ms to be able to see selected text
.pause(5000);
})
.end();
First we query all elements with tag name p
. The res.value
object contains an array of elements. Then we just select a text using the shift key. I admit that this is not straightforward for new user because the protocol commands aren't really documented. webdriver.io is gonna to go live soon and will cover that.
I'm really starting to lean towards webdriver.io!!!!
@dmitrym0 do you have any further questions?
@wayneseymour great! sounds good
seems to be that there are no further questions. closing.
Thanks for all your help @christian-bromann !
curious you and adam wd.js both work at sauce. Plan to keep 2 webdriver node libs going?
I don't know where WD.js is going, I started working on webdriver.io long before I joined sauce and all my work I put in here has nothing in common with the stuff I do at sauce. I am doing this all in my free time and enjoy it to contribute to the open source world ;-)
thanks for the response and the project looks great!
@christian-bromann I know this is rather old and may have been resolved already but your example of using a pause is a really bad practice in the selenium world and leads to inconclusive results, i.e how do you know it takes 5 seconds and can you guarantee that it will always be 5 seconds?
.pause(5000);
A better approach is to retry with a timeout period, i.e we don't know how long it takes but we will keep retrying for 30 seconds and if we still don't have it then there is obviously an issue.
Is there something in place for this type of approach using webdriver IO?
Yeah, WebdriverIO has a bunch of waitFor* commands. Check out the API
Hi Christian , I really need your help. I am very much confused in selecting automation testing stack.
Options 1) Webdriver.IO , Selenium standalone and Cucumber.io (A JavaScript Approached) AND
Option 2) WebdriverJS, Selenium JAR and Cucumber JAR (A Java Approached) .
We as a team really had spent a good amount of time and experienced - WebdriverIO is not mature enough as compare to Selenium , Cucumber and Webdriver (java approach) .
I saw your lot of help and comments in the internet and would really appreciate your comments here too.
Hi Guys,
I have gone through this thread, but I'm still confused which framework to go for.
I will be testing a mobile application on Android and iOS both, also will be on real devices/simulators.
It will be having need of functions to scroll vertically/horizontally and all.
Please suggest!
Thanks
but I'm still confused which framework to go for.
What am I suppose to say here? I can just recommend to use WebdriverIO. It supports it all.
Okay. Thank you @christian-bromann :)
Do you have any sample code for TouchAction functions?