【问题标题】:Protractor Click function does not work, It throws Time out exception error量角器单击功能不起作用,它会抛出超时异常错误
【发布时间】:2017-05-07 04:38:43
【问题描述】:

节点版本:v6.9.4

量角器版本:5.1.1

Angular 版本: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 步: 使用此 URL https://www.neonmob.com/login 打开网站

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

第 3 步: 登录后导航到此 URL 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();

如果您无法按照这些步骤操作,请告诉我。我认为量角器存在问题

【问题讨论】:

  • 看不到交易按钮 XD - 我刚刚看到了

标签: protractor


【解决方案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/请开发人员解决此问题。

【讨论】:

  • 如果是angular页面,有一个函数会等待页面加载完毕再检查对象。您也可以使用 browser.sleep 但秒数是固定的。您还可以尝试使用可以充当“waitForAngular”函数的递归函数。 stackoverflow.com/questions/43656135/…
  • 还将超时设置为 120 秒,但没有帮助。这意味着睡眠也将不起作用。我认为保持打开 http 调用的页面间隔有问题
【解决方案2】:

@wswebcreation ,你确定这不是 Angular 页面吗?如果不是,那么角度等待将不起作用。将需要 browser.ignoreSynchronization=true 。

无论如何,我会要求我们的开发人员对此进行研究并对其进行更多调试,以便从应用程序方面进行修复。

无论如何,上面提供的当前解决方案都可以正常工作。

非常感谢您的帮助

【讨论】:

  • 嗨,我确定。检查页面的源代码。如果您打开页面,请检查源代码,您将在第 567 行看到对 Angular 的第一个引用,然后在第 586 行加载 angular 文件和在正文标记 <body class=" nm-signed-in" id="neonmob-app" ng-app="nmApp"> 中看到 ng-app 引用。无法提供更多证据。你现在接受了一个错误解释的正确答案。我希望你明白他和我的回答只是一种解决方法(使用browser.ignoreSynchronization=true ),并且会阻碍你以正确的方式自动化页面/应用程序。
【解决方案3】:

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

尝试使用下面的代码:

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}
};

【讨论】:

  • 您是否使用提供的信息进行了尝试?然后你会看到它由于等待角度超时而无法工作
  • 一个问题,你为什么不登录 'shariftestuser' 而不是 'sharif33332'?你在这里测试一个特定的功能吗?
  • 页面“neonmob.com/shariftestuser”是一个角度页面。只需打开您的控制台并输入angular,您将获得角度对象。通过 Chrome 中的 devtools 查看 DOM 时,您还可以在代码中找到 Angular 调试信息。
  • 不管怎样,试试上面的代码,我测试了它,并且在我的桌面上工作。不知道你为什么投了反对票
  • 上面提供的解决方案是 (browser.waitForAngular(); browser.ignoreSynchronization=true) 工作。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-07
  • 2012-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-03
相关资源
最近更新 更多