【问题标题】:Error Timeout on protractor test量角器测试错误超时
【发布时间】:2017-10-03 18:14:51
【问题描述】:

我正在使用量角器和茉莉花进行自动化测试。 我正在注册页面上进行测试,代码如下:

               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 指定的超时内未调用异步回调

我真的不明白为什么。

【问题讨论】:

  • 增加 config.js 文件中的 'defaultTimeoutInterval:60000'

标签: angularjs jasmine protractor automated-tests


【解决方案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');
});

【讨论】:

  • 好的,这对我有帮助,但不能解决我的问题。有没有可能连续两个预期不能做?
  • 我没试过。你为什么不尝试一次。代码将基本保持不变
【解决方案2】:

你试过了吗:
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
        });
    });
});

【讨论】:

    【解决方案3】:

    您可以使用 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();
     });    
    });    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      • 2015-10-04
      • 1970-01-01
      • 1970-01-01
      • 2016-09-09
      • 1970-01-01
      • 2018-05-30
      相关资源
      最近更新 更多