diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c38c191..e5f8199f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -76,11 +76,48 @@ jobs: version: latest args: --disable-all -c dummy.yml -E=gofumpt --max-same-issues=0 --timeout 5m --modules-download-mode=mod + e2e: + name: e2e-test + runs-on: ubuntu-latest + needs: [ frontend, backend, linter ] + services: + mysql: + image: mysql:5.7 + env: + MYSQL_DATABASE: casdoor + MYSQL_ROOT_PASSWORD: 123456 + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: '^1.16.5' + - uses: actions/setup-node@v2 + with: + node-version: 16 + - name: front install + run: yarn install + working-directory: ./web + - name: front start + run: nohup yarn start & + working-directory: ./web + - name: back start + run: nohup go run ./main.go & + working-directory: ./ + - name: Sleep for starting + run: sleep 60s + shell: bash + - name: e2e + run: npx cypress run --spec "**/e2e/**.cy.js" + working-directory: ./web + release-and-push: name: Release And Push runs-on: ubuntu-latest if: github.repository == 'casdoor/casdoor' && github.event_name == 'push' - needs: [ frontend, backend, linter ] + needs: [ frontend, backend, linter, e2e ] steps: - name: Checkout uses: actions/checkout@v2 diff --git a/web/cypress.config.js b/web/cypress.config.js new file mode 100644 index 00000000..0969aae3 --- /dev/null +++ b/web/cypress.config.js @@ -0,0 +1,7 @@ +module.exports = { + e2e: { + setupNodeEvents(on, config) { + // implement node event listeners here + }, + }, +}; diff --git a/web/cypress/e2e/login.cy.js b/web/cypress/e2e/login.cy.js new file mode 100644 index 00000000..01f60865 --- /dev/null +++ b/web/cypress/e2e/login.cy.js @@ -0,0 +1,56 @@ +describe("Login test", () => { + const selector = { + username: "#input", + password: "#normal_login_password", + loginButton: ".ant-btn", + }; + it("Login succeeded", () => { + cy.request({ + method: "POST", + url: "http://localhost:7001/api/login", + body: { + "application": "app-built-in", + "organization": "built-in", + "username": "admin", + "password": "123", + "autoSignin": true, + "type": "login", + "phonePrefix": "86", + }, + }).then((Response) => { + expect(Response).property("body").property("status").to.equal("ok"); + }); + }); + it("ui Login succeeded", () => { + cy.visit("http://localhost:7001"); + cy.get(selector.username).type("admin"); + cy.get(selector.password).type("123"); + cy.get(selector.loginButton).click(); + cy.url().should("eq", "http://localhost:7001/"); + }); + + it("Login failed", () => { + cy.request({ + method: "POST", + url: "http://localhost:7001/api/login", + body: { + "application": "app-built-in", + "organization": "built-in", + "username": "admin", + "password": "1234", + "autoSignin": true, + "type": "login", + "phonePrefix": "86", + }, + }).then((Response) => { + expect(Response).property("body").property("status").to.equal("error"); + }); + }); + it("ui Login failed", () => { + cy.visit("http://localhost:7001"); + cy.get(selector.username).type("admin"); + cy.get(selector.password).type("1234"); + cy.get(selector.loginButton).click(); + cy.url().should("eq", "http://localhost:7001/login"); + }); +}); diff --git a/web/cypress/support/commands.js b/web/cypress/support/commands.js new file mode 100644 index 00000000..66ea16ef --- /dev/null +++ b/web/cypress/support/commands.js @@ -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) => { ... }) \ No newline at end of file diff --git a/web/cypress/support/e2e.js b/web/cypress/support/e2e.js new file mode 100644 index 00000000..0e7290a1 --- /dev/null +++ b/web/cypress/support/e2e.js @@ -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') \ No newline at end of file