Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): Migrate login acceptance tests from behat to Cypress #41033

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1621,36 +1621,6 @@ trigger:
- pull_request
- push

---
kind: pipeline
name: acceptance-login

steps:
- name: submodules
image: ghcr.io/nextcloud/continuous-integration-alpine-git:latest
commands:
- git submodule update --init
- name: acceptance-login
image: ghcr.io/nextcloud/continuous-integration-acceptance-php8.0:latest
commands:
- tests/acceptance/run-local.sh --timeout-multiplier 10 --nextcloud-server-domain acceptance-login --selenium-server selenium:4444 allow-git-repository-modifications features/login.feature

services:
- name: selenium
image: ghcr.io/nextcloud/continuous-integration-selenium:3.141.59
environment:
# Reduce default log level for Selenium server (INFO) as it is too
# verbose.
JAVA_OPTS: -Dselenium.LOGGER.level=WARNING

trigger:
branch:
- master
- stable*
event:
- pull_request
- push

---
kind: pipeline
name: acceptance-users
Expand Down
146 changes: 146 additions & 0 deletions cypress/e2e/login/login.cy.ts
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/)
})
})
2 changes: 0 additions & 2 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ default:
- FileListContext
- FilesAppContext
- FilesAppSharingContext
- LoginPageContext
- NotificationsContext
- PublicShareContext
- SearchContext
Expand Down Expand Up @@ -46,7 +45,6 @@ default:
- FileListContext
- FilesAppContext
- FilesAppSharingContext
- LoginPageContext
- NotificationsContext
- PublicShareContext
- SearchContext
Expand Down
149 changes: 0 additions & 149 deletions tests/acceptance/features/bootstrap/LoginPageContext.php

This file was deleted.

Loading
Loading