如何在nodejs苏打中生成动态断言



我有下面的代码在nodejs硒使用苏打脚本。

如果你看到下面的脚本,寻找verifyData()有固定列值的行测试。我想动态地生成这些断言,只有行数会变化,列将始终相同,如何实现这一点。我可以把行号传递给这个方法。

第二件事,如果你看到assert我使用了function(),我们可以在这里捕获err/assertfail吗?

var browser = soda.createClient({
.....
});
browser 
    .chain
    .session()  
    .setSpeed(speed)
    .setTimeout(2000)
    .open('/')
    .and(login('dev@dev.com', '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')
  }
}

我得到了解决方案,我们必须这样做:

browser
  .chain
  .setSpeed(200)
  .session()
  .open('/')
  .click("id=save")
  .focus(editor)
  .and(function (browser) {
    for (var i = 0; i < 10; i++) {
      browser.keyDown(editor, '\40')
    }
  })
  ...

最新更新