Nightwatch断言呈现带有类名的锚标记

时间:2018-06-01 15:35:26

标签: nightwatch.js

我正在尝试针对以下锚标记编写Nightwatch测试:

<a class="ui label transition visible" data-value="PRIMARY" style="display: inline-block !important;">
Operational
<i class="delete icon"></i>
</a>

在Chrome的开发工具控制台中,我可以通过引用此锚点 $('a.ui.label.transition.visible')我得到的地方:<a class=​"ui label transition visible" data-value=​"Operational" style=​"display:​ inline-block !important;​">​…​</a>​

在Nightwatch中,我无法引用此锚点。

  'a simple test': function (browser) {
    const devServer = browser.globals.devServerURL
    browser
      .url(devServer+endpoint)
      .waitForElementVisible('.qpi-category-selector.ui.fluid.multiple.selection.normal.dropdown', 5000)
      .assert.elementPresent('a.ui.label.transition.visible')
      .end()
  }

结果:

FAILED: 1 assertions failed and  1 passed (29.052s)
   Testing if element <a.ui.label.transition.visible> is present. - expected "present" but got: "not present"
       at <anonymous>
       at process._tickCallback (internal/process/next_tick.js:188:7)
_________________________________________________

TEST FAILURE:  1 assertions failed, 1 passed. 31.138s

 ✖ study/test
 – QPI filter test (29.052s)
   Testing if element <a.ui.label.transition.visible> is present. - expected "present" but got: "not present"

使用Nightwatch 1.0.4

有什么明显的东西我不见了吗?

1 个答案:

答案 0 :(得分:0)

Answering my own question because this is actually an issue with http vs https.

The test url was set to http://localhost... but our dev environment is set up to use https.

Without https our internal server was unable to communicate:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost.qdss.io:8080' is therefore not allowed access

Hence, some of the anchor tags we expected to show up did not. I changed the url to https and used chromeOptions: { args: ['disable-web-security', 'ignore-certificate-errors'] } tldr: if Nightwatch is not picking up on something that should obviously be there, the problem is probably somewhere else.