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