1
更新:问题解决了,检查评论无效的会话ID在使用上nightwatch黄瓜页面对象
我试图将一些经常使用的测试页面对象和我有作为pg.js以下:
var myCommands ={
security:function(username){
this.click('@logon')
.waitForElementVisible('@id',20000)
.click('@id')
.setValue('@id',username)
.click('@device')
},
password:function(username){
console.log(this)
return this.useXpath()
.navigate()
.assert.elementPresent('@logon', 20000)
.click('@logon')
.waitForElementVisible('@id',20000)
.click('@id')
.setValue('@id',username)
.click('@password')
.waitForElementVisible('//input[@name="Answer"]', 20000);
}
};
module.exports={
url : 'https://mywebsite',
commands :[myCommands],
elements:{
logon:{
locateStrategy: 'xpath',
selector:'//a[@title="Log on"]'
},
id:{
locateStrategy: 'xpath',
selector:'//input[@name="userid"]'
},
device:{
locateStrategy: 'xpath',
selector:'//a[text() = "Login with PIN"]'
},
password:{
locateStrategy: 'xpath',
selector:'//a[text() = "Login with passwords"]'
}
}
};
从执行console.log(本),我可以看到会话ID和上下文为空:
在我test.js,我有这样两条线:
var logon=client.page.pg()
....
logon.password(username)
当我运行测试,它显示
Error: Creating screenshot was not successful. Response was:
{ status: -1,
value:
{ error: 'invalid session id',
message: 'No active session with ID null',
stacktrace: '' },
errorStatus: 6,
error: '' }
我的问题是,为什么会是空?如果在pg.js或test.js中设置页面对象有任何问题。
问题解决:在测试中使用页面对象后,需要使用Pageobject.api来调用函数,并且不能执行client.whateveritis()。例如'logon.password(用户名).api.elements(blablabla)' – Raymond