量角器:测试领域焦点 [英] protractor: test for focus of field

查看:65
本文介绍了量角器:测试领域焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何测试输入字段是否与量角器不匹配?我正在这样做:

How can I test if an input field is infocus with protractor? I'm doing this:

it('should focus email field', function(){
    expect(element(by.model('login.email')).getAttribute('id')).toEqual(browser.driver.switchTo().activeElement().getAttribute('id'));
});

这似乎适用于chrome,但是此测试对于firefox失败.有什么想法吗?

This seems to work with chrome, but this test fails with firefox. Any ideas?

这是失败消息:

[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'));
    });
});

推荐答案

在进行任何断言之前,您需要等待角度:

You need to wait for angular before making any assertions:

beforeEach(function() {
    browser.get(loginURL);
    browser.waitForAngular();
});

除此之外,它可能与 autofocus 属性相关,它在Firefox中存在/有问题,请参见:

Aside from that, this might be connected to the autofocus attribute, it has/had issues in Firefox, see:

这篇关于量角器:测试领域焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