我有以下设置来测试指令:
beforeEach(inject(function($compile, $rootScope, $injector) {
$httpBackend = $injector.get('$httpBackend');
var html = '<password-strength-bar password-to-check="password"></password-strength-bar>';
scope = $rootScope.$new();
elm = angular.element(html);
$compile(elm)(scope);
$httpBackend.expectGET('l10n/en.js').respond({});
$httpBackend.expectGET('tpl/page_signin.html').respond({});
}));
这在Mac上运行良好。但是,当我在Linux上运行相同的代码时,它会因以下错误而失败。它是一个无头的Linux盒子,但我使用PhantomJS作为我的浏览器&#34;在karma.conf.js
。
Error: Unsatisfied requests: GET tpl/page_signin.html
我确认两个操作系统都使用相同版本的Node。
在类似的说明中,我已经安装了Chrome和Xfvb(通过Jenkins)来运行由Protractor驱动的e2e测试。以下在我的Mac本地运行时工作正常,但在Linux上失败。
it('should render signup when user clicks on "Create one" link', function () {
var signupLink = element(by.linkText('Create one'));
expect(signupLink.isDisplayed()).toBe(true);
signupLink.click();
expect(element.all(by.css('.wrapper')).first().getText()).
toMatch(/Hi there, we're so glad you're here./);
在Jenkins(在Linux上),错误是:
Failures:
1) account signup should render signup when user clicks on "Create one" link
Message:
[31m Expected '' to match /Hi there, we're so glad you're here./.[0m
Stack:
Error: Failed expectation
at Object.<anonymous> (/var/lib/jenkins/jobs/myapp/workspace/tests/e2e/account.js:27:17)
at runMicrotasksCallback (node.js:337:7)
任何想法为什么测试在Mac上运行正常,但在Linux上没有?
答案 0 :(得分:0)
原来这是因为我的Protractor测试使用了by.linkText('Create one')。一旦我将一个id添加到链接并由.id('create-account')使用,它就可以工作。
我还发现使用$('。alert')或by.css('alert')并不像by.id那样好用。特别是当您单击按钮并等待下一个屏幕上显示的内容时。例如:
var alert = element(by.id('success'));
browser.driver.wait(protractor.until.elementIsVisible(alert));