我尝试设置一些简单的 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
附加信息:
click()
上成功导航。很明显,它以某种方式失去对正在发生的事情的追踪,但我无法指出是什么导致这种情况发生...... 答案 0 :(得分:0)
好吧,实际上我用最糟糕的例子来尝试我的测试。我可能是因为懒惰的装载或类似的其他机制,但根本没有: 我的地图是使用 ArcGIS JS API 的 Esri 地图,由于ArcGIS JS API通过Dojo提供,因此该地图通过angular-esri-loader库提供。
因此,它不完全是一个角度上下文,我不得不使用browser.waitForAngularEnabled(false);
来使它工作。