Protractor 量角器点击功能不工作,它抛出超时异常错误

Protractor 量角器点击功能不工作,它抛出超时异常错误,protractor,Protractor,节点版本:v6.9.4 量角器版本:5.1.1 角度版本:1.2.28 浏览器:Chrome:version58.0.3029.96(64位)chromewebdriver:version2.29 操作系统和版本:MAC OS Siera 10.12.3 量角器配置文件 exports.config = { directConnect: true, capabilities: { 'browserName': 'chrome' }, framework: 'jasmine

节点版本:
v6.9.4

量角器版本:
5.1.1

角度版本:
1.2.28

浏览器:
Chrome:version58.0.3029.96(64位)chromewebdriver:version2.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
}
相关示例测试

页面中有一个按钮,当我尝试使用量角器单击时,它抛出超时错误。无法单击该元素。在SeleniumWebDriver上也可以做同样的事情

复制步骤 步骤1:使用此URL打开网站
https://www.neonmob.com/login

步骤2:
输入下面提到的用户名和密码,然后单击登录按钮
用户名:
sharif3332
密码:
1234

步骤3:登录后导航到此URL
https://www.neonmob.com/shariftestuser
导航到发生问题的确切页面

问题
现在在这个页面无法点击交易按钮,它抛出超时异常错误。

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

使用以下代码单击此按钮

元素(按.css(“span[id='trade-btn']”)。单击()


如果您不能按照步骤操作,请告诉我。我相信protratcor中有一个问题。检查后,您的第二个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}
};

检查后,您的第二个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}
};

我发现了问题。量角器没有问题。这页有问题。单击按钮/未找到按钮时,不会出现超时。由于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没有释放页面,页面超时,因此出现错误。仍然有未完的电话或其他任何事情,使我们没有准备好。这是我得到的日志

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

这将确认量角器没有问题,但您需要在此页面上深入角度/请开发人员修复此问题。

@wswebcreation,您确定这不是角度页面吗。如果不是,那么角度等待将不起作用。将需要访问浏览器。ignoreSynchronization=true

无论如何,我将要求我们的开发人员关注这一点,并从应用程序方面对其进行更多的调试

无论如何,目前的解决方案提供上述工作良好


非常感谢您的帮助

@wswebcreation,您确定这不是角度页面吗。如果不是,那么角度等待将不起作用。将需要访问浏览器。ignoreSynchronization=true

无论如何,我将要求我们的开发人员关注这一点,并从应用程序方面对其进行更多的调试

无论如何,目前的解决方案提供上述工作良好


非常感谢您的帮助

看不到交易按钮XD-我刚刚看到它看不到交易按钮XD-我刚刚看到它如果它是一个有角度的页面,则有一个函数在检查对象之前等待页面加载。您也可以使用browser.sleep,但秒数是固定的。您还可以尝试使用可以充当“waitForAngular”函数的递归函数。同时将超时设置为120秒,这没有帮助。这意味着睡眠也不会起作用。我认为保持打开http调用的页面上的间隔有问题。如果是角度页面,则有一个函数在检查对象之前等待页面加载。您也可以使用browser.sleep,但秒数是固定的。您还可以尝试使用可以充当“waitForAngular”函数的递归函数。同时将超时设置为120秒,这没有帮助。这意味着睡眠也不会起作用。我认为保持打开http调用的页面上的间隔有问题。您使用提供的信息进行了尝试吗?然后您将看到,由于等待angularOne的超时,它将无法工作。您为什么不登录“shariftestuser”而不是“Sharif3332”?您正在测试一个特定的函数吗?页面“”是一个有角度的页面。只需打开控制台并键入
angular
,即可获得角度对象。当您通过Chrome中的devtools查看DOM时,也可以在代码中找到角度调试信息。无论如何,只要尝试上面的代码,我已经测试了它,并且正在我的桌面上工作。不确定您投票否决的原因上述提供的解决方案(browser.waitForAngular();browser.ignoreSynchronization=true)正在运行。感谢您的帮助。您是否使用提供的信息尝试过它?然后您将看到,由于等待angularOne的超时,它将无法工作。您为什么不登录“shariftestuser”而不是“Sharif3332”?您正在测试一个特定的函数吗?页面“”是一个角度