量角器:测试视野焦点
protractor: test for focus of field
如何使用量角器测试输入字段是否聚焦?我正在这样做:
it('should focus email field', function(){
expect(element(by.model('login.email')).getAttribute('id')).toEqual(browser.driver.switchTo().activeElement().getAttribute('id'));
});
这似乎适用于 chrome,但该测试无法用于 firefox。有什么想法吗?
这是失败消息:
[firefox #1] 2) Login page should focus email field
[firefox #1] Message:
[firefox #1] Expected 'login' to equal ''.
[firefox #1] Stacktrace:
[firefox #1] Error: Failed expectation
[firefox #1] at [object Object].<anonymous> (/Users/Jason/Desktop/app/test/e2e/login-spec.js:38:69)
[firefox #1]
这是我的测试脚本:
describe('Login page', function() {
var loginURL = 'http://localhost:8090/app/#/login';
var loginEmailField = 'login-email';
beforeEach(function() {
browser.get(loginURL);
});
it('should focus email field', function(){
expect(element(by.id(loginEmailField)).getAttribute('id')).toEqual(browser.driver.switchTo().activeElement().getAttribute('id'));
});
});
您需要等待 angular 才能做出任何断言:
beforeEach(function() {
browser.get(loginURL);
browser.waitForAngular();
});
除此之外,这可能与 autofocus
属性有关,它在 Firefox 中 has/had 问题,请参阅:
- Autofocus Attribute of HTML5 does not work only in FireFox when <Form><input> are loaded via Ajax. WHY?
- Why doesn't autofocus=“autofocus” work in Mozilla Firefox?
如何使用量角器测试输入字段是否聚焦?我正在这样做:
it('should focus email field', function(){
expect(element(by.model('login.email')).getAttribute('id')).toEqual(browser.driver.switchTo().activeElement().getAttribute('id'));
});
这似乎适用于 chrome,但该测试无法用于 firefox。有什么想法吗?
这是失败消息:
[firefox #1] 2) Login page should focus email field
[firefox #1] Message:
[firefox #1] Expected 'login' to equal ''.
[firefox #1] Stacktrace:
[firefox #1] Error: Failed expectation
[firefox #1] at [object Object].<anonymous> (/Users/Jason/Desktop/app/test/e2e/login-spec.js:38:69)
[firefox #1]
这是我的测试脚本:
describe('Login page', function() {
var loginURL = 'http://localhost:8090/app/#/login';
var loginEmailField = 'login-email';
beforeEach(function() {
browser.get(loginURL);
});
it('should focus email field', function(){
expect(element(by.id(loginEmailField)).getAttribute('id')).toEqual(browser.driver.switchTo().activeElement().getAttribute('id'));
});
});
您需要等待 angular 才能做出任何断言:
beforeEach(function() {
browser.get(loginURL);
browser.waitForAngular();
});
除此之外,这可能与 autofocus
属性有关,它在 Firefox 中 has/had 问题,请参阅:
- Autofocus Attribute of HTML5 does not work only in FireFox when <Form><input> are loaded via Ajax. WHY?
- Why doesn't autofocus=“autofocus” work in Mozilla Firefox?