赛普拉斯新手:找不到的元素

时间:2018-11-06 13:21:17

标签: javascript cypress

只是在跟随量角器/茉莉花一起开始使用赛普拉斯。总体而言一切正常,并且使用Cypress UI(Chrome和Electron)都可以正常运行测试。

但是,当我在VS Code或VSTS Pipeline中运行无头Electron时,会出现未找到的元素错误。当在浏览器中运行时,这些元素“就在您的脸上”,所以我不确定是什么问题。

这是一个示例-(以前的规范会加载URL)

describe('OBM Smoketests', function() {
it('Select Hotel and Enter Search Dates', function() {


    cy.get('.jss189 > div > .jss69 > .jss230 > .jss72').click({force: true});

    cy.get('[value="OBMNG3"]').click();
    cy.wait(1000);


});
});

我一直在使用选择器游乐场,可以看出,尝试了“强制”。这就是错误:

1) OBM Smoketests Select Hotel and Enter Search Dates:
 CypressError: Timed out retrying: Expected to find element: '.jss189 > div > .jss69 > .jss230 > .jss72', but never found it.
  at Object.cypressErr (http://localhost:58691/__cypress/runner/cypress_runner.js:62993:11)
  at Object.throwErr (http://localhost:58691/__cypress/runner/cypress_runner.js:62958:18)
  at Object.throwErrByPath (http://localhost:58691/__cypress/runner/cypress_runner.js:62985:17)
  at retry (http://localhost:58691/__cypress/runner/cypress_runner.js:56601:16)
  at http://localhost:58691/__cypress/runner/cypress_runner.js:48711:18
  at tryCatcher (http://localhost:58691/__cypress/runner/cypress_runner.js:124200:23)
  at Promise._settlePromiseFromHandler (http://localhost:58691/__cypress/runner/cypress_runner.js:122218:31)
  at Promise._settlePromise (http://localhost:58691/__cypress/runner/cypress_runner.js:122275:18)
  at Promise._settlePromise0 (http://localhost:58691/__cypress/runner/cypress_runner.js:122320:10)
  at Promise._settlePromises (http://localhost:58691/__cypress/runner/cypress_runner.js:122395:18)
  at Async._drainQueue (http://localhost:58691/__cypress/runner/cypress_runner.js:119124:16)
  at Async._drainQueues (http://localhost:58691/__cypress/runner/cypress_runner.js:119134:10)
  at Async.drainQueues (http://localhost:58691/__cypress/runner/cypress_runner.js:119008:14)
  at <anonymous>

有人提供一些建议吗? 谢谢

更多信息

尽管在Electron中无头运行时,控制台输出指出已经找到了三个规范,并且似乎一个接一个地运行它们,但我已经尝试过了

cypress run --headed

...现在我看到在运行第一个规范后,浏览器将关闭,并针对下一个规范重新启动...这假定浏览器保持打开状态,就像您正在硒中一样的东西!

必须有一种同时运行规格的方法,而不必重新打开浏览器...还是长规格的情况?

2 个答案:

答案 0 :(得分:0)

如果在第一个cy.get之后放置wait(1000)怎么办?

您可以将选择器游乐场用于第一个元素吗? (.jss189> div> .jss69> .jss230> .jss72),然后重试?

答案 1 :(得分:0)

我建议为要获取的元素设置唯一的测试ID。像

data_cy = element1

然后使用这样的get函数

cy.get('[data_cy=element1]').click()