我正在使用量角器和茉莉花进行自动化测试。 我正在注册页面上进行测试,代码如下:
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('Forfirmtestuser+user217@gmail.com'); //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 :(得分: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');
});
答案 1 :(得分: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
});
});
});
答案 2 :(得分:0)
您可以使用 Jasmine 回调来断言异步行为。 Jasmine 测试提供了额外的参数作为回调参数。完成断言后,您可以调用回调 API。
示例:
it('should have a button element present', function(done) {
browser.get('http://juliemr.github.io/protractor-demo/');
var gobtn = element(by.id('gobutton'));
gobtn.isPresent().then( (result) => {
expect(result).toBe(true);
done();
});
});