使用量角器 2.0 在 beforeAll 中调用 clear() 行为不当
calling clear() in beforeAll misbehaves with protractor 2.0
我已经从量角器 1.8 升级到量角器 2.0。在 it 块中执行测试场景之前使用 beforeAll (jasmine 2.0) 登录我的应用程序时,我看到了奇怪的行为。似乎最后一次调用 element.clear() 。我看到了这种情况:
- "teacher01" 被输入 usernameFld
- institutionFld 已清除
- "school01" 输入 institutionFld
- passwordFld 已清除
- "teacherpassword" 输入 passwordFld
- usernameFld 已清除
- 登录按钮被点击
- 测试失败,因为 usernameFld 为空
有人能告诉我我做错了什么吗(见下面的代码)?
备注:
我试过切换到 directConnect。我试过将 clear() 和 sendKeys() 分成不同的行。似乎都没有帮助。
使用相同的代码并回滚到 Protractor 1.8.0,我没有遇到这个问题。首先清除usernameFld,然后将用户名输入usernameFld,测试可以正常登录。将登录代码从 beforeAll 移动到 "it" 块中,使测试也按预期运行。
请注意,passwordFld 是 password 类型的输入,而 loginBtn 只是一个按钮。这是针对非 angular 网页的测试。我正在使用 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');
});
});
我不会为您提供解释,但希望能提供解决方案。
将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();
});
我已经从量角器 1.8 升级到量角器 2.0。在 it 块中执行测试场景之前使用 beforeAll (jasmine 2.0) 登录我的应用程序时,我看到了奇怪的行为。似乎最后一次调用 element.clear() 。我看到了这种情况:
- "teacher01" 被输入 usernameFld
- institutionFld 已清除
- "school01" 输入 institutionFld
- passwordFld 已清除
- "teacherpassword" 输入 passwordFld
- usernameFld 已清除
- 登录按钮被点击
- 测试失败,因为 usernameFld 为空
有人能告诉我我做错了什么吗(见下面的代码)?
备注:
我试过切换到 directConnect。我试过将 clear() 和 sendKeys() 分成不同的行。似乎都没有帮助。
使用相同的代码并回滚到 Protractor 1.8.0,我没有遇到这个问题。首先清除usernameFld,然后将用户名输入usernameFld,测试可以正常登录。将登录代码从 beforeAll 移动到 "it" 块中,使测试也按预期运行。
请注意,passwordFld 是 password 类型的输入,而 loginBtn 只是一个按钮。这是针对非 angular 网页的测试。我正在使用 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');
});
});
我不会为您提供解释,但希望能提供解决方案。
将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();
});