Skip to content

Commit a32e07b

Browse files
author
Devecor
committed
Add course test cases
1 parent 15dde4a commit a32e07b

9 files changed

Lines changed: 267 additions & 32 deletions

File tree

test/README.md

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,52 @@
1-
# Codebang Test Cases
2-
Here are robot test cases to verify the main functions of `codebang`, each test case has one `.robot` file. These test cases also could be as a guide for end users to understand how to use codebang.
1+
# Codebang Tests
2+
This folder contains the various test runners for **codebang**.
33

4-
## Let's start!
5-
In order to run them automatically, first install RobotFramework and SeleniumLibrary by `pip`
4+
## Requirements
65

6+
### 1. Install the dependencis
7+
Before running the test, install the dependencies:
78
```sh
89
python3 -m pip install robotframework robotframework-SeleniumLibrary
910
```
1011

11-
then, please complete the following preparations step by step
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
1214

13-
### 1. install webDirvers
14-
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`. here are two fast links about chrome and firefox drivers in `npm.taobao.org` for chinese users.
15+
* [ChromeDriver for google Chrome](https://npm.taobao.org/mirrors/chromedriver/)
1516

16-
[chrome webdriver](https://npm.taobao.org/mirrors/chromedriver/)
17+
* [Geckodriver for firefox](https://npm.taobao.org/mirrors/geckodriver/)
1718

18-
[firefox geckodriver](https://npm.taobao.org/mirrors/geckodriver/)
19+
### 3. Start server
1920

20-
### 2. start codebang and future-server
21-
22-
you have to start future-server at port `9092`. change directory to `future-server` in a terminal,
21+
You have to start future-server at port `9092`. Change directory to `future-server` in a terminal,
2322
then
2423
```sh
2524
python3 manage.py runserver 9092
2625
```
2726

28-
change directory to `codebang` in a terminal and start codebang at any port you want(default: `8080`), then
27+
Change directory to `codebang` in a terminal and start codebang at any port you expected(default: `8080`), then
2928
```sh
3029
npm run serve
3130
```
3231

33-
or you may want to use a shell script named `autostart.sh` for starting codebang and future-server automaticaly(just for bash with gnome)
32+
You may want to use a shell script named `autostart.sh` for starting codebang and future-server automaticaly.
3433
```sh
3534
./autostart.sh
3635
```
3736

38-
### 3. run tests
39-
create a directory for testing log
37+
## Run tests
38+
Create a directory for test log files
4039
```sh
4140
mkdir test-results
4241
```
4342

44-
run any of one test suite which contains some test cases. for ecample
43+
Run any of one test suite which contains some test cases. for ecample
4544
```sh
4645
cd codebang/test
47-
robot -X -d ./test-results login
46+
robot -X -d test-results --suite login_suite code_manager_test
4847
```
4948

50-
or run the whole test suite
49+
Or run the whole test suite
5150
```sh
5251
robot -X -d test-results .
5352
```
@@ -59,8 +58,3 @@ robot -X -d test-results .
5958
* Login With Invalid Username
6059
* Login With Invalid Password
6160
* Login With Invalid Username And Password
62-
63-
## Reference
64-
65-
* [robotframework](https://robotframework.org/#examples)
66-
* [SeleniumLibrary](https://robotframework.org/SeleniumLibrary/)
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
*** Settings ***
2-
Documentation the login test suite
2+
Documentation the code manager test suite
33
Metadata Version 0.1
44
Library SeleniumLibrary
55
Resource ../common.robot
6-
Resource login_action.robot
76
Suite Setup Open Codebang To Home Page
87
Suite Teardown Close Browser
9-
Test Teardown Logout
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
*** Keywords ***
19+
Click Add Course Button
20+
Click Button ${Add Course Button}
21+
22+
Input Course Name
23+
[Arguments] ${Course Name}
24+
Input Text ${Course Input} ${Course Name}
25+
26+
Input New Course Name
27+
[Arguments] ${Course Name}
28+
Input Text ${Course Input} ${Course Name}
29+
30+
Confirm To Add Course
31+
Click Button ${Confirm To Add Course Button}
32+
33+
Current Course Should Be
34+
[Arguments] ${Course Name}
35+
Sleep 0.2s
36+
Element Attribute Value Should Be ${Select Course Input} value ${Course Name}
37+
38+
Verify Course Can Not Be Added
39+
Wait Until Element Is Visible ${Can Not Add Course Alert} 0.5s
40+
41+
Verify Course Can Not Be Renamed
42+
Element Should Be Disabled ${Rename Course Button}
43+
44+
Verify Course Can Not Be Deleted
45+
Element Should Be Disabled ${Delete Course Button}
46+
47+
Click Button To Delete Course
48+
Click Button ${Delete Course Button}
49+
50+
Click Button To Rename Course
51+
Click Button ${Rename Course Button}
52+
53+
Confirm To Delete Course
54+
Click Button ${Confirm To Delete Course Button}
55+
56+
Confirm To Rename Course
57+
Click Button ${Confirm To Rename Course Button}
58+
59+
Course Should Be Deleted
60+
[Arguments] ${Course Name}
61+
Click Element ${Select Course Input}
62+
Page Should Not Contain Element xpath: //div[@class="el-scrollbar"]/descendant::li[span="${Course Name}"]
63+
Click Element ${Select Course Input}
64+
65+
# 会使页面停在课程列表处
66+
Course Should Exist
67+
[Arguments] ${Course Name}
68+
Click Element ${Select Course Input}
69+
${Course Li} = Get WebElement xpath: //div[@class="el-scrollbar"]/descendant::li[span="${Course Name}"]
70+
Wait Until Page Contains Element ${Course Li} 1s
71+
[Return] ${Course Li}
72+
73+
Course Should Not Exist
74+
[Arguments] ${Course Name}
75+
Click Element ${Select Course Input}
76+
77+
Select Course
78+
[Arguments] ${Course Name}
79+
${Course Element} = Course Should Exist ${Course Name}
80+
Sleep 0.5s
81+
Click Element ${Course Element}
82+
Current Course Should Be ${Course Name}
83+
84+
Add Course
85+
[Arguments] ${Course Name}
86+
Click Button ${Add Course Button}
87+
Input Text ${Course Input} ${Course Name}
88+
Click Button ${Confirm To Add Course Button}
89+
Current Course Should Be ${Course Name}
90+
91+
Delete Course
92+
[Arguments] ${Course Name}
93+
Select Course ${Course Name}
94+
Click Button ${Delete Course Button}
95+
Click Button ${Confirm To Delete Course Button}
96+
Sleep 0.5s
97+
Click Element ${Select Course Input}
98+
Page Should Not Contain Element xpath: //div[@class="el-scrollbar"]/descendant::li[span="${Course Name}"]
99+
Click Element ${Select Course Input}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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] 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 Delete Course ${Course Name} AND Logout
22+
23+
Add Course Before Login
24+
[Tags] abnormal
25+
[Setup]
26+
Click Add Course Button
27+
Verify Course Can Not Be Added
28+
[Teardown]
29+
30+
Delete Course After Login
31+
[Tags] normal
32+
Add Course ${Course Name}
33+
Select Course ${Course Name}
34+
Click Button To Delete Course
35+
Confirm To Delete Course
36+
Wait Until Animation Is Finished
37+
Course Should Be Deleted ${Course Name}
38+
39+
Rename Course After Login
40+
[Tags] normal
41+
Add Course ${Course Name}
42+
Select Course ${Course Name}
43+
Click Button To Rename Course
44+
Input New Course Name ${New Course Name}
45+
Confirm To Rename Course
46+
Current Course Should Be ${New Course Name}
47+
Delete Course ${New Course Name}
48+
49+
Course Renaming Or Deletion Before Login
50+
[Tags] abnormal
51+
[Setup]
52+
Verify Course Can Not Be Deleted
53+
Verify Course Can Not Be Renamed
54+
[Teardown]
55+
56+
Switch Another Course After Login
57+
[Tags] normal fail
58+
Add Course ${Course Name}
59+
Add Course ${Another Course Name}
60+
Select Course ${Course Name}
61+
Delete Course ${Course Name}
62+
Delete Course ${Another Course Name}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ Is Login
5959
Click Button ${Me Dropdown Button}
6060
[Return] ${Return Value}
6161

62+
Login
63+
[Arguments] ${User Name} ${Password}
64+
Open Login Dialog
65+
Input User Name ${User Name}
66+
Input User Password ${Password}
67+
Confirm To Login
68+
Login Should Succeed
69+
6270
Logout
6371
${Is Login} = Is Login
6472
Return From Keyword If not ${Is Login} ${None}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*** Settings ***
22
Documentation the test cases for login
3-
Library SeleniumLibrary
43
Resource login_action.robot
4+
Test Teardown Logout
55

66

77
*** Variables ***
@@ -13,27 +13,31 @@ ${Invalid User Password} wrong password
1313

1414
*** Test Cases ***
1515
Login With Valid User
16+
[Tags] normal
1617
Open Login Dialog
1718
Input User Name ${Valid User Name}
1819
Input User Password ${Valid Password}
1920
Confirm To Login
2021
Login Should Succeed
2122

2223
Login With Invalid Username
24+
[Tags] abnormal
2325
Open Login Dialog
2426
Input User Name ${Invalid User Name}
2527
Input User Password ${Valid Password}
2628
Confirm To Login
2729
Login Should Fail
2830

2931
Login With Invalid Password
32+
[Tags] abnormal
3033
Open Login Dialog
3134
Input User Name ${Valid User Name}
3235
Input User Password ${Invalid User Password}
3336
Confirm To Login
3437
Login Should Fail
3538

3639
Login With Invalid Username And Password
40+
[Tags] abnormal
3741
Open Login Dialog
3842
Input User Name ${Invalid User Name}
3943
Input User Password ${Invalid User Password}

test/codebang_test_user_guide.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Codebang test guide
2+
3+
## Getting started
4+
This is a tutorial for developer to prefect test cases of codebang. There is a [specification](#Specification) that we must follow
5+
6+
### Prerequisites
7+
[See README](README)
8+
9+
### Specification
10+
11+
#### File encoding
12+
* utf-8
13+
14+
#### Separated format
15+
* Space: 4 in genaral or more in special, for example
16+
```Robot Framework
17+
*** Settings ***
18+
Documentation Example using the space separated format.
19+
Library OperatingSystem
20+
21+
*** Variables ***
22+
${MESSAGE} Hello, world!
23+
24+
*** Test Cases ***
25+
My Test
26+
[Documentation] Example test.
27+
Log ${MESSAGE}
28+
My Keyword ${CURDIR}
29+
30+
Another Test
31+
Should Be Equal ${MESSAGE} Hello, world!
32+
33+
*** Keywords ***
34+
My Keyword
35+
[Arguments] ${path}
36+
Directory Should Exist ${path}
37+
```
38+
39+
#### File name
40+
* File names must be all lowercase and may include underscores: `_`
41+
* No additional punctuation.
42+
* Filenames’ extension must be `.robot`.
43+
44+
For example: `login_action.robot`
45+
46+
#### Structure
47+
* a test suite of codebang with fandamental capability created from only **two** files:
48+
* Resource file: `anction.robot`
49+
* Test case file: `suite.robot`
50+
51+
Any costomized `keyword` about the current suite should be defined in Resource file `anction.robot`. All cases for the current suite within test case file `suite.robot` are expected.
52+
* A high level suite of codebang created from a directory with a initialization file. An initialization file name must always be of the format `__init__.ext`, where the extension must be one of the supported file formats (typically `__init__.robot`).The main usage for initialization files is specifying test suite related settings in global. For example
53+
```
54+
*** Settings ***
55+
Documentation the code manager test suite
56+
Metadata Version 0.1
57+
Library SeleniumLibrary
58+
Resource ../common.robot
59+
Suite Setup Open Codebang To Home Page
60+
Suite Teardown Close Browser
61+
```
62+
### Tags
63+
64+
## Reference
65+
66+
* [Robot Framework User Guide](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html)
67+
* [The home page of SeleniumLibrary](https://robotframework.org/SeleniumLibrary/)

0 commit comments

Comments
 (0)