《NODE.JS selenium-webdriver 远程测试》要点:
本文介绍了NODE.JS selenium-webdriver 远程测试,希望对您有用。如果有疑问,可以联系我们。
相关主题:node.js web开发
NODE.JS selenium-webdriver 远程测试从一台测试机遥控另台selenium-server-standalone
var webdriver = require('/usr/local/lib/node_modules/selenium-webdriver'); var builder = new webdriver.Builder(). usingServer('http://192.168.6.20:4444/wd/hub'). withCapabilities(webdriver.Capabilities.firefox()); var driver = builder.build(); driver.get('http://www.google.com'); driver.findElement(webdriver.By.name('q')).sendKeys('webdriver'); driver.findElement(webdriver.By.name('btnK')).click(); driver.wait(function() { return driver.getTitle().then(function(title) { return title === 'webdriver - Google Search'; }); }, 1000); driver.quit();
安装 mocha
npm install -g mocha
测试脚本
var assert = require('assert'), test = require('selenium-webdriver/testing'), webdriver = require('selenium-webdriver'); test.describe('Google Search', function() { test.it('should work', function() { //var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build(); var driver = new webdriver.Builder().usingServer('http://192.168.6.20:4444/wd/hub').withCapabilities(webdriver.Capabilities.firefox()).build(); driver.get('http://www.google.com'); var searchBox = driver.findElement(webdriver.By.name('q')); searchBox.sendKeys('simple programmer'); searchBox.getAttribute('value').then(function(value) { assert.equal(value, 'simple programmer'); }); driver.quit(); }); });
运行测试程序
# mocha mocha.js 1 passing (10s)
测试成功返回1 passing (10s)