This is the bug I’m facing I do not understand why the params are not fully gotten with the cypress wait function
thenfunction(){}
AssertionError
expected ’19/0′ to equal ’19/01/2028′
/* eslint-disable mocha/no-setup-in-describe,no-undef,mocha/no-skipped-tests */
// noinspection ES6ConvertRequireIntoImport
require('chai/register-expect');
const {basicResponseObj, bodyObjSearch2} = require("./common");
describe('Stubbed suite', function() {
// Step 1: setup the application state
beforeEach(function () {
cy.clearCookies();
cy.clearLocalStorage();
cy.intercept('GET', '*/entries?usage=basic*', {body: basicResponseObj});
cy.intercept('GET', '*/entries?usage=search*', {body: bodyObjSearch2}).as("searchResults");;
cy.visit('search-test');
});
describe('Search by date range', function () {
it("Fill filter and check query param is filled", () => {
cy.get('#date-from').type("19/01/2028")
cy.get('#date-to').type("19/01/2028")
cy.get('#search-btn').click();
cy.wait("@searchResults").then((req) => {
expect(req.request.query.dateFrom).to.eq("19/01/2028");
});
});
});
})
2
Answers
How I managed to solve this is with adding the api interception to a beforeEach hook to make sure it is used by every test case and changing the first hook
beforeeach
to a before hook.It’s probably not the
intercept
that fails, more likely thetype
needs a delay or some other adjustment.To check, add an assertion after
type()
then add in delay to make the
.type()
stable