Angular 角度2+;量角器试运行无结果
我正在为Angular 2应用程序启动简单的量角器测试,如下所示:Angular 角度2+;量角器试运行无结果,angular,protractor,Angular,Protractor,我正在为Angular 2应用程序启动简单的量角器测试,如下所示: import { browser, element, by } from 'protractor'; describe('My Page', function() { it('should load news block', () => { browser.get('/my/page'); element(by.id('news')).getText().th
import { browser, element, by } from 'protractor';
describe('My Page', function() {
it('should load news block', () => {
browser.get('/my/page');
element(by.id('news')).getText().then(function(text) {
expect(text.length > 0).toBeTruthy();
});
});
});
结果,系统运行浏览器,转到所需页面,如果测试成功执行,我看不到结果。在控制台中,我总是看到“Spec started”消息
我做错了什么
量角器配置文件:
exports.config = {
allScriptsTimeout: 2500000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 2500000,
print: function() {}
},
useAllAngular2AppRoots: true,
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e'
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(new SpecReporter());
}
};
我相信它应该记录一段时间来通过测试;但是,由于您使用的是
SpecReporter
,因此这可能会覆盖控制台的默认报告程序。有两种方法可以对此进行调试:
(更新更多日志记录的答案):
请提供量角器配置文件;-)添加了配置文件。。注意-如果我检查expect(true).toBe(true),所有都可以正常工作,并且我已经尝试使用console.log()进行调试。。但是,当我按F12键打开浏览器控制台时,我的量角器测试因此错误而关闭-console.log应打印到测试运行的区域。因此,在它说
运行1个实例之后,您应该能够看到一些日志记录。我更新了答案,增加了一行日志记录。如果您在窗口中看不到这一行,则说明有其他问题。因此,当我执行console.log-in Digrator测试时,它应该在Windows控制台中打印消息,而不是在浏览器控制台中打印消息?是的,它应该这样做。我还会注释掉/删除量角器配置文件中的onPrepare插件。还有最后一个问题。它是否真的导航到您的“/my/page”?刚刚执行了您的代码,至少可以看到消息“我们将找到新闻id”。但除此之外:(
console.log('we are going to find the news id');
element(by.id('news')).getText().then(text => {
// If we do have text, let's log it so we know we got to this block of code.
console.log('Pass! We have text: ' + text);
expect(text.length > 0).toBeTruthy();
}).catch(err => {
// Else we could not fid the 'news' id, so we should log an error.
console.log('The id for news could not be found.);
console.log(err);
});