量角器Click功能不起作用,它会抛出超时异常错误

时间:2017-05-07 04:38:43

标签: protractor

节点版本:v6.9.4

量角器版本:5.1.1

Angular Version:1.2.28

浏览器:Chrome:Version 58.0.3029.96 (64-bit) Chrome WebDriver:Version 2.29

操作系统和版本:MAC OS Siera 10.12.3

量角器配置文件

exports.config = {
  directConnect: true,
  capabilities: {
    'browserName': 'chrome'
  },
  framework: 'jasmine',
  specs: ['./Test/LoginTest.js'],
  allScriptsTimeout: 120000,
  getPageTimeout: 120000,
  jasmineNodeOpts: {
  showColors: true,
  defaultTimeoutInterval: 120000
}

相关的示例测试

页面中有按钮,当我尝试使用量角器点击时,它会抛出超时错误。无法单击该元素。同样的事情在selenium webdriver上工作。

重现步骤 第1步:使用此网址https://www.neonmob.com/login

打开网站

第2步: Enter the user name and password mentioned below and click on Login button          用户名:sharif33332          密码:1234

第3步:登录后,导航至此网址https://www.neonmob.com/shariftestuser,以导航至出现问题的确切页面。

问题Now at this page unable to click on Trade Button and it throws time out exception error.

使用jQuery可以找到相同的元素。请按照上述步骤重现此问题。

使用以下代码点击此按钮

element(by.css("span[id='trade-btn']")).click();

如果您无法按照步骤操作,请与我们联系。我相信protratcor有一个问题

2 个答案:

答案 0 :(得分:1)

我发现了问题。量角器没有问题。页面有问题。单击按钮/没有找到它时,您没有超时。您收到错误,因为页面超时是因为Angular没有释放页面。仍然有公开的电话或者是什么让Angular没有准备好。这是我得到的日志

Failures:
1) click on trade button should click on the trade button
  Message:
    Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
  Stack:
    Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
        at ontimeout (timers.js:365:14)
        at tryOnTimeout (timers.js:237:5)
        at Timer.listOnTimeout (timers.js:207:5)
  Message:
    Failed: Timed out waiting for asynchronous Angular tasks to finish after 30 seconds. This may be because the current page is not an Angular application. Please see the FAQ for more details: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular
    While waiting for element with locator - Locator: By(css selector, #trade-btn).
    The following tasks were pending:
     - $timeout: function (){ownershipPromise=artPieceService.syncOwnership()}

如果您使用此功能禁用等待角度,则可以使用

describe('click on trade button', () => {
    beforeEach(function () {
        browser.get(browser.baseUrl);
        $('#field-username').sendKeys('sharif33332');
        $('#field-password').sendKeys('1234');
        $('#signin-btn').click();
        browser.driver.wait(() => browser.getCurrentUrl().then((currentUrl) => currentUrl === 'https://www.neonmob.com/sharif33332'));
        browser.get('https://www.neonmob.com/shariftestuser')
    });

    it('should click on the trade button', () => {
        // Disable wait for Angular
        browser.ignoreSynchronization = true;
        // Wait 2 seconds for the page to be loaded
        browser.sleep(2000)
        $('#trade-btn').click();
        // Wait to verify that the trade button has been clicked.
        browser.sleep(5000);
    })
});

这将证实量角器没有任何问题,但您需要在此页面上深入了解Angular /请开发人员解决此问题。

答案 1 :(得分:-1)

检查后,您的第二个URL(似乎不是)是一个角度页面,需要ignoreSynchronization。

尝试使用以下代码:

describe('angularjs homepage todo list', function() {
  it('should add a todo', function() {
    browser.get('https://www.neonmob.com/login');
    element(by.id('field-username')).sendKeys('sharif33332');
    element(by.id('field-password')).sendKeys('1234');
    element(by.id('signin-btn')).click();
    browser.waitForAngular();
    browser.ignoreSynchronization=true
    browser.executeScript('this.document.location = "https://www.neonmob.com/shariftestuser"');
    element(by.id('trade-btn')).click();
  });
});

我没有修复格式,你可以做那个。 :)

配置上没什么特别之处,我只使用它:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js'],
  jasmineNodeOpts: {defaultTimeoutInterval: 60000}
};