WebDriver元素为isVisible / waitForForVisible返回false

时间:2015-04-26 16:19:45

标签: meteor cucumber webdriver-io meteor-velocity

我正在Meteor应用程序中进行第一组Cucumber测试,但是我无法使用登录步骤。我的应用程序使用我专门为此项目编写的自定义登录插件。这是步骤,因为我目前用调试输出定义了它:

this.Given(/^I am logged in as a\/an "([^"]*)"$/, function(roleName, callback) {
  this.browser
    .url(url.resolve(process.env.HOST, '/'))
    .waitForExist('#appSignIn');
  this.browser.getHTML('#appSignIn', function(err, html) {
    if (err) {
      console.log('err: ', err);
    } else {
      console.log('link HTML: ', html);
    }
  });
  this.browser.getCssProperty('#appSignIn', 'display', function(err, value) {
    console.log('link HTML display: ', value);
  });
  browser.isVisible('#appSignIn', function(err, isVisible) {
      console.log('#appSignIn', isVisible);
  });
  this.browser
    .waitForVisible('#appSignIn')
    .click('#appSignIn')
    .waitForExist('#username')
    .waitForVisible('#username')
    .setValue('#username', 'test' + roleName)
    .setValue('#password', 'test' + roleName)
    .leftClick('#signin')
    .waitForExist('#appSignOut')
    .waitForVisible('#appSignOut')
    .call(callback);
});

我在这个日志中看到的是:

 Scenario:                               # features/my.feature:11
    Given The server data has been reset  # features/my.feature:12
link HTML:  <a id="appSignIn" href="/signin">Sign In</a>
link HTML display:  { property: 'display',
  value: 'block',
  parsed: { type: 'ident', string: 'block' } }
#appSignIn false
    And I am logged in as a/an "ADMIN"    # features/my.feature:13
      RuntimeError: RuntimeError
           (ScriptTimeout:28) A script did not complete before its timeout expired.
           Problem: Timed out waiting for asyncrhonous script result after 511 ms

基本上,我看到HTML输出,所以我知道元素就在那里。我看到CSS设置为display: block,但随后WebDriver报告该元素在isVisible中不可见,并且同样超时waitForVisible调用。 &#34;登录&#34; link是Bootstrap可折叠导航栏的一部分,位于右上角。

1 个答案:

答案 0 :(得分:2)

问题很简单:视口的默认大小太小,导致Bootstrap nav元素崩溃。我将浏览器大小设置为1000x600,并且按预期工作。