Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Export of Login, Logout... as functions #38

Open
LukasOchmann opened this issue Aug 12, 2022 · 0 comments
Open

Export of Login, Logout... as functions #38

LukasOchmann opened this issue Aug 12, 2022 · 0 comments

Comments

@LukasOchmann
Copy link

We have multiple Users with different Permissions and want to choose which user to login per test.

I currently override the login-function:

// cypress/commands.ts
declare global {
  namespace Cypress {
    interface Chainable {
      login(username?: string, password?: string): Cypress.Chainable
    }
  }
}

and use Cypress.Commands.overwrite to implement it:

// cypress/commands.ts
Cypress.Commands.overwrite('login', (originalFunktion, username: string = '', password: string = '') => {
  // @ts-ignore
  originalFunktion({
    realm: '<realm>',
    root: '<root>',
    client_id: '<client_id>',
    username,
    password,
    redirect_uri: 'http://localhost:8080/',
  })
})

This works but i have to add the ts-ignore-comment and do not get the autocomplete-functions.

The best solution (for me) would be to import the login function.

// cypress/commands.ts
import {login} from 'cypress-keycloak'

declare global {
  namespace Cypress {
    interface Chainable {
      login(username?: string, password?: string): Cypress.Chainable
    }
  }
}

Cypress.Commands.add('login', (username, password) => {
  login({
    realm: '<realm>',
    root: '<root>',
    client_id: '<client_id>',
    username,
    password,
    redirect_uri: 'http://localhost:8080/',
  })
})
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant