Reputation: 101
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.
Upvotes: 5
Views: 25142
Reputation: 1
I found a solution that worked for my issue on GitHub. You can check it out here: https://github.com/cypress-io/cypress/issues/21213
Workaround can be add the chromeWebSecurity: false
property
on cypress.config.js
:
const { defineConfig } = require("cypress");
module.exports = defineConfig({
projectId: 'f11gqz',
e2e: {
chromeWebSecurity: false,
setupNodeEvents(on, config) {
},
},
});
Upvotes: 0
Reputation: 31
I hope this helps anyone who face the issue.
cy.visit('http://XXXX:8089/', {
auth: {
username: 'admin',
password: 'admin123',
}
});
This one helps me solve the 401 Unauthorized issue. Apparently this helps you solve your issue when you're facing a Basic Authentication when visiting a site.
Source: https://docs.cypress.io/api/commands/visit#Options
Upvotes: 3
Reputation: 49
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});
Upvotes: 4
Reputation: 381
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');
});
});
Upvotes: 1