最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I use selenium-webdriver package with SauceLabs? - Stack Overflow

programmeradmin1浏览0评论

SauceLabs gives examples of how to write remote tests using the WD node package. I prefer the selenium-webdriver package. Is there some way to use that remotely instead?

SauceLabs gives examples of how to write remote tests using the WD node package. I prefer the selenium-webdriver package. Is there some way to use that remotely instead?

Share Improve this question edited Jul 31, 2014 at 7:54 Artjom B. 62k26 gold badges135 silver badges230 bronze badges asked Jan 16, 2014 at 19:10 AnonymousAnonymous 3,4143 gold badges38 silver badges52 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 18

Taking the sample code from the selenium-webdriver docs, we can modify it as follows to talk to Sauce Labs's selenium cloud. It assumes you've got credentials in ENV vars, of course you could hardcode them if you want to be less secure.

var webdriver = require('selenium-webdriver');

var sauce = 'http://ondemand.saucelabs.:80/wd/hub';
var driver = new webdriver.Builder().
    usingServer(sauce).
    withCapabilities({
        browserName: 'Chrome',
        platform: 'Windows 2012',
        name: 'Sample selenium-webdriver test',
        username: process.env.SAUCE_USERNAME,
        accessKey: process.env.SAUCE_ACCESS_KEY
    }).
    build();

driver.get('http://www.google.');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
    return driver.getTitle().then(function(title) {
        return title === 'webdriver - Google Search';
    });
}, 1000);

driver.quit();
发布评论

评论列表(0)

  1. 暂无评论