量角器简单测试可在50%的时间内工作

时间:2017-09-20 11:57:39

标签: angular typescript protractor

我尝试设置一些简单的 protractor 测试,尝试使用Angular2进行E2E测试。我使用以下版本:( v4.4.3 NG2 / v5.1.2量角器)。

我还使用最新的@angular/cli版本和premade protractor.conf.js 文件。

以下是我使用现有应用程序设置的简单测试。

import { browser, by, element } from 'protractor';

describe('Protractor testing suite with TypeScript', () => {
  beforeAll(() => {
    browser.get('/');  

    // Add logging.
    browser.manage().logs().get('browser').then(function (browserLog) {
      console.log('log: ' + require('util').inspect(browserLog));
    });
  });

  describe('Protractor first test suite', function () {
    it('should navigate to the map', function () {
      const navigationMapButton = element(by.id('general.menu.esri_maps'));
      navigationMapButton.click();

      // Testing the navigation to another page here (The page is lazy-loaded, that might be linked)
      browser.wait(() => {
        return browser.getCurrentUrl().then((url) => {
          console.log(url);
          return url.includes('esrimaps');
        })
      })
        .then((resolved) => {
          expect(resolved).toBeTruthy();
        });
    });
  });
})

主要问题是50%的时间,测试失败,而另一次,它的工作原理。以下是日志:

成功的测试日志:

[13:48:14] I/launcher - Running 1 instances of WebDriver
[13:48:14] I/direct - Using ChromeDriver directly...
Spec started
log: []
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/maps/esrimaps

  Protractor testing suite with TypeScript

    Protractor first test suite
      √ should navigate to the map

Executed 1 of 1 spec SUCCESS in 6 secs.
[13:48:23] I/launcher - 0 instance(s) of WebDriver still running
[13:48:23] I/launcher - chrome #01 passed

失败测试日志:

[13:49:37] I/launcher - Running 1 instances of WebDriver
[13:49:37] I/direct - Using ChromeDriver directly...
Spec started
log: []
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard
http://localhost:4200/pages/dashboard

  Protractor testing suite with TypeScript

    Protractor first test suite
      × should navigate to the map

   ...

**************************************************
*                    Failures                    *
**************************************************

1) Protractor testing suite with TypeScript Protractor first test suite should navigate to the map
  - Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds. This may be because the current page is not an Angular application. Please see t
he FAQ for more details: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular

Executed 1 of 1 spec (1 FAILED) in 17 secs.
[13:49:57] I/launcher - 0 instance(s) of WebDriver still running
[13:49:57] I/launcher - chrome #01 failed 1 test(s)
[13:49:57] I/launcher - overall: 1 failed spec(s)
[13:49:57] E/launcher - Process exited with error code 1

附加信息:

  • 当失败时,显然它是因为它在尝试导航时超时,但在Web驱动程序实例上,它每次都在click()上成功导航。很明显,它以某种方式失去对正在发生的事情的追踪,但我无法指出是什么导致这种情况发生......
  • 加载时间之间有一个加载器,所以它可能已经链接了吗? (我使用根据我的需求定制的NG2管理模板:https://github.com/akveo/ngx-admin
  • 正如我之前所说,信息中心地图是延迟加载的,所以它可能已被链接了吗?
  • 我已经看到了这个链接:https://github.com/angular/protractor/blob/master/docs/timeouts.md关于超时,但我不知道我应该实现哪个用例...我真的需要在任何地方更改我的代码才能使用{{ 1}}用于异步任务?因为这个问题而改变一切似乎真的很烦人......

1 个答案:

答案 0 :(得分:0)

好吧,实际上我用最糟糕的例子来尝试我的测试。我可能是因为懒惰的装载或类似的其他机制,但根本没有: 我的地图是使用 ArcGIS JS API Esri 地图,由于ArcGIS JS API通过Dojo提供,因此该地图通过angular-esri-loader库提供。

因此,它不完全是一个角度上下文,我不得不使用browser.waitForAngularEnabled(false);来使它工作。