![](/img/trans.png)
[英]AngularJS & Protractor & Jasmine - global variable for all specs
[英]angularjs protractor 3.3.0 not reporting specs
我沒有看到傳遞的運行的預期輸出,斷言沒有列出。 我希望在這一行中看到斷言“1規格,0失敗”。
輸出:
[18:28:06] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[18:28:06] I/launcher - Running 1 instances of WebDriver
Started
.
1 spec, 0 failures
Finished in 0.854 seconds
[18:28:08] I/launcher - 0 instance(s) of WebDriver still running
[18:28:08] I/launcher - chrome #01 passed
在量角器的網站上可以看到預期的運行結束輸出, http://www.protractortest.org/#/ “運行測試”):
1 test, 3 assertions, 0 failures
規格:
describe('Viewing index.html', function() {
'use strict';
beforeEach(function(){
browser.get('/');
});
it('should have pages in left nav', function() {
expect(element.all(by.repeater('page in adminClient.selectedSite.pages')).count()).toBeGreaterThan(0);
});
});
我驗證了by.repeater定位器的工作原理:
element.all(by.repeater('page in adminClient.selectedSite.pages')).count()
.then(function(count){
console.log('page count: ' + count);
});
[更新]根據這個SO,這是一個版本問題,並建議在onPrepare鈎子上注入jasmine記者,但這給我帶來了更多的運行時錯誤。 堆棧溢出問題
我的量角器配置:
exports.config = {
allScriptsTimeout: 11000,
chromeOnly: true,
chromeDriver: 'node_modules/protractor/bin/selenium/chromedriver_2.21',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['tests/e2e/*-spec.js'],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:8889/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
要查看規范名稱和斷言,必須將--verbose
標志傳遞給量角器。 如果您使用grunt或其他東西來運行量角器,則需要在配置中指定此標志。
編輯閱讀完編輯后,我相信我找到了解決問題的方法。 我用我自己的項目嘗試過它似乎工作。
潛在的問題是你可能使用量角器3,它不再支持許多以前的選項,特別是在jasmineNodeOpts
。 要解決此問題,您應該將量角器的版本降級為2,最新版本為2.5.1
這是關於量角器的github存儲庫的相關問題 。 它還提到了onPrepare鈎子中的一個自定義記者,就像你在談論的那樣,但是另一個: jasmine-spec-reporter
。 我的工作原理與你使用的配置略有不同,但它沒有顯示斷言,只是為測試提供了更好的輸出,我非常喜歡:
jasmineNodeOpts: {
print: function () {} // remove dots for each test
},
onPrepare: function () {
var SpecReporter = require('jasmine-spec-reporter');
jasmine.getEnv().addReporter(new SpecReporter({displayStackTrace: true}));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.