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

test action cypress #4383

Draft
wants to merge 20 commits into
base: master
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
50 changes: 19 additions & 31 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,6 @@ jobs:
name: Tests E2E docker
runs-on: ubuntu-20.04
needs: [build_docker_image]
env:
CYPRESS_BASE_URL: http://geotrek.local
CYPRESS_CACHE_FOLDER: ~/cypress/cache

services:
postgres:
Expand Down Expand Up @@ -314,20 +311,15 @@ jobs:
sudo ln -s /home/runner/work/Geotrek-admin/Geotrek-admin/cypress/nginx.conf /etc/nginx/sites-enabled/geotrek.conf
sudo systemctl restart nginx

- name: install Cypress
run: |
cd /home/runner/work/Geotrek-admin/Geotrek-admin/cypress
npm ci
npm list
echo "Waiting for container..."
while ! nc -z "127.0.0.1" "8001"; do
sleep 0.1
done

- name: E2E test
run: |
/home/runner/work/Geotrek-admin/Geotrek-admin/cypress/node_modules/.bin/cypress run -P /home/runner/work/Geotrek-admin/Geotrek-admin/cypress --record --key 64a5a9b3-9869-4a2f-91e4-e3cd27c2f564
continue-on-error: false
- name: Cypress run
uses: cypress-io/github-action@v6
with:
working-directory: cypress
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_BASE_URL: http://geotrek.local
CYPRESS_CACHE_FOLDER: ~/cypress/cache

- name: Archive results as artifacts
uses: actions/upload-artifact@v4
Expand All @@ -342,10 +334,6 @@ jobs:
runs-on: ubuntu-20.04
needs: [ build_deb ]

env:
CYPRESS_BASE_URL: http://geotrek.local
CYPRESS_CACHE_FOLDER: ~/cypress/cache

services:
postgres:
image: postgis/postgis:12-2.5
Expand Down Expand Up @@ -400,16 +388,16 @@ jobs:
sudo cp -r * /opt/geotrek-admin/var/media/upload/
done

- name: Install cypress
run: |
cd /home/runner/work/Geotrek-admin/Geotrek-admin/cypress
npm ci
npm list

- name: E2E test
run: |
/home/runner/work/Geotrek-admin/Geotrek-admin/cypress/node_modules/.bin/cypress run -P /home/runner/work/Geotrek-admin/Geotrek-admin/cypress --record --key 64a5a9b3-9869-4a2f-91e4-e3cd27c2f564
continue-on-error: false
- name: Cypress run
uses: cypress-io/github-action@v6
with:
working-directory: cypress
record: true
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_BASE_URL: http://geotrek.local
CYPRESS_CACHE_FOLDER: ~/cypress/cache

- name: Archive results as artifacts
uses: actions/upload-artifact@v4
Expand Down
17 changes: 17 additions & 0 deletions cypress/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
projectId: 'ktpy7v',
redirectionLimit:400,
requestTimeout: 50000,
defaultCommandTimeout: 80000,
screenshotsFolder: "screenshots",
fixturesFolder: "fixtures",
videosFolder: "videos",
videos: true,
e2e: {
baseUrl: "http://geotrek.local:8000",
supportFile: "support/e2e.js",
specPattern: "e2e/**/*.cy.{js,jsx,ts,tsx}",
},
});
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ describe('Login from home page / admin page', () => {

beforeEach(() => {
cy.setCookie('django_language', 'en');
})
});

it('Redirects to login page.', () => {
cy.visit('/');
cy.url().should('include', '/login/?next=/');
cy.get('form');
cy.contains("Username");
cy.get('[name="username"]');
})
});

it('Fail to login', () => {
cy.visit('/login/?next=/');
Expand All @@ -22,7 +22,7 @@ describe('Login from home page / admin page', () => {
.should('have.value', 'password');
cy.get("button[type='submit']").click();
cy.url().should('include', '/login/?next=/');
})
});

it('Login', () => {
cy.visit('/login/?next=/');
Expand All @@ -35,34 +35,29 @@ describe('Login from home page / admin page', () => {
cy.get("button[type='submit']").click();
cy.url().should('include', '/path/list/');
cy.url().should('not.include', '/login/?next=/');
})
});

it('Redirects to admin login page.', () => {
cy.visit('/admin');
cy.url().should('include', '/login/?next=/');
cy.get('form');
cy.contains("Username");
cy.get('[name="username"]');
})
})

});
});

describe('Logout', () => {
beforeEach(() => {
const username = 'admin';
const password = 'admin';
cy.loginByCSRF(username, password)
.then((resp) => {
expect(resp.status).to.eq(200)
})
Cypress.Cookies.preserveOnce('sessionid', 'csrftoken');
})
cy.loginByCSRF(username, password);
});

