-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41033 from nextcloud/chore/migrate-login-feature
chore(tests): Migrate login acceptance tests from behat to Cypress
- Loading branch information
Showing
5 changed files
with
146 additions
and
236 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
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 |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import type { User } from '@nextcloud/cypress' | ||
|
||
describe('Login', () => { | ||
let user: User | ||
let disabledUser: User | ||
|
||
after(() => cy.deleteUser(user)) | ||
before(() => { | ||
// disable brute force protection | ||
cy.runOccCommand('config:system:set auth.bruteforce.protection.enabled --value false --type bool') | ||
cy.createRandomUser().then(($user) => { | ||
user = $user | ||
}) | ||
cy.createRandomUser().then(($user) => { | ||
disabledUser = $user | ||
cy.runOccCommand(`user:disable '${disabledUser.userId}'`) | ||
}) | ||
}) | ||
|
||
beforeEach(() => { | ||
cy.logout() | ||
}) | ||
|
||
it('log in with valid user and password', () => { | ||
// Given I visit the Home page | ||
cy.visit('/') | ||
// I see the login page | ||
cy.get('form[name="login"]').should('be.visible') | ||
// I log in with a valid user | ||
cy.get('form[name="login"]').within(() => { | ||
cy.get('input[name="user"]').type(user.userId) | ||
cy.get('input[name="password"]').type(user.password) | ||
cy.contains('button[data-login-form-submit]', 'Log in').click() | ||
}) | ||
|
||
// see that the login is done | ||
cy.get('[data-login-form-submit]').if().should('not.contain', 'Logging in') | ||
|
||
// Then I see that the current page is the Files app | ||
cy.url().should('match', /apps\/dashboard(\/|$)/) | ||
}) | ||
|
||
it('try to log in with valid user and invalid password', () => { | ||
// Given I visit the Home page | ||
cy.visit('/') | ||
// I see the login page | ||
cy.get('form[name="login"]').should('be.visible') | ||
// I log in with a valid user but invalid password | ||
cy.get('form[name="login"]').within(() => { | ||
cy.get('input[name="user"]').type(user.userId) | ||
cy.get('input[name="password"]').type(`${user.password}--wrong`) | ||
cy.contains('button', 'Log in').click() | ||
}) | ||
|
||
// see that the login is done | ||
cy.get('[data-login-form-submit]').if().should('not.contain', 'Logging in') | ||
|
||
// Then I see that the current page is the Login page | ||
cy.url().should('match', /\/login/) | ||
// And I see that a wrong password message is shown | ||
cy.get('form[name="login"]').then(($el) => expect($el.text()).to.match(/Wrong.+password/i)) | ||
cy.get('input[name="password"]:invalid').should('exist') | ||
}) | ||
|
||
it('try to log in with valid user and invalid password', () => { | ||
// Given I visit the Home page | ||
cy.visit('/') | ||
// I see the login page | ||
cy.get('form[name="login"]').should('be.visible') | ||
// I log in with a valid user but invalid password | ||
cy.get('form[name="login"]').within(() => { | ||
cy.get('input[name="user"]').type(user.userId) | ||
cy.get('input[name="password"]').type(`${user.password}--wrong`) | ||
cy.contains('button', 'Log in').click() | ||
}) | ||
|
||
// see that the login is done | ||
cy.get('[data-login-form-submit]').if().should('not.contain', 'Logging in') | ||
|
||
// Then I see that the current page is the Login page | ||
cy.url().should('match', /\/login/) | ||
// And I see that a wrong password message is shown | ||
cy.get('form[name="login"]').then(($el) => expect($el.text()).to.match(/Wrong.+password/i).and.to.match(/Wrong.+username/)) | ||
cy.get('input[name="password"]:invalid').should('exist') | ||
}) | ||
|
||
it('try to log in with invalid user', () => { | ||
// Given I visit the Home page | ||
cy.visit('/') | ||
// I see the login page | ||
cy.get('form[name="login"]').should('be.visible') | ||
// I log in with an invalid user but valid password | ||
cy.get('form[name="login"]').within(() => { | ||
cy.get('input[name="user"]').type(`${user.userId}--wrong`) | ||
cy.get('input[name="password"]').type(user.password) | ||
cy.contains('button', 'Log in').click() | ||
}) | ||
|
||
// see that the login is done | ||
cy.get('[data-login-form-submit]').if().should('not.contain', 'Logging in') | ||
|
||
// Then I see that the current page is the Login page | ||
cy.url().should('match', /\/login/) | ||
// And I see that a wrong password message is shown | ||
cy.get('form[name="login"]').then(($el) => expect($el.text()).to.match(/Wrong.+password/i).and.to.match(/Wrong.+username/)) | ||
cy.get('input[name="password"]:invalid').should('exist') | ||
}) | ||
|
||
it('try to log in as disabled user', () => { | ||
// Given I visit the Home page | ||
cy.visit('/') | ||
// I see the login page | ||
cy.get('form[name="login"]').should('be.visible') | ||
// When I log in with user disabledUser and password | ||
cy.get('form[name="login"]').within(() => { | ||
cy.get('input[name="user"]').type(disabledUser.userId) | ||
cy.get('input[name="password"]').type(disabledUser.password) | ||
cy.contains('button', 'Log in').click() | ||
}) | ||
|
||
// see that the login is done | ||
cy.get('[data-login-form-submit]').if().should('not.contain', 'Logging in') | ||
|
||
// Then I see that the current page is the Login page | ||
cy.url().should('match', /\/login/) | ||
// And I see that the disabled user message is shown | ||
cy.get('form[name="login"]').then(($el) => expect($el.text()).to.match(/User.+disabled/i)) | ||
cy.get('input[name="password"]:invalid').should('exist') | ||
}) | ||
|
||
it('try to logout', () => { | ||
cy.login(user) | ||
|
||
// Given I visit the Home page | ||
cy.visit('/') | ||
// I see the dashboard | ||
cy.url().should('match', /apps\/dashboard(\/|$)/) | ||
|
||
// When click logout | ||
cy.get('#user-menu button').should('exist').click() | ||
cy.get('#logout a').should('contain.text', 'Log out').click() | ||
|
||
// Then I see that the current page is the Login page | ||
cy.url().should('match', /\/login/) | ||
}) | ||
}) |
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
149 changes: 0 additions & 149 deletions
149
tests/acceptance/features/bootstrap/LoginPageContext.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.