Reputation: 778
I'm trying to test our web application with the E2E Testing Framework Cypress. But now I've ran into a problem.
For our webapp we are using two backends one is active and the other inactive. But when testing it is not known which backend is currently active. How can I now write a test that doesnt fail just because one of the URL's cant be reached. Here is the code I currently have.
describe("Backend Test", () => {
it("Test Backend 1", () => {
cy.visit("BACKEND1_HOSTNAME.company.com") //Lets say this fails because backend 1 is currently inactive
})
it("Test Backend 2", () => {
cy.visit("BACKEND2_HOSTNAME.company.com") //This will work because its active
})
})
In this scenario the whole test-suite will fail because one of the backends doesnt respond because its not active.
Is there any way I can avoid the test from failing as long as one of the tests is succesful?
Upvotes: 1
Views: 226
Reputation: 10580
Run one of the backend in a cy.request()
to find out which is active.
describe("Backend Test", () => {
let activeUrl;
before(() => {
cy.request('BACKEND1_HOSTNAME.company.com', {failOnStatusCode:false})
.then(response => {
activeUrl = (repsonse.statusCode === 200) ? 'BACKEND1_HOSTNAME.company.com'
: 'BACKEND2_HOSTNAME.company.com'
})
})
it("Test active backend", () => {
cy.visit(activeUrl)
})
})
Upvotes: 1