1

我已经从量角器 1.8 升级到量角器 2.0。在 it 块中执行测试场景之前使用 beforeAll (jasmine 2.0) 登录我的应用程序时,我看到了奇怪的行为。似乎对 element.clear() 的第一次调用是最后发生的。我看到这种情况发生:

  1. “teacher01”被输入到 usernameFld
  2. 机构Fld 被清除
  3. “school01”输入到机构Fld
  4. passwordFld 被清除
  5. “teacherpassword”被输入passwordFld
  6. usernameFld 被清除
  7. loginBtn 被点击
  8. 测试失败,因为 usernameFld 为空

有人可以告诉我我做错了什么(见下面的代码)?

笔记:

我试过切换到directConnect。我尝试将 clear() 和 sendKeys() 分成不同的行。似乎都没有帮助。

使用相同的代码并回滚到量角器 1.8.0,我没有这个问题。先清除usernameFld,然后在usernameFld中输入用户名,测试就可以正常登录了。将登录代码从 beforeAll 移到“it”块中,也可以使测试按预期运行。

请注意,passwordFld 是密码类型的输入,而 loginBtn 只是一个按钮。这是对非角度网页的测试。我正在使用 jasmine 2.0、chrome 浏览器 41.0.2272.101、firefox 36.0.4 并从测试脚本启动 selenium 服务器。

HTML:

<input type="text" name="teacherUsername" size="20" value="" tabindex="1" id="username" title="Enter your Username">
<input type="text" name="teacherInstitution" size="20" value="" tabindex="2" id="institution" title="Enter your Institution">
<input type="password" name="teacherPassword" size="20" tabindex="3" id="password" title="Enter your Password">
<button class="submit" tabindex="4" id="loginbtn">Log In</button>

conf.js:

exports.config = {
  framework: 'jasmine2',
  specs: ['school_spec.js']
};

测试:

describe('Protractor 2.0', function() {
  browser.ignoreSynchronization = true;
  var loginBtn = element(by.id('loginbtn'));
  var usernameFld = element(by.id('username'));
  var institutionFld = element(by.id('institution'));
  var passwordFld = element(by.id('password'));

  beforeAll(function() {
    browser.get('http://mypage.net/login.html');
    usernameFld.clear().sendKeys('teacher01');
    institutionFld.clear().sendKeys('school01');
    passwordFld.clear().sendKeys('teacherpassword');
    loginBtn.click();
  });

  it('should work with beforeAll', function() {
    expect(browser.getTitle()).toEqual('My Classes');
  });
});
4

1 回答 1

0

我不会为您提供解释,但希望有一个解决方案。

移动browser.ignoreSynchronization = true;beforeAll()并调用sendKeys()clear()完成:

beforeAll(function() {
    browser.ignoreSynchronization = true;
    browser.get('http://mypage.net/login.html');

    usernameFld.clear().then(function () {
        usernameFld.sendKeys('teacher01');
    });
    institutionFld.clear().then(function () {
        institutionFld.sendKeys('school01');
    });
    passwordFld.clear().then(function () {
        passwordFld.sendKeys('teacherpassword');
    });

    loginBtn.click();
});
于 2015-03-24T21:56:44.350 回答