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: added e2e test for Login page #619

Merged
merged 23 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 11 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
28 changes: 28 additions & 0 deletions .github/workflows/frontend-e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Front-end e2e test

on:
push:
branches:
- master
pull_request:
branches:
- master
- v2.0

jobs:
frontend-e2e:
name: Front-end e2e test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup Node.js environment for Front-end
uses: actions/setup-node@v1
with:
node-version: 14.x
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved

- name: Install Front-end dependencies
run: yarn install

- name: Start Front-end and Test
run: yarn test:e2e
3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"prettier": "prettier -c --write \"**/*\"",
"site": "yarn run fetch:blocks && yarn run build",
"start": "umi dev",
"test:e2e": "start-server-and-test 'yarn start' http://localhost:8000 'yarn test'",
"start:dev": "cross-env REACT_APP_ENV=dev MOCK=none umi dev",
"start:no-mock": "cross-env MOCK=none umi dev",
"start:no-ui": "cross-env UMI_UI=none umi dev",
Expand Down Expand Up @@ -73,6 +74,7 @@
"react-device-detect": "^1.12.1",
"react-dom": "^16.8.6",
"react-helmet-async": "^1.0.4",
"start-server-and-test": "^1.11.5",
"swagger-ui-react": "^3.33.0",
"umi": "^3.1.2",
"umi-request": "^1.0.8",
Expand Down Expand Up @@ -112,6 +114,7 @@
"mockjs": "^1.0.1-beta3",
"prettier": "^2.0.1",
"pro-download": "1.0.1",
"puppeteer": "^5.4.1",
"puppeteer-core": "^4.0.1",
"stylelint": "^13.0.0"
},
Expand Down
71 changes: 71 additions & 0 deletions frontend/src/e2e/Login.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint-disable import/no-extraneous-dependencies */
const puppeteer = require('puppeteer');

let browser;
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
const domSelectors = {
inputUserName: '#control-ref_username',
inputPassWord: '#control-ref_password',
buttonLogin: '.ant-btn-lg',
notificationNotice: '.ant-notification-notice',
notificationLogin: '.ant-notification-notice-description',
loginSuccessIcon: '.ant-notification-notice-icon-success',
loginFailedIcon: '.ant-notification-notice-icon-error',
};
const loginFailedData = {
userName: 'admin',
passWord: '123456',
};
const loginSuccessData = {
userName: 'admin',
passWord: 'admin',
};

beforeAll(async () => {
browser = await puppeteer.launch({
headless: false,
});
});

describe('Login', () => {
test('Login failed with wrong password', async () => {
const page = await browser.newPage();
await page.goto(BASE_URL);
await page.type(domSelectors.inputUserName, loginFailedData.userName);
await page.type(domSelectors.inputPassWord, loginFailedData.passWord);
await page.click(domSelectors.buttonLogin);
await page.waitForSelector(domSelectors.loginFailedIcon);
await page.close();
}, 10000);

test('Login success then Logout', async () => {
const page = await browser.newPage();
await page.goto(BASE_URL);
await page.type(domSelectors.inputUserName, loginSuccessData.userName);
await page.type(domSelectors.inputPassWord, loginSuccessData.passWord);
await page.click(domSelectors.buttonLogin);
await page.waitForSelector(domSelectors.loginSuccessIcon);
await page.close();
}, 10000);

afterAll(async () => {
await browser.close();
});
});
41 changes: 41 additions & 0 deletions frontend/src/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

### Writing test cases
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

disharmony IMO


1. Installing dependencies and running local development environments

```sh
yarn install && yarn start
```

2. Add a new test case file to the `src/e2e` folder
3. Run test cases

```sh
yarn test
```

If you want to run a particular test file separately, you can execute the following command

```sh
yarn test ${yourFileName}.e2e.js
```

The test results will be displayed on the console.
41 changes: 41 additions & 0 deletions frontend/src/e2e/README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->

### 本地书写测试案例
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved

1. 安装依赖并运行本地开发环境

```sh
yarn install && yarn start
```

2. 在 `src/e2e` 文件夹增加新的测试案例文件
3. 运行测试案例

```sh
yarn test
```

如果你想单独运行某一个测试文件,可以执行如下命令

```sh
yarn test ${yourFileName}.e2e.js
```

测试结果将会在控制台显示。
Loading