'Request Method: POST Status Code: 401 Unauthorized While Clicking a Button to submit the form through Cypress Automation
I am trying to Click on a Button that submits the inputs during the automation in Cypress. While performing manual entry the data is submitted but while submitting through Cypress the input doesn't submit and leads to Status Code: 401 Unauthorized. Cypress Test Runner
context("Checking Add Importer Functionality", () => {
it("submits the form accepting only the mandatory field", () => {
cy.login(data.username, data.password);
cy.get("[title=Static]").click().url().should("include", "/importer");
cy.get(".css-1uccc91-singleValue")
.contains("Importer")
.type("importer {enter}");
cy.get(".buttontext").contains("Add Importer").click();
cy.get("[placeholder=Name]").should("be.visible").type("Ironman");
cy.get("[name=nameNp]").should("be.visible").type("Ironman");
cy.get("[name=eximCode]").clear().type("1234567891234");
cy.get("[type=submit]").click();
Solution 1:[1]
You can try & check by preserving your browser cookies Ex:
beforeEach(() => {
Cypress.Cookies.preserveOnce('<id>')
})
https://docs.cypress.io/api/cypress-api/cookies#Preserve-Once
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pali |
