我正在为我的React应用编写赛普拉斯测试。
测试在我的本地计算机上通过,但在CI期间失败,并显示以下消息:
npx cypress run "--config" "baseUrl=http://localhost:12361"
It looks like this is your first time using Cypress: 4.4.0
[09:13:50] Verifying Cypress can run /root/.cache/Cypress/4.4.0/Cypress [started]
[09:13:52] Verifying Cypress can run /root/.cache/Cypress/4.4.0/Cypress [completed]
Opening Cypress...
====================================================================================================
tput: No value for $TERM and no -T specified
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 4.4.0 │
│ Browser: Electron 80 (headless) │
│ Specs: 1 found (subscription.js) │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: subscription.js (1 of 1)
Validate subscriptions screens
1) "before each" hook for "my test"
0 passing (1s)
1 failing
1) Validate subscriptions screens "before each" hook for "my test":
Uncaught ReferenceError: UIC is not defined
This error originated from your application code, not from Cypress.
When Cypress detects uncaught errors originating from your application it will automatically fail the current test.
This behavior is configurable, and you can choose to turn this off by listening to the `uncaught:exception` event.
https://on.cypress.io/uncaught-exception-from-application
Because this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `Validate subscriptions screens`
at eval (webpack:///external_%22UIC%22?:1:18)
at Object.@dds-uicore/all (http://localhost:12361/main.934edbcaff2f713bd900.js:907:1)
at __webpack_require__ (http://localhost:12361/main.934edbcaff2f713bd900.js:80:30)
at eval (webpack:///./src/App.js?:24:74)
at Module../src/App.js (http://localhost:12361/main.934edbcaff2f713bd900.js:221:1)
at __webpack_require__ (http://localhost:12361/main.934edbcaff2f713bd900.js:80:30)
at eval (webpack:///./src/index.js?:7:62)
at Module../src/index.js (http://localhost:12361/main.934edbcaff2f713bd900.js:336:1)
at __webpack_require__ (http://localhost:12361/main.934edbcaff2f713bd900.js:80:30)
at eval (webpack:///multi_(webpack)-dev-server/client?:5:18)
似乎有2个错误:
赛普拉斯测试:
/// <reference types="Cypress" />
describe('E2E tests', function() {
beforeEach(() => {
cy.server();
cy.route('/subscriptions').as('getSubscriptions');
cy.visit('/', {
//needed in order to mock the 'fetch' requests
onBeforeLoad (win) {
delete win.fetch
},
});
cy.contains('Sign In').click();
});
it('my test', function() {
cy.get('table');
cy.wait('@getSubscriptions');
cy.contains('item 1');
});
});
请帮助。 谢谢!