Skip to content

Commit 34d8033

Browse files
authored
Merge pull request #11 from dashingsoft/robot-test
Robot test
2 parents 08d283e + bf7d55b commit 34d8033

13 files changed

+608
-0
lines changed

test/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Codebang Tests
2+
This folder contains the various test runners for **codebang**.
3+
4+
## Requirements
5+
6+
### 1. Install the dependencis
7+
Before running the test, install the dependencies:
8+
```sh
9+
python3 -m pip install robotframework robotframework-SeleniumLibrary
10+
```
11+
12+
### 2. Install webDirvers
13+
The general approach to install a browser driver is downloading a right driver, such as chromedriver for Chrome, and placing it into a directory that is in **PATH**. Drivers for different browsers can be found as follows
14+
15+
* [ChromeDriver for google Chrome](https://npm.taobao.org/mirrors/chromedriver/)
16+
17+
* [Geckodriver for firefox](https://npm.taobao.org/mirrors/geckodriver/)
18+
19+
### 3. Start server
20+
21+
You have to start future-server at port `9092`. Change directory to `future-server` in a terminal,
22+
then
23+
```sh
24+
python3 manage.py runserver 9092
25+
```
26+
27+
Change directory to `codebang` in a terminal and start codebang at any port you expected(default: `8080`), then
28+
```sh
29+
npm run serve
30+
```
31+
32+
You may want to use a shell script named `autostart.sh` for starting codebang and future-server automaticaly.
33+
```sh
34+
./autostart.sh
35+
```
36+
37+
## Run tests
38+
Create a directory for test log files
39+
```sh
40+
mkdir test-results
41+
```
42+
43+
Run any test suite which contains some test cases
44+
```sh
45+
cd codebang/test
46+
robot -X -d test-results --suite login_suite code_manager
47+
```
48+
49+
Run one test case that is in a test suite
50+
```sh
51+
robot -X -d test-results --suite login_suite --test login_with_valid_user
52+
```
53+
54+
Run the smoke test with `-i tag`
55+
```sh
56+
robot -X -d test-results -i normal .
57+
```
58+
59+
Run the whole test suite
60+
```sh
61+
robot -X -d test-results .
62+
```
63+
64+
## Test cases
65+
See [Test Cases List](codebang_test_cases.md)
66+
67+
## Test guide
68+
[Codebang Test Guide For Developer](codebang_test_guide.md)

test/autostart.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
CODEBANG_WORKSPACE="/media/devecor/Data/clone/codebang"
3+
IFUTURE_SERVER_WORKSPACE="/media/devecor/Data/clone/future-server/ifuture"
4+
5+
# set title for current window
6+
echo -e "\033]0;codebang\007"
7+
8+
gnome-terminal --tab --title="future-server" \
9+
-- bash -c "cd $IFUTURE_SERVER_WORKSPACE;\
10+
python3 manage.py runserver 9092;\
11+
exec bash;"
12+
13+
cd $CODEBANG_WORKSPACE
14+
sudo npm run serve

test/code_manager/__init__.robot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*** Settings ***
2+
Documentation the code manager test suite
3+
Metadata Version 0.1
4+
Library SeleniumLibrary
5+
Resource ../common.robot
6+
Suite Setup Open Codebang To Home Page
7+
Suite Teardown Close Browser

test/code_manager/course_action.robot

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
*** Settings ***
2+
Documentation the common keywords for login defined here
3+
Resource ../common.robot
4+
5+
*** Variables ***
6+
${Add Course Button} xpath: //div/button[@title="新增课程"]
7+
${Confirm To Add Course Button} xpath: //div[@class="el-message-box"]/descendant::button[contains(./span/text(), "确定")]
8+
${Delete Course Button} xpath: //div[@class="cb-navbar"]/descendant::button[@title="删除当前课程和相关的课程文件"]
9+
${Rename Course Button} xpath: //div[@class="cb-navbar"]/descendant::button[@title="修改课程标题"]
10+
${Confirm To Delete Course Button} xpath: //div[@class="el-message-box"]/descendant::button[contains(span, "确定")]
11+
${Confirm To Rename Course Button} xpath: //div[@class="el-message-box"]/descendant::button[contains(span, "确定")]
12+
13+
${Course Input} xpath: //div[@class="el-message-box"]/descendant::div[@class="el-input"]/input
14+
${Select Course Input} xpath: //div[@class="cb-card"]/descendant::input[@class="el-input__inner"]
15+
16+
${Can Not Add Course Alert} xpath: //div[@role="alert"]/descendant::p[contains(text(), "未登陆用户不能创建课程")]
17+
18+
${Default Course Name} glibc
19+
20+
21+
*** Keywords ***
22+
Click Add Course Button
23+
Click Button ${Add Course Button}
24+
25+
Input Course Name
26+
[Arguments] ${Course Name}
27+
Input Text ${Course Input} ${Course Name}
28+
29+
Input New Course Name
30+
[Arguments] ${Course Name}
31+
Input Text ${Course Input} ${Course Name}
32+
33+
Confirm To Add Course
34+
Click Button ${Confirm To Add Course Button}
35+
36+
Current Course Should Be
37+
[Arguments] ${Course Name}
38+
Sleep 0.2s
39+
Element Attribute Value Should Be ${Select Course Input} value ${Course Name}
40+
41+
Verify Course Can Not Be Added
42+
Wait Until Element Is Visible ${Can Not Add Course Alert} 0.5s
43+
44+
Verify Course Can Not Be Renamed
45+
Element Should Be Disabled ${Rename Course Button}
46+
47+
Verify Course Can Not Be Deleted
48+
Element Should Be Disabled ${Delete Course Button}
49+
50+
Click Button To Delete Course
51+
Click Button ${Delete Course Button}
52+
53+
Click Button To Rename Course
54+
Click Button ${Rename Course Button}
55+
56+
Confirm To Delete Course
57+
Click Button ${Confirm To Delete Course Button}
58+
59+
Confirm To Rename Course
60+
Click Button ${Confirm To Rename Course Button}
61+
62+
Course Should Be Deleted
63+
[Arguments] ${Course Name}
64+
Click Element ${Select Course Input}
65+
Page Should Not Contain Element xpath: //div[@class="el-scrollbar"]/descendant::li[span="${Course Name}"]
66+
Click Element ${Select Course Input}
67+
68+
# 会使页面停在课程列表处
69+
Course Should Exist
70+
[Arguments] ${Course Name}
71+
Click Element ${Select Course Input}
72+
${Course Li} = Get WebElement xpath: //div[@class="el-scrollbar"]/descendant::li[span="${Course Name}"]
73+
Wait Until Page Contains Element ${Course Li} 1s
74+
[Return] ${Course Li}
75+
76+
Course Should Not Exist
77+
[Arguments] ${Course Name}
78+
Click Element ${Select Course Input}
79+
80+
Select Course
81+
[Arguments] ${Course Name}
82+
${Course Element} = Course Should Exist ${Course Name}
83+
Sleep 0.5s
84+
Click Element ${Course Element}
85+
Current Course Should Be ${Course Name}
86+
87+
Add Course
88+
[Arguments] ${Course Name}
89+
Click Button ${Add Course Button}
90+
Input Text ${Course Input} ${Course Name}
91+
Click Button ${Confirm To Add Course Button}
92+
Current Course Should Be ${Course Name}
93+
94+
Delete Course
95+
[Arguments] ${Course Name}
96+
Select Course ${Course Name}
97+
Click Button ${Delete Course Button}
98+
Click Button ${Confirm To Delete Course Button}
99+
Sleep 0.5s
100+
Click Element ${Select Course Input}
101+
Page Should Not Contain Element xpath: //div[@class="el-scrollbar"]/descendant::li[span="${Course Name}"]
102+
Click Element ${Select Course Input}
103+
104+
Add Default Course
105+
Add Course ${Default Course Name}
106+
107+
Delete Default Course
108+
Delete Course ${Default Course Name}

test/code_manager/course_case.robot

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
*** Settings ***
2+
Documentation the test cases for course
3+
Resource course_action.robot
4+
Resource login_action.robot
5+
Test Setup Login devecor t
6+
Test Teardown Logout
7+
8+
*** Variables ***
9+
${Course Name} glibc
10+
${New Course Name} glibc-new
11+
${Another Course Name} linux-core
12+
13+
14+
*** Test Cases ***
15+
Add Course After Login
16+
[Tags] main normal
17+
Click Add Course Button
18+
Input Course Name ${Course Name}
19+
Confirm To Add Course
20+
Current Course Should Be ${Course Name}
21+
[Teardown] Run Keywords
22+
... Delete Course ${Course Name} AND
23+
... Logout
24+
25+
Add Course Before Login
26+
[Tags] abnormal
27+
[Setup]
28+
Click Add Course Button
29+
Verify Course Can Not Be Added
30+
[Teardown]
31+
32+
Delete Course After Login
33+
[Tags] main normal
34+
Add Course ${Course Name}
35+
Select Course ${Course Name}
36+
Click Button To Delete Course
37+
Confirm To Delete Course
38+
Wait Until Animation Is Finished
39+
Course Should Be Deleted ${Course Name}
40+
41+
Rename Course After Login
42+
[Tags] main normal
43+
Add Course ${Course Name}
44+
Select Course ${Course Name}
45+
Click Button To Rename Course
46+
Input New Course Name ${New Course Name}
47+
Confirm To Rename Course
48+
Current Course Should Be ${New Course Name}
49+
Delete Course ${New Course Name}
50+
51+
Course Renaming Or Deletion Before Login
52+
[Tags] abnormal
53+
[Setup]
54+
Verify Course Can Not Be Deleted
55+
Verify Course Can Not Be Renamed
56+
[Teardown]
57+
58+
Switch Another Course After Login
59+
[Tags] normal fail
60+
Add Course ${Course Name}
61+
Add Course ${Another Course Name}
62+
Select Course ${Course Name}
63+
Delete Course ${Course Name}
64+
Delete Course ${Another Course Name}

test/code_manager/login_action.robot

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
*** Settings ***
2+
Documentation the common keywords for login defined here
3+
Resource ../common.robot
4+
5+
6+
*** Variables ***
7+
${Confirm To Login Button} xpath: //div/button[span="登陆"]
8+
${Me Dropdown Button} xpath: //div[@class="el-dropdown"]/button
9+
${Login Button} xpath: //ul/li[contains(text(), "登陆")]
10+
${Logout Button} xpath: //ul/li[contains(text(), "注销")]
11+
${Login Dialog Close Button} xpath: //div[@class="el-dialog__header"]/descendant::button[@aria-label="Close"]
12+
13+
${Login Dialog} xpath: //div[@class="el-dialog__wrapper" and contains(./descendant::label/text(), "账户")]
14+
15+
${User Name Input} xpath: //input[@placeholder="用户名/邮箱/手机号"]
16+
${User Password Input} xpath: //div/input[@type="password"]
17+
18+
${Default User Name} devecor
19+
${Default User Password} t
20+
21+
22+
*** Keywords ***
23+
Open Login Dialog
24+
Click Button ${Me Dropdown Button}
25+
Wait Until Element Is Visible ${Login Button} 0.5s
26+
Click Element ${Login Button}
27+
Wait Until Element Is Visible ${Login Dialog} 0.5s
28+
29+
Input User Name
30+
[Arguments] ${User Name}
31+
Input Text ${User Name Input} ${User Name}
32+
33+
Input User Password
34+
[Arguments] ${User Password}
35+
Input Password ${User Password Input} ${User Password}
36+
37+
Confirm To Login
38+
Click Button ${Confirm To Login Button}
39+
40+
Login Should Succeed
41+
[Arguments] ${User Name}=${Empty}
42+
${IsLogin} = Is Login ${User Name}
43+
Run Keyword If not ${IsLogin} Fail "Login should succeed, but it didn't"
44+
45+
Login Should Fail
46+
[Arguments] ${User Name}=${Empty}
47+
[Documentation] Verifies that the ${User Name} login failed.
48+
... ${Login Dialog} should be existing, or it will raise a fail.
49+
Click Element ${Login Dialog Close Button}
50+
Wait Until Element Is Not Visible ${Login Dialog Close Button} 0.5s
51+
${IsLogin} = Is Login ${User Name}
52+
Run Keyword If ${IsLogin} Fail "Login should fail, but it didn't"
53+
54+
Is Login
55+
[Arguments] ${User Name}=${Empty}
56+
Wait Until Element Is Visible ${Me Dropdown Button} 0.5s
57+
Click Button ${Me Dropdown Button}
58+
Sleep 0.3s
59+
${Element Text} = Get Text ${Login Button}
60+
${Return Value} = Set Variable ${False}
61+
${Return Value} = Run Keyword If "登陆为${Space}${User Name}" in "${Element Text}" Set Variable ${True}
62+
Click Button ${Me Dropdown Button}
63+
[Return] ${Return Value}
64+
65+
Login
66+
[Arguments] ${User Name} ${Password}
67+
Open Login Dialog
68+
Input User Name ${User Name}
69+
Input User Password ${Password}
70+
Confirm To Login
71+
Login Should Succeed
72+
73+
Logout
74+
${Is Login} = Is Login
75+
Return From Keyword If not ${Is Login} ${None}
76+
Click Button ${Me Dropdown Button}
77+
Wait Until Element Is Visible ${Logout Button} 0.5s
78+
Click Element ${Logout Button}
79+
Wait Until Element Is Not Visible ${Logout Button} 0.5s
80+
${Is Login} = Is Login
81+
Run Keyword If ${Is Login} Fail "Logout failed"
82+
83+
Login With Default User
84+
Login ${Default User Name} ${Default User Password}

test/code_manager/login_case.robot

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
*** Settings ***
2+
Documentation the test cases for login
3+
Resource login_action.robot
4+
Test Teardown Logout
5+
6+
7+
*** Variables ***
8+
${Valid User Name} devecor
9+
${Valid Password} t
10+
${Invalid User Name} wrong name
11+
${Invalid User Password} wrong password
12+
13+
14+
*** Test Cases ***
15+
Login With Valid User
16+
[Tags] main normal
17+
Open Login Dialog
18+
Input User Name ${Valid User Name}
19+
Input User Password ${Valid Password}
20+
Confirm To Login
21+
Login Should Succeed
22+
23+
Login With Invalid Username
24+
[Tags] abnormal
25+
Open Login Dialog
26+
Input User Name ${Invalid User Name}
27+
Input User Password ${Valid Password}
28+
Confirm To Login
29+
Login Should Fail
30+
31+
Login With Invalid Password
32+
[Tags] abnormal
33+
Open Login Dialog
34+
Input User Name ${Valid User Name}
35+
Input User Password ${Invalid User Password}
36+
Confirm To Login
37+
Login Should Fail
38+
39+
Login With Invalid Username And Password
40+
[Tags] abnormal
41+
Open Login Dialog
42+
Input User Name ${Invalid User Name}
43+
Input User Password ${Invalid User Password}
44+
Confirm To Login
45+
Login Should Fail

0 commit comments

Comments
 (0)