При запуске моего теста на кипарис он сразу пропускает тест и прогоняет после него. Затем он регистрирует сообщение об ошибке и завершает:
Uncaught CypressError: Cannot call "cy.get()" outside a running test.
This usually happens when you accidentally write commands outside an it(...) test.
If that is the case, just move these commands inside an it(...) test.
Check your test file for errors.
https://on.cypress.io/cannot-execute-commands-outside-test
This error originated from your test code, not from Cypress.
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.
Любые идеи, которые могут быть причиной этого странного поведения. Он должен сначала запустить тест, а затем запустить хуки после. Я использую Cypress-Cucumber-препроцессор и запускаю файл функций.
Ниже мой индекс. js из папки поддержки (для перехватов):
import '@applitools/eyes-cypress/commands';
import './commands';
const xhrData = [];
//Hooks
before(function () {
cy.fixture('./TestData').as('TestData');
// runs once before all tests in the block
cy.server({
// Here we hanDle all requests passing through Cypress' server
onResponse: (response) => {
if (Cypress.env('record')) {
const url = response.url;
const method = response.method;
const data = response.response.body;
// We push a new entry into the xhrData array
xhrData.push({ url, method, data });
}
}
});
// This tells Cypress to hook into any GET request
if (Cypress.env('record')) {
cy.route({
method: 'GET',
url: '*',
});
cy.route({
method: 'POST',
url: '*',
});
}
// Load stubbed data from local JSON file
if (!Cypress.env('record')) {
cy.fixture('fixture')
.then((data) => {
for (let i = 0, length = data.length; i < length; i++) {
cy.route(data[i].method, data[i].url, data[i].data);
}
});
}
});
beforeEach(function () {
cy.visit(Cypress.config().baseUrl);
// runs before each test in the block
cy.eyesOpen({
appName: 'CafeTownsend',
testName: 'Complete Happy Path',
browser: {
"viewportWidth": 1000,
"viewportHeight": 660
},
});
});
after(function () {
// runs once after all tests in the block
if (Cypress.env('record')) {
const path = './cypress/fixtures/fixture.json';
cy.writeFile(path, xhrData);
cy.log("Wrote "+ xhrData.length +" XHR responses to local file "+path);
}
});
afterEach(function () {
// runs after each test in the block
cy.eyesClose();
cy.reload();
});