it('Logout', () => {
cy.visit('/');
cy.url().should('include', '/path/list/');
cy.get("a.dropdown-toggle").contains('admin').click();
cy.get("a[href='/logout/']").click();
cy.url().should('include', '/login/');
})
})
});
});
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
describe('Create path', () => {
before(() => {
beforeEach(() => {
const username = 'admin';
const password = 'admin';
cy.loginByCSRF(username, password)
.then((resp) => {
expect(resp.status).to.eq(200)
});
})

beforeEach(() => {
Cypress.Cookies.preserveOnce('sessionid', 'csrftoken');
cy.loginByCSRF(username, password);
});

it('Change language', () => {
Expand All @@ -20,6 +13,5 @@ describe('Create path', () => {
cy.url().should('include', '/path/list/');
cy.get("a.dropdown-toggle").contains('admin').click();
cy.get("button.language-menu-item[value='en']").click();
})

})
});
});
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
describe('Create path', () => {
before(() => {
beforeEach(() => {
const username = 'admin';
const password = 'admin';

cy.loginByCSRF(username, password)
.then((resp) => {
expect(resp.status).to.eq(200)
});
cy.loginByCSRF(username, password);
cy.mockTiles();
});

beforeEach(() => {
cy.setCookie('django_language', 'en');
Cypress.Cookies.preserveOnce('sessionid', 'csrftoken');
});

it('Create path', () => {
cy.visit('/path/list');
cy.wait('@tiles');
Expand All @@ -30,7 +21,7 @@ describe('Create path', () => {
cy.get('#save_changes').click();
cy.url().should('not.include', '/path/add/');
cy.get('.content').should('contain', 'Path number 1');
})
});

it('Create path split', () => {
cy.visit('/path/list');
Expand All @@ -44,20 +35,23 @@ describe('Create path', () => {
cy.get('#save_changes').click();
cy.url().should('not.include', '/path/add/');
cy.get('.content').should('contain', 'Path number 2');
})
});

it('Path list', () => {
cy.visit('/path/list');
cy.get("a[title='Path number 1']").should('have.length', 2);
cy.get("a[title='Path number 2']").should('have.length', 2);
})
});

it('Path action delete multiple without path', () => {
cy.visit('/path/list');
cy.get("a.btn-primary[data-toggle='dropdown']").click();
cy.get("a[href='#delete']").click();
cy.url().should('include', '/path/list/');
cy.get("a[title='Path number 1']").should('have.length', 2);
cy.get("a[title='Path number 2']").should('have.length', 2);
})
});

it('Path action delete multiple path', () => {
cy.visit('/path/list');
cy.get("input[name='path[]'][value='1']").click();
Expand All @@ -68,7 +62,8 @@ describe('Create path', () => {
cy.url().should('include', '/path/list/');
cy.get("a[title='Path number 1']").should('have.length', 1);
cy.get("a[title='Path number 2']").should('have.length', 1);
})
});

// Two path
it('Path action merge multiple path', () => {
cy.visit('/path/list');
Expand All @@ -79,6 +74,5 @@ describe('Create path', () => {
cy.get("button").contains('Merge').click();
cy.url().should('include', '/path/list/');
cy.get("table#objects-list tbody tr").should('have.length', 1);
})
// One last path
})
});
});
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
return false
})
return false;
});

describe('Create signage', () => {
before(() => {
beforeEach(() => {
const username = 'admin';
const password = 'admin';

cy.loginByCSRF(username, password)
.then((resp) => {
expect(resp.status).to.eq(200)
});
cy.loginByCSRF(username, password);
cy.mockTiles();
})

beforeEach(() => {
cy.setCookie('django_language', 'en');
Cypress.Cookies.preserveOnce('sessionid', 'csrftoken');
cy.visit('/signage/list');
});

it('Create signage', () => {
cy.visit('/signage/list');
cy.wait('@tiles');
cy.server()
cy.route('/api/signage/drf/signages.geojson').as('signage')
cy.get("a.btn-success[href='/signage/add/']").contains('Add a new signage').click()
cy.wait('@signage')
cy.get("a.pointtopology-control").click()
cy.server();
cy.route('/api/signage/drf/signages.geojson').as('signage');
cy.get("a.btn-success[href='/signage/add/']").contains('Add a new signage').click();
cy.wait('@signage');
cy.get("a.pointtopology-control").click();
cy.get('.leaflet-map-pane')
.click(403, 287);
cy.get("input[name='name_en']").type('Signage number 1')
cy.get("input[name='name_en']").type('Signage number 1');
cy.get("a[href='#name_fr']").click()
cy.get("input[name='name_fr']").type('Signalétique numéro 1')
cy.get("select[id='id_type']").select("Service")
cy.get("input[name='name_fr']").type('Signalétique numéro 1');
cy.get("select[id='id_type']").select("Service");
cy.get('#save_changes').click()
cy.url().should('not.include', '/signage/add/')
})
cy.url().should('not.include', '/signage/add/');
});

it('Liste signage', () => {
cy.visit('/signage/list')
cy.get("a[title='Signage number 1']").should('have.length', 1)
})
})
cy.get("a[title='Signage number 1']").should('have.length', 1);
});
});
Loading
Loading