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

feat: include cypress tests #18

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
96 changes: 96 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Cypress
on:
pull_request:
push:
branches:
- main

jobs:
cypress:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: otservbr-global
MYSQL_USER: myaac
MYSQL_PASSWORD: myaac
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
matrix:
php-versions: [ '7.4', '8.0', '8.1' ]
name: MyAAC on PHP ${{ matrix.php-versions }}
steps:
- name: 📌 MySQL Start & init & show db
run: |
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE otservbr-global;' -uroot -proot
mysql -e "SHOW DATABASES" -uroot -proot

- name: Checkout MyAAC
uses: actions/checkout@v3
with:
ref: "0.8.12"

- name: Checkout Canary
uses: actions/checkout@v3
with:
repository: opentibiabr/canary
ref: "2.6"
path: canary

- name: Import Canary Schema
run: |
mysql -uroot -proot otservbr-global < canary/schema.sql

- name: Rename config.lua
run: mv canary/config.lua.dist canary/config.lua

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, mysql, json, xml, pdo, pdo_mysql

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Run PHP server
run: nohup php -S localhost:8080 > php.log 2>&1 &

- name: Cypress Run
uses: cypress-io/github-action@v5
env:
CYPRESS_URL: http://localhost:8080
CYPRESS_SERVER_PATH: /home/runner/work/myaac/myaac/canary

- name: Save screenshots
uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-screenshots
path: cypress/screenshots

- name: Upload Cypress Videos
uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-videos
path: cypress/videos
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ node_modules

# cypress
cypress.env.json
cypress/e2e/2-advanced-examples
cypress/e2e/advanced-examples/*

# created by release.sh
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

MyAAC is a free and open-source Automatic Account Creator (AAC) written in PHP. It supports only MySQL databases.

[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/opentibiabr/myaac/cypress.yml)](https://github.com/opentibiabr/myaac/actions)

### Requirements

- PHP 7.4 or later
Expand Down
12 changes: 12 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {defineConfig} = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
// env: {
// URL: 'http://localhost/' //change chere to your myaac url
// }
});
75 changes: 75 additions & 0 deletions cypress/e2e/1-install.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
describe('Install MyAAC', () => {
beforeEach(() => {
// Cypress starts out with a blank slate for each test
// so we must tell it to visit our website with the `cy.visit()` command.
// Since we want to visit the same URL at the start of all our tests,
// we include it in our beforeEach function so that it runs before each test
cy.visit(Cypress.env('URL'))
})

it('Go through installer', () => {
cy.visit(Cypress.env('URL') + '/install/?step=welcome')
cy.wait(1000)

cy.screenshot('install-welcome')

// step 1 - Welcome
cy.get('select[name="lang"]').select('en')

//cy.get('input[type=button]').contains('Next »').click()

cy.get('form').submit()

// step 2 - License
// just skip
cy.contains('GNU/GPL License');
cy.get('form').submit()

// step 3 - Requirements
cy.contains('Requirements check');

cy.get('#step').then(elem => {
elem.val('config');
});

cy.get('form').submit()

// step 4 - Configuration
cy.contains('Basic configuration');

cy.get('#vars_server_path').click().clear().type(Cypress.env('SERVER_PATH'))
cy.get('#vars_mail_admin').click().clear().type('[email protected]')

cy.get('[type="checkbox"]').uncheck() // usage statistics uncheck

cy.wait(1000)

cy.get('form').submit()

// check if there is any error


// step 5 - Import Schema
cy.contains('Import MySQL schema');

// AAC is not installed yet, this message should not come
cy.contains('Seems AAC is already installed. Skipping importing MySQL schema..').should('not.exist')

cy.contains('[class="alert alert-success"]', 'Local configuration has been saved into file: config.local.php').should('be.visible')

cy.get('form').submit()

// step 6 - Admin Account
cy.get('#vars_email').click().clear().type('[email protected]')
cy.get('#vars_account').click().clear().type('admin')
cy.get('#vars_password').click().clear().type('test1234')
cy.get('#vars_password_confirm').click().clear().type('test1234')
cy.get('#vars_player_name').click().clear().type('Admin')

cy.get('form').submit()

cy.contains('[class="alert alert-success"]', 'Congratulations', {timeout: 30000}).should('be.visible')

cy.screenshot('install-finish')
})
})
33 changes: 33 additions & 0 deletions cypress/e2e/2-create-account.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe('Create Account Page', () => {
beforeEach(() => {
// Cypress starts out with a blank slate for each test
// so we must tell it to visit our website with the `cy.visit()` command.
// Since we want to visit the same URL at the start of all our tests,
// we include it in our beforeEach function so that it runs before each test
cy.visit(Cypress.env('URL') + '/index.php/account/create')
})

it('Create Test Account', () => {
cy.screenshot('create-account-page')

cy.get('#account_input').type('tester')
cy.get('#email').type('[email protected]')

cy.get('#password').type('test1234')
cy.get('#password2').type('test1234')

cy.get('#character_name').type('Slaw')

cy.get('#sex1').check()
cy.get('#vocation1').check()
cy.get('#accept_rules').check()

cy.get('#createaccount').submit()

// no errors please
cy.contains('The Following Errors Have Occurred:').should('not.exist')

// ss of post page
cy.screenshot('create-account-page-post')
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Binary file added cypress/screenshots/install-welcome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading
Loading