what are the differences (and when to use) selenium-webdriver over webdriverjs?

前端 未结 3 426
眼角桃花
眼角桃花 2021-01-31 12:44

I\'m an experience professional that uses selenium-webdriver. I\'m exploring more options on how to test javascript applications and I found webdriverJs. Unfortunately, I dont u

3条回答
  •  情歌与酒
    2021-01-31 12:58

    They do basically the same thing. The main difference is how you write your tests. selenium-webdriver is a mix of promises and callbacks - WebdriverIO only works with promises and can be used as standalone or with an internal testrunner. There is also a library called wd.js. Here is an example of how all three flavors.

    selenium-webdriverjs:

    driver.get('http://www.google.com');
    driver.findElement(webdriver.By.id('q')).sendKeys('webdriver');
    driver.findElement(webdriver.By.id('btnG')).click();
    

    WD.js

    browser
       .get("http://www.google.com")
       .elementById('q')
       .sendKeys('webdriver')
       .elementById('btnG')
       .click()
    

    WebdriverIO:

    browser
        .url('http://google.com')
        .setValue('#q','webdriver')
        .click('#btnG')
    

    WebdriverIOs concept is to wrap all protocol commands in handy action commands but it has also almost all protocol commands implemented, so you can do the same with the standard JSONWire protocol commands.

    browser
        .url('http://google.com')
        .element('#q').then(function(res) {
            return browser.elementIdValue(res.value.ELEMENT, 'webdriver');
        })
        .element('#btnG').then(function(res) {
            return browser.elementIdClick(res.value.ELEMENT);
        });
    

提交回复
热议问题