-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ismay
committed
Oct 14, 2024
1 parent
9c83e47
commit 506730e
Showing
1 changed file
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,46 @@ | ||
import { enableAutoLogin } from '@dhis2/cypress-commands' | ||
/* global Cypress */ | ||
|
||
enableAutoLogin() | ||
/** | ||
* Custom login command, can be used to login or switch between sessions. | ||
* Will cache and restore cookies, localStorage, and sessionStorage. See: | ||
* https://docs.cypress.io/api/commands/session | ||
*/ | ||
Cypress.Commands.add('login', (user) => { | ||
cy.session( | ||
user, | ||
() => { | ||
// Login via API | ||
cy.request({ | ||
url: `${user.server}/dhis-web-commons-security/login.action`, | ||
method: 'POST', | ||
form: true, | ||
followRedirect: true, | ||
body: { | ||
j_username: user.name, | ||
j_password: user.password, | ||
'2fa_code': '', | ||
}, | ||
}) | ||
|
||
// Set base url for the app platform | ||
window.localStorage.setItem('DHIS2_BASE_URL', user.server) | ||
}, | ||
{ | ||
validate: () => { | ||
cy.request(`${user.server}/api/me`).then((response) => { | ||
expect(response.status).to.eq(200) | ||
expect(response.body.username).to.eq(user.name) | ||
}) | ||
}, | ||
} | ||
) | ||
}) | ||
|
||
// Log in before each test, if not already logged in | ||
beforeEach(() => { | ||
cy.login({ | ||
name: Cypress.env('LOGIN_NAME'), | ||
password: Cypress.env('LOGIN_PASSWORD'), | ||
server: Cypress.env('LOGIN_SERVER'), | ||
}) | ||
}) |