简体   繁体   English

赛普拉斯:由于超时,在浏览器中通过的相同测试在无头模式下失败

[英]Cypress: same tests that pass in browser fail in headless mode due to timeout

When I run Cypress with vue-cli-service test:e2e --headless some tests inside a register request callback fail:当我使用vue-cli-service test:e2e --headless运行 Cypress 时,注册请求回调中的一些测试失败:

在此处输入图像描述

whereas normally when run in browser ( vue-cli-service test:e2e ) they pass:而通常在浏览器中运行时( 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;
        });
(...)

Stack trace:堆栈跟踪:

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://localho 1) 试用注册表提交时没有促销代码:CypressError:重试超时:预期<button#btn-submit.thz-button.thz-radius-50.thz-btn-border-2.thz-align-center.thz-ff-g-hind-vadodara-600>不要在 Object.cypressErr ( https://localhost:8000/__cypress/runner/cypress_runner.js:82944:11 ) 在 Object.throwErr ( Object.throwErr ( 885205638 localhost:8000/__cypress/runner/cypress_runner.js:82909:18 ) 在 Object.throwErrByPath ( https://localhost:8000/__cypress/runner/cypress_runner.js:82936:17 ) 在重试 ( 88105683835270: 8000/__cypress/runner/cypress_runner.js:76454:16 )在https://localhost:8000/__cypress/runner/cypress_runner.js:68529:18在 tryCatcher( https://localhost:8000/__cypress/runner/cypress_runner .js:131381:23 ) 在 Promise._settlePromiseFromHandler ( https://localhost:8000/__cypress/runner/cypress_runner.js:129399:31 ) 在 Promise._settlePromise ( 88520583 38520563 st: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 ST:8000/__ CYPRESS/RUNNER/CYPRESS_RUNNER.JS:129456:18 )致电Promise._settlePromise0( https:// localhost:8000/__ cypress/runner/cypress/cypress/cypress_runner.js:1295011: 12959595959595959595959595959595959595959590.1959595959595909. localhost:8000/__cypress/runner/cypress_runner.js:129576:18 ) 在 Async._drainQueue ( https://localhost:8000/__cypress/runner/cypress_runner.js:126305:16 ) 在 Async._drainQueues ( https:// localhost:8000/__cypress/runner/cypress_runner.js:126315:10 ) 在 Async.drainQueues ( https://localhost:8000/__cypress/runner/cypress_runner.js:126189:14 ) 在

Following lines inside cy.wait('@register') callback should pass in headless mode: 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');

Looks like the timeout happens because elements #btn-submit and .thz-items-loading are not reachable in @register callback, even though in both cases they exist in DOM, but why?看起来超时是因为元素#btn-submit.thz-items-loading@register回调中无法访问,即使在这两种情况下它们都存在于 DOM 中,但为什么呢? They are reachable before the request just fine.在请求之前可以访问它们就好了。

I'm running Cypress 3.2.0 from a project created with vue-cli on Windows 10. Tested app is not a part of the project, is hosted elsewhere and is a static html page.我在 Windows 10 上从使用 vue-cli 创建的项目运行 Cypress 3.2.0。经过测试的应用程序不是该项目的一部分,托管在其他地方,是一个 static html 页面。 Headless browser is Electron 59.无头浏览器是 Electron 59。

It turns out that Electron browser silently fails at executing newer syntax like Promises, that's why code in resolved Promise's then() callback which was supposed to change display property of .thz-items-loading and #btn-submit was never executed and tests expecting that change never passed.事实证明,Electron 浏览器在执行像 Promises 这样的新语法时默默地失败了,这就是为什么在已解决的 Promise 的then()回调中的代码应该改变.thz-items-loading#btn-submit显示属性从未执行过并且测试期望这种变化从未过去。

Adding babel's polyfills before main.js of tested APP fixed this issue:在测试APP的main.js之前添加babel的main.js修复了这个问题:

<script src="../../node_modules/@babel/polyfill/dist/polyfill.min.js"></script> <!-- or copy to root dir in build process -->
<script src="./main.js"></script>

This fixed it for me:这为我修好了:

"experimentalFetchPolyfill": true 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Cypress 测试在无头运行时失败,但在 Cypress 界面上运行时通过 - Cypress tests fail when running headless but pass when running on Cypress interface 单元测试失败并出现错误“超过 '4000ms' 的赛普拉斯命令超时”。 - Unit tests fail with error “Cypress command timeout of '4000ms' exceeded.” AngularJS量角器:在无头模式下随机失败(Firefox) - AngularJS Protractor: randomly fail in headless mode (Firefox) 赛普拉斯不在无头模式下重复使用 cookie 或会话 - Cypress not re-using cookies or session in headless mode 在无头模式下测试嵌套 iframe 时出现赛普拉斯错误 - 竞争条件 - Cypress error when testing nested iframes in headless mode - race condition 赛普拉斯模糊事件(当输入失去焦点时)不会由无头“cypress run --browser firefox”触发,而是与“cypress open”一起使用 - Cypress blur events (when input loses focus) are not triggered with headless "cypress run --browser firefox" but work with "cypress open" 酶测试由于在React 16中掉毛而失败 - Enzyme tests fail due to linting in React 16 Cypress:检查浏览器是否处于全屏模式 - Cypress: check if browser is in full screen mode Cypress:如何获取 Cypress 开始以无头模式录制的时间戳? - Cypress: How can I get the timestamp of when Cypress start to record in headless mode? 将相同的随机数传递给赛普拉斯的所有测试 - Passing a same random number to all tests in Cypress
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM