gpt4 book ai didi

javascript - 断言selenium webdriver Node js

转载 作者:太空宇宙 更新时间:2023-11-03 23:40:46 25 4
gpt4 key购买 nike

我正在尝试通过node js运行断言以使用selenium webdriver进行测试,但它显示未定义,我获取页面标题,即页面的URL,然后断言它,看起来我必须导入某些东西来进行断言,请帮忙,还请告诉我selenium是否可以与node 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");
}
//

最佳答案

我正在寻找同样的问题,我发现这个片段对我有用

driver.findElement(By.id('elementId'))
.getText().then(textValue => {
assert.equal('tested string', textValue);
});

我在selenium-webdriver的github repo的示例文件中找到了它

关于javascript - 断言selenium webdriver Node js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24210403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com