2013-04-27 61 views
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') 

    } 
} 

回答

0

我得到了解決,我們必須這樣做如下:

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') 
    } 
    }) 
    ...