2017-05-05 149 views
0

我正在使用量角器和茉莉花進行自動化測試。 我做了一個測試註冊頁面上,用下面的代碼:量角器測試錯誤超時

   it('Verify Alert message when New user registered itself for the first time',function() { 
    FuncLib.ButtonClick('Close'); //Close the error message displayed in previous scenario 
    Registration.Email.clear(); //Clear valid E-mail Id 
    Registration.Password.clear(); //Clear Password 
    Registration.ConfirmPassword.clear(); //Clear Confirm Password 
    Registration.Firstname.clear(); //clear Firstname Password 
    Registration.Lastname.clear(); //clear Lastname Password 
    Registration.Phonenumber.clear(); //clear phonenumber 
    browser.sleep(500); 
    Registration.Email.sendKeys('[email protected]'); //Enter valid E-mail Id 
    Registration.Password.sendKeys('Hello1'); //Enter Password 
    Registration.ConfirmPassword.sendKeys('Hello1'); //Enter wrong Confirm Password 
    Registration.Firstname.sendKeys('candy'); //Enter Firstname Password 
    Registration.Lastname.sendKeys('smith'); //Enter Lastname Password 
    Registration.Phonenumber.sendKeys('9191919106'); //Enter phone number. 
    expect(Registration.Checkbox.isPresent()).toBe(true); // Terms and condition checkbox should display 
    Registration.Checkbox.click(); // select the Terms and condition checkbox 
    Registration.Checkbox.click(); // select the Terms and condition checkbox 
    browser.sleep(200); 
     expect(Registration.RegisterButton.isPresent()).toBe(true); 
     Registration.RegisterButton.click(); //click Register button 
     browser.sleep(200); 
      browser.driver.wait(function() { // Wait for the current URL to change to Home page 
       return browser.driver.getCurrentUrl().then(function(url) { 
        return (/home/).test(url); 
       }); 
      }); 


      expect(browser.getCurrentUrl()).toEqual(Registration.HomeURL); 
      console.log('When New user registered itself for the first time:'); 
       expect(Registration.AlertMsg.getText()).toEqual(Registration.msg6); 
       Registration.AlertMsg.getText().then(function(text) { 
       console.log(' When New user registered itself for the first time:'); //Jasmine expect statement : compare actual and expected value 
       }); 
});    

一切工作正常,直到這部分代碼:

    expect(Registration.RegisterButton.isPresent()).toBe(true); 
    Registration.RegisterButton.click(); //click Register button 
    browser.sleep(200); 
     browser.driver.wait(function() { // Wait for the current URL to change to Home page 
      return browser.driver.getCurrentUrl().then(function(url) { 
       return (/home/).test(url); 
      }); 
     }); 


     expect(browser.getCurrentUrl()).toEqual(Registration.HomeURL); 
     console.log('When New user registered itself for the first time:'); 
      expect(Registration.AlertMsg.getText()).toEqual(Registration.msg6); 
      Registration.AlertMsg.getText().then(function(text) { 
      console.log(' When New user registered itself for the first time:'); //Jasmine expect statement : compare actual and expected value 
      }); 

在這裏我得到的報告這個錯誤結束: 錯誤:超時 - 異步回調不被jasmine.DEFAULT_TIMEOUT_INTERVAL

指定的超時時間內調用,我真的不明白爲什麼。

+0

在你的config.js文件中增加'defaultTimeoutInterval:60000' –

回答

1

首先browser.sleep(200);是不好的事情使用。它總是很好的等待一個元素加載。在量角器中,這可以使用then函數完成。檢查樣品波紋管,這會給你和理念

element(by.xpath("xpath_locator")).click().then(function(){ 
    var list = element(by.id('id_locator')); 
    var until = protractor.ExpectedConditions; 
    browser.wait(until.presenceOf(list), 80000, 'Element taking too long to appear in the DOM'); 
}); 
+0

好吧,這會幫助我,但不能解決我的問題。有可能無法連續兩次預期? – mpeg90

+0

我還沒有嘗試過。你爲什麼不嘗試一次。該代碼將保持大部分相同 – Acid

0

你試過:
1.在配置文件中增加默認超時?
2.增加睡眠秒數?
3.插入睡眠內的期望?

expect(Registration.RegisterButton.isPresent()).toBe(true); 
Registration.RegisterButton.click(); //click Register button 
browser.sleep(2000).then(function() { // Wait for the current URL to change to Home page 
    browser.getCurrentUrl().then(function(url) { 
     expect(url).toEqual(Registration.HomeURL); 
     console.log('When New user registered itself for the first time:'); 
     expect(Registration.AlertMsg.getText()).toEqual(Registration.msg6); 
     Registration.AlertMsg.getText().then(function(text) { 
      console.log(' When New user registered itself for the first time:'); //Jasmine expect statement : compare actual and expected value 
     }); 
    }); 
}); 
相關問題