赛普拉斯新手:未发现的元素
Cypress Newbie : Unfound Elements
刚开始使用 Cypress 是因为 Protractor/Jasmine 的乐趣。总体来说还不错,使用 Cypress UI - Chrome 和 Electron 运行 测试都很好。
但是,当我在 VS 代码或 VSTS 管道中 运行 无头电子时,出现未找到的元素错误。在浏览器中 运行 时,这些元素是 'in your face',所以我不确定是什么问题。
这是一个示例 -(之前的规范加载 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);
});
});
我一直在使用 Selector Playground,可以看出,我尝试了 'force'。这是错误:
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 中 运行ning headless 时,控制台输出表明已找到三个规范并且似乎 运行 他们一个接一个,我已经尝试过
cypress run --headed
...现在我看到在第一个规范 运行 之后,浏览器关闭并为下一个规范重新启动...假设浏览器保持打开状态...就像您在 Selenium 中做同样的事情一样!
必须有一种方法可以同时 运行 指定规范而不必重新打开浏览器...或者是长规范的情况?
如果你把 wait(1000) 放在第一个 cy.get 之后会怎么样?
你可以为第一个元素使用选择器游乐场吗? (.jss189 > div > .jss69 > .jss230 > .jss72) 再试一次?
我建议给你想要获取的元素设置一个唯一的测试ID。像
data_cy = element1
然后像这样使用get函数
cy.get('[data_cy=element1]').click()
刚开始使用 Cypress 是因为 Protractor/Jasmine 的乐趣。总体来说还不错,使用 Cypress UI - Chrome 和 Electron 运行 测试都很好。
但是,当我在 VS 代码或 VSTS 管道中 运行 无头电子时,出现未找到的元素错误。在浏览器中 运行 时,这些元素是 'in your face',所以我不确定是什么问题。
这是一个示例 -(之前的规范加载 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);
});
});
我一直在使用 Selector Playground,可以看出,我尝试了 'force'。这是错误:
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 中 运行ning headless 时,控制台输出表明已找到三个规范并且似乎 运行 他们一个接一个,我已经尝试过
cypress run --headed
...现在我看到在第一个规范 运行 之后,浏览器关闭并为下一个规范重新启动...假设浏览器保持打开状态...就像您在 Selenium 中做同样的事情一样!
必须有一种方法可以同时 运行 指定规范而不必重新打开浏览器...或者是长规范的情况?
如果你把 wait(1000) 放在第一个 cy.get 之后会怎么样?
你可以为第一个元素使用选择器游乐场吗? (.jss189 > div > .jss69 > .jss230 > .jss72) 再试一次?
我建议给你想要获取的元素设置一个唯一的测试ID。像
data_cy = element1
然后像这样使用get函数
cy.get('[data_cy=element1]').click()