https://cypress.io logo
Actually what I want is a little different from th...
# e2e-testing
r
Actually what I want is a little different from the video tutorial. I have multiple environments so I dont want to have in url in cypress.config.js file. I want to export CYPRESS_BASE_URL=... But below in my code I want to replace Cypress.env('url') and that is where I stuck.
Copy code
Cypress.Commands.add('login', (userType, email) => {
  cy.visit('/auth');
  const types = {
    admin: {
      email: 'email',
      password: 'password'
    },
    sales: {
      email: 'email',
      password: 'password'
    },
    newUser: {
      email: email,
      password: 'password'
    }
  };
  const user = types[userType];
  cy.dataCy('email').find('input').clear().type(user.email);
  cy.dataCy('password').find('input').clear().type(user.password);
  cy.btnName('login');
  cy.notification('Signed in successfully');
  cy.request({
    method: 'POST',
    url: Cypress.env('url'),
    body: {
      user: { email: user.email, password: user.password, recaptcha: null, remember_me: true }
    }
  }).then(data => {
    const { headers } = data;
    cy.storeData('token', `{
     "token": "${headers.authorization}" ,
     "name": "${data.body.data.attributes.name}",
     "role": "${data.body.data.attributes.role_name}",
     "userType": "${data.body.data.attributes.user_type}"
     }`);
  });