401 - Unauthorized in cypress io auto testing
Solution 1
Here is my way to log in before each test.
const login = () => {
cy.visit('http://0.0.0.0:8080/#/login');
cy.get('#username').type('username');
cy.get('#password').type('1234password$');
cy.get('#login-button').click();
}
describe('UI', () => {
// beforeEach(login);
beforeEach(() => {
login();
Cypress.Cookies.preserveOnce('session_id', 'remember_token');
});
});
Solution 2
I was facing this issue and fix by:
add {failOnStatusCode: false} will ignore the status because Cypress will stop the the run by any 40X status so with {failOnStatusCode: false} will told cypress to continue
cy.visit('/', {failOnStatusCode: false});
John
Updated on June 04, 2022Comments
-
John almost 2 years
First time to write a Cypress (cypress Io framework) auto test for internal website (http://XXXX:8089/). The access of this website homepage requires special permissions by using active directory (get the windows credential and check if the user belongs to a certain group or have the certain role). The testing script is pretty simple:
describe('The Home Page', function() { it('successfully loads', function() { cy.visit('http://XXXX:8089/') }) })
got the 401 -Unauthoized error message. Tried replacing url with embedded windows credential like http://username:password@xxxx:8089/, got the same error. Cannot find a solution through google. Hope someone can kindly help me solve this problem. Thanks a lot.
-
Hackerman almost 6 yearsQuick question, does the
http://username:password@xxxx:8089/
works if you paste the link into a chrome browser? -
John almost 6 yearsYes. It will redirect to xxxx:8089
-
Hackerman almost 6 yearsMaybe related github.com/cypress-io/cypress/issues/850
-
John almost 6 yearsLooks so similar to that one. So there is not any solutions available for this question so far?
-
Hackerman almost 6 yearsThe is a solution, but involves implementing some kind of proxy
-
John almost 6 yearsHackerman, Could you please tell me how?
-
-
Ben Power almost 4 yearsI don't think this solves the issue. You won't be able to find any of the DOM elements such as #username if the AD security is in place. The page won't load and you'll get a 401 instead.