我正在尝试通过节点js运行selenium webdriver进行测试的断言,但是它说未定义,我得到页面标题,这是页面的URL然后断言它,看起来我必须导入某个断言,请帮忙,还请告诉我,如果selenium与节点js工作正常,这里是我的代码:
var webdriver = require('selenium-webdriver'),
//var test = require('selenium-webdriver/testing'),
nodeThen = require('node-then');
var assert = require('assert');
//var jsdom = require("jsdom");
//var document = require('jquery');
var xpath = require('xpath');
//var driver = new webdriver.Builder().
// withCapabilities(webdriver.Capabilities.chrome()).
//build();
function createDriver() {
var driver = new webdriver.Builder()
.usingServer('link')
.withCapabilities(webdriver.Capabilities.chrome())
.build();
driver.manage().timeouts().setScriptTimeout(10000);
return driver;
}
var driver = createDriver();
var By = webdriver.By;
driver.get("URL")
.then(function(){
driver.sleep(10000);
var element=driver.findElement(By.id("get-started"));
element.click();
})
.then(function(){`enter code here`
return driver.getTitle();
})
.then(function(title) {
//console.log(title);
//driver.manage().timeouts().setScriptTimeout(50000);
if (title == ('URL')) {
console.log("pass");
}
//
答案 0 :(得分:1)
我正在寻找同样的问题,我发现这个片段对我有用
driver.findElement(By.id('elementId'))
.getText().then(textValue => {
assert.equal('tested string', textValue);
});
我在selenium-webdriver' s github repo
的示例文件中找到了它答案 1 :(得分:0)
你安装了断言吗?命令为npm install asserts
。此外,您需要var Asserts = require('asserts');
答案 2 :(得分:0)
这是您正在寻找的示例
// Require chai.js expect module for assertions
const chai = require('chai');
const expect = require('chai').expect;
// Application Server
const serverUri = '0.0.0.0:3000';
// Official selenium webdriver testing setup
const webdriver = require('selenium-webdriver');
describe('basic test', function () {
let driver;
before(() => {
// Start of test use this
driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
console.log("Selenium Webdriver Chrome Started");
});
after(function(){
// End of test use this.
driver.quit();
});
it('should be on correct page', function (done) {
this.timeout(10000);
driver.get(serverUri);
driver.getTitle().then(function(title) {
expect(title).to.equal('Some String Here');
done();
console.log("Selenium Webdriver Chrome Shutdown");
})
});
});