赛普拉斯:由于超时,在浏览器中通过的相同测试在无头模式下失败
Cypress: same tests that pass in browser fail in headless mode due to timeout
当我 运行 赛普拉斯 vue-cli-service test:e2e --headless
注册请求回调中的一些测试失败时:
而通常当 运行 在浏览器 (vue-cli-service test:e2e
) 中他们通过时:
it('Submit WITHOUT promo code', () => {
cy.server();
cy.route({method: 'POST', url: 'api/register'}).as('register');
cy.get('.thz-items-loading').should('not.be.visible');
cy.get('#btn-submit').should('not.be.disabled');
cy.get('iframe[name^="__privateStripeFrame"]').then(($iframe) => {
const $body = $iframe.contents().find('body');
cy.wrap($body).find('input:eq(1)').click({force: true}).clear();
cy.wrap($body).find('input:eq(1)').type('4000000000009979'); // stolen card
cy.get('#btn-submit').click(); // SUBMIT FORM
cy.wait('@register').then(xhr => {
cy.contains('#card-errors', 'Your card was declined.');
// cy.get('.thz-items-loading').should('not.be.visible'); // FAILS
// cy.get('.thz-items-loading').to.have.style('display', 'none'); // FAILS
cy.get('#btn-submit').should('not.be.disabled'); // FAILS
(...)
});
return null;
});
(...)
堆栈跟踪:
1) Trial registration form Submit WITHOUT promo code:
CypressError: Timed out retrying: expected <button#btn-submit.thz-button.thz-radius-50.thz-btn-border-2.thz-align-center.thz-ff-g-hind-vadodara-600>
not to be 'disabled'
at Object.cypressErr (https://localhost:8000/__cypress/runner/cypress_runner.js:82944:11)
at Object.throwErr (https://localhost:8000/__cypress/runner/cypress_runner.js:82909:18)
at Object.throwErrByPath (https://localhost:8000/__cypress/runner/cypress_runner.js:82936:17)
at retry (https://localhost:8000/__cypress/runner/cypress_runner.js:76454:16)
at https://localhost:8000/__cypress/runner/cypress_runner.js:68529:18
at tryCatcher (https://localhost:8000/__cypress/runner/cypress_runner.js:131381:23)
at Promise._settlePromiseFromHandler (https://localhost:8000/__cypress/runner/cypress_runner.js:129399:31)
at Promise._settlePromise (https://localhost:8000/__cypress/runner/cypress_runner.js:129456:18)
at Promise._settlePromise0 (https://localhost:8000/__cypress/runner/cypress_runner.js:129501:10)
at Promise._settlePromises (https://localhost:8000/__cypress/runner/cypress_runner.js:129576:18)
at Async._drainQueue (https://localhost:8000/__cypress/runner/cypress_runner.js:126305:16)
at Async._drainQueues (https://localhost:8000/__cypress/runner/cypress_runner.js:126315:10)
at Async.drainQueues (https://localhost:8000/__cypress/runner/cypress_runner.js:126189:14)
at
cy.wait('@register')
回调中的以下几行应该以无头模式传递:
cy.get('.thz-items-loading').should('not.be.visible');
cy.get('.thz-items-loading').to.have.style('display', 'none');
cy.get('#btn-submit').should('not.be.disabled');
看起来超时是因为元素 #btn-submit
和 .thz-items-loading
在 @register
回调中无法访问,即使在这两种情况下它们都存在于 DOM 中,但为什么?他们在请求之前就可以访问了。
我正在 运行ning Cypress 3.2.0 来自 Windows 10 上使用 vue-cli 创建的项目。经过测试的应用程序不是该项目的一部分,托管在其他地方并且是一个静态 html 页面。无头浏览器是 Electron 59.
事实证明,Electron 浏览器在执行像 Promises 这样的新语法时默默地失败了,这就是为什么解析 Promise 的 then()
回调中的代码应该更改显示 属性 of .thz-items-loading
和#btn-submit
从未执行过,预期更改的测试从未通过。
在被测APPmain.js
之前添加babel的polyfills修复了这个问题:
<script src="../../node_modules/@babel/polyfill/dist/polyfill.min.js"></script> <!-- or copy to root dir in build process -->
<script src="./main.js"></script>
当我 运行 赛普拉斯 vue-cli-service test:e2e --headless
注册请求回调中的一些测试失败时:
而通常当 运行 在浏览器 (vue-cli-service test:e2e
) 中他们通过时:
it('Submit WITHOUT promo code', () => {
cy.server();
cy.route({method: 'POST', url: 'api/register'}).as('register');
cy.get('.thz-items-loading').should('not.be.visible');
cy.get('#btn-submit').should('not.be.disabled');
cy.get('iframe[name^="__privateStripeFrame"]').then(($iframe) => {
const $body = $iframe.contents().find('body');
cy.wrap($body).find('input:eq(1)').click({force: true}).clear();
cy.wrap($body).find('input:eq(1)').type('4000000000009979'); // stolen card
cy.get('#btn-submit').click(); // SUBMIT FORM
cy.wait('@register').then(xhr => {
cy.contains('#card-errors', 'Your card was declined.');
// cy.get('.thz-items-loading').should('not.be.visible'); // FAILS
// cy.get('.thz-items-loading').to.have.style('display', 'none'); // FAILS
cy.get('#btn-submit').should('not.be.disabled'); // FAILS
(...)
});
return null;
});
(...)
堆栈跟踪:
1) Trial registration form Submit WITHOUT promo code: CypressError: Timed out retrying: expected
<button#btn-submit.thz-button.thz-radius-50.thz-btn-border-2.thz-align-center.thz-ff-g-hind-vadodara-600>
not to be 'disabled' at Object.cypressErr (https://localhost:8000/__cypress/runner/cypress_runner.js:82944:11) at Object.throwErr (https://localhost:8000/__cypress/runner/cypress_runner.js:82909:18) at Object.throwErrByPath (https://localhost:8000/__cypress/runner/cypress_runner.js:82936:17) at retry (https://localhost:8000/__cypress/runner/cypress_runner.js:76454:16) at https://localhost:8000/__cypress/runner/cypress_runner.js:68529:18 at tryCatcher (https://localhost:8000/__cypress/runner/cypress_runner.js:131381:23) at Promise._settlePromiseFromHandler (https://localhost:8000/__cypress/runner/cypress_runner.js:129399:31) at Promise._settlePromise (https://localhost:8000/__cypress/runner/cypress_runner.js:129456:18) at Promise._settlePromise0 (https://localhost:8000/__cypress/runner/cypress_runner.js:129501:10) at Promise._settlePromises (https://localhost:8000/__cypress/runner/cypress_runner.js:129576:18) at Async._drainQueue (https://localhost:8000/__cypress/runner/cypress_runner.js:126305:16) at Async._drainQueues (https://localhost:8000/__cypress/runner/cypress_runner.js:126315:10) at Async.drainQueues (https://localhost:8000/__cypress/runner/cypress_runner.js:126189:14) at
cy.wait('@register')
回调中的以下几行应该以无头模式传递:
cy.get('.thz-items-loading').should('not.be.visible');
cy.get('.thz-items-loading').to.have.style('display', 'none');
cy.get('#btn-submit').should('not.be.disabled');
看起来超时是因为元素 #btn-submit
和 .thz-items-loading
在 @register
回调中无法访问,即使在这两种情况下它们都存在于 DOM 中,但为什么?他们在请求之前就可以访问了。
我正在 运行ning Cypress 3.2.0 来自 Windows 10 上使用 vue-cli 创建的项目。经过测试的应用程序不是该项目的一部分,托管在其他地方并且是一个静态 html 页面。无头浏览器是 Electron 59.
事实证明,Electron 浏览器在执行像 Promises 这样的新语法时默默地失败了,这就是为什么解析 Promise 的 then()
回调中的代码应该更改显示 属性 of .thz-items-loading
和#btn-submit
从未执行过,预期更改的测试从未通过。
在被测APPmain.js
之前添加babel的polyfills修复了这个问题:
<script src="../../node_modules/@babel/polyfill/dist/polyfill.min.js"></script> <!-- or copy to root dir in build process -->
<script src="./main.js"></script>