我有一个用JHipster制作的网站:http://www.jhipsterpress.com/#/post/15/view 我正在尝试使用量角器进行测试(我是新手)。因此,我想测试的第一件事是登录该站点。当您进入时,您必须在模式中登录。
describe('JhipsterPress Demo App', function() {
it('Should login', function() {
browser.get('http://www.jhipsterpress.com/#/post/15/view');
element(by.id('username')).sendKeys('admin');
element(by.id('password')).sendKeys('admin');
var username = element(by.binding('username'));
var password = element(by.binding('password'));
element(by.css("button[class='btn btn-primary']")).click().then(function(){
const EC = protractor.ExpectedConditions;
// Waits max. 5 seconds for the input field to become clickable
browser.wait(EC.elementToBeClickable(by.css("button[class='btn btn-primary']")), 5000);
});
});
});
量角器 说...
Message:
Failed: by.id(...).click is not a function
Stack:
TypeError: by.id(...).click is not a function
编辑:修复括号错误后:
Failures:
1) JhipsterPress Demo App Should login
Message:
Failed: element not interactable
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64)
Stack:
ElementNotVisibleError: element not interactable
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64)
你的错误是因为你的括号搞砸了。 您需要在click
功能之前关闭定位器。
将element(by.id('login').click())
更改为element(by.id('login')).click()
当前发生,因为量角器尝试与出现的模态对话框的输入字段进行交互。要解决此问题,您可以使用 Protractor
中的预期条件。
有了它们,您可以等到输入字段可交互:
element(by.id('login').click()).then(function(){
const EC = protractor.ExpectedConditions;
// Waits max. 5 seconds for the input field to become clickable
browser.wait(EC.elementToBeClickable(element(by.id('username')), 5000);
element(by.id('username')).sendKeys('admin');
...
});