I have created a fixture which will fetch all credentials.
const myPass = {
password: process.env['CYPRESS_ROBOT_MY_CT_PW']
};
module.exports = (on, config) => {
on('task', {
secret: async () => {
const myPassword = await myCTPass.password;
return myPassword;
}
});
};
i checked ,plugin file works correctly:
i am trying to add this task on commands.js
Cypress.Commands.add('myLogin', (username, password) => {
cy.visit(`${Cypress.env('MY_COMTRAVO_URL')}/assets/about.html`).then(
(win) => {
return new Promise((resolve, reject) => {
cy.task('secret').then((myPassword) => {
const myUsername = username || MY_USERNAME;
const myCTPassword = password || myPassword;
const authenticationDetails = new AuthenticationDetails({
Username: myUsername,
Password: myCTPassword
});
const pool = new CognitoUserPool({
UserPoolId: Cypress.env('USER_POOL_ID'),
ClientId: Cypress.env('CLIENT_ID'),
Storage: win.localStorage
});
const cognitoUser = new CognitoUser({
Username: myUsername,
Pool: pool,
Storage: win.localStorage
});
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: (user) => {
return resolve(user);
},
onFailure: reject
});
});
});
}
);
});
what i want ? - i am trying to log in beforeEach
const MY_URL = Cypress.env('MY_COMTRAVO_URL');
describe('Permission', function() {
beforeEach(function() {
cy.server();
});
it('should create traveler', () => {
cy.route('GET', /\/v1\/account/).as('waitForLoad');
cy.visit(`${MY_URL}/auth/login`);
cy.wait('@waitForLoad');
cy.get('[formcontrolname="email"]')
.type('[email protected]')
.should('have.value', '[email protected]');
cy.task('secret').then((myPassword) => {
cy.get('[type="password"]')
.eq(0)
.type(myPassword)
.should('have.value', myPassword);
});
});
});
i am trying to login beforeEach
describe('test login', function() {
beforeEach(function() {
cy.myLogin();
cy.server();
});
it('should test', () => {
cy.route('GET', /\/v1\/account/).as('waitForLoad');
cy.visit(`${MY_URL}/auth/login`);
cy.wait('@waitForLoad');
});
});
found solution
@nikhilesh009 For the future: It's nice if you write down your solution, so other people in the future can use the information when they find this issue.
Most helpful comment
@nikhilesh009 For the future: It's nice if you write down your solution, so other people in the future can use the information when they find this issue.