0
我在使用苏打水脚本的selenium的nodejs中有以下代码。如何在nodejs苏打水中生成动态断言
如果您在下面看到我的脚本,请查找verifyData() 存在对固定列值进行行测试的情况。我想动态地生成这些断言,只有行号会不同,列总是一样的,如何实现这一点。我可以将行号传递给这个方法。第二件事,如果你看到assert中使用了function(),我们可以在这里捕获err/assertfail吗?
var browser = soda.createClient({
.....
});
browser
.chain
.session()
.setSpeed(speed)
.setTimeout(2000)
.open('/')
.and(login('[email protected]', 'x1212GQsdtpS'))
.and(verifyData())
.end(function(err){
console.log('error');
});
function login(user, pass) {
return function(browser) {
browser
.click('css=a#loginButton')
.type('css=input.input-medium.email',user)
.type('css=input.input.pwd',pass)
.clickAndWait('css=a.btn.login')
.assertTextPresent('Clients',function(){ console.log('logged in ok')})
}
}
function verifyData() {
return function(browser) {
browser
//Row 1 testing
.assertText('css=div.keyYears table tbody tr:nth-child(1) td:nth-child(3)','some text',function(){ console.log('looks good')})
.assertText('css=div.keyYears table tbody tr:nth-child(1) td:nth-child(5)','some text')
.assertText('css=div.keyYears table tbody tr:nth-child(1) td:nth-child(6)','some text')
.assertText('css=div.keyYears table tbody tr:nth-child(1) td:nth-child(7)','some text')
//Row 2 testing
.assertText('css=div.keyYears table tbody tr:nth-child(2) td:nth-child(3)','some text1',function(){ console.log('looks good')})
.assertText('css=div.keyYears table tbody tr:nth-child(2) td:nth-child(5)','some text1')
.assertText('css=div.keyYears table tbody tr:nth-child(2) td:nth-child(6)','some text1')
.assertText('css=div.keyYears table tbody tr:nth-child(2) td:nth-child(7)','some text1')
}
}