如何使用量角器定位和填充模态?

时间:2019-01-18 16:31:51

标签: protractor jhipster

我有一个使用JHipster创建的网站:http://www.jhipsterpress.com/#/post/15/view,我正在尝试使用Protractor(我是新手)进行测试。因此,我要测试的第一件事是登录该网站。进入时,您必须登录模态。

  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)

2 个答案:

答案 0 :(得分:0)

您的错误是因为您的括号弄乱了。您需要在click函数之前关闭定位器。

element(by.id('login').click())更改为element(by.id('login')).click()

答案 1 :(得分:0)

您当前正在发生,因为量角器试图与出现的模式对话框的输入字段进行交互。为了解决这个问题,您可以使用jessie-backports中的Expected Condition

有了它们,您可以等到输入字段可以交互:

Protractor