I am facing some unusual situations and I'm not quite sure how to address them.
As a newcomer to testing, I've been tasked with testing a website's cart function for proper functionality.
The challenge arises when we add a certain number of products to the cart and run a stock check. If there is a conflict in stock availability, we must resolve it before proceeding; otherwise, we can continue as usual.
I have successfully created a function that resembles the following:
describe("Details page", function () {
detailsPage = new DetailsPage();
// Checking if the details page is accessible via the specified URL
it(`Is defined by the URL: ${userData["url"]}${browser.baseUrl}`,
async function () {
await detailsPage.navigateDesktop();
});
// Verifying that the details page includes a form for user data input
it("Has a form that can receive user data",
async function() {
await detailsPage.fillFormWithUserData();
await utils.click(detailsPage.getForm().buttons.nextStep);
});
if (detailsPage.hasStockConflict()) {
// Allowing users to resolve stock conflicts on the details page
it('Enables resolution of stock conflicts', async function () {
// Waiting for stock information to fully load
await detailsPage.hasStockConflict();
await detailsPage.clickAllRemoveButtons();
await detailsPage.clickAllDecreaseButtons();
});
// Granting access to the next stage of purchasing once all conflicts are resolved
it('Allows the user to proceed to the next stage of purchasing', async function () {
const nextStepButton = detailsPage.getForm().buttons.nextStep;
await utils.elementToBeClickable(nextStepButton);
await utils.click(nextStepButton);
});
}
});
However, my main issue lies in the fact that I need to wait until I receive a response from the server. This could either be a stock conflict triggered by:
hasStockConflict() //checks if there is stockConflict message in DOM
Or redirection to a new page.
My question is, how can I create a functional solution that automatically checks for a stock conflict? If one is detected, the problem should be resolved; otherwise, we can bypass this step and move forward without interruption (leading us to the next page).
I have set a timeout of 1 minute. If no resolution is reached within that time frame, the test will fail.
In essence, I aim to handle stock conflicts as required or skip over them seamlessly. Any guidance on effective testing practices would also be greatly appreciated!