Skip to content

Commit b2e28b3

Browse files
Merge pull request #2 from lucas-scandido/api-tests
[API] Create API automated tests for Users
2 parents bb20422 + fc3743d commit b2e28b3

File tree

17 files changed

+429
-46
lines changed

17 files changed

+429
-46
lines changed

README.md

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ cd challenge-robot-ambev
2424
- To facilitate installation, simply run the command `pip install -r requirements.txt`, which will install all libraries at once.
2525

2626
# Documentations
27-
- **Documentation of the Application ServeRest:**
27+
- **ServeRest Documentation:**
2828
1. [API ServeRest](https://serverest.dev/)
2929
2. [GitHub ServeRest](https://github.com/ServeRest/ServeRest)
3030
- **Robot Documentation:**
@@ -36,30 +36,59 @@ The project structure was developed based on documentation: [Robot Framework - P
3636

3737
- **Folder Structure:**
3838
```
39-
├── helpers/ # Helpers needed to run the tests, including fixtures and locators
40-
└── fixtures/ # Static data files used during test execution
41-
└── signup/ # Signup Fixtures
42-
└── alerts.json # JSON file that stores all error messages from the user registration
43-
└── locators/ # Locators used to interact with page elements
44-
└── locators.py # Python file containing the mapped locators
45-
├── resources/ # Reusable keywords
46-
└── common.resource # Common Keywords
47-
└── signup.resource # Signup Keywords
48-
├── tests/ # Test Suites
49-
└── e2e/ # End-to-end Test Suite
50-
└── signup/ # Signup Suite
51-
└── invalid_login.robot # Test Suite for Invalid Signup
52-
└── login.robot # Test Suite for Valid Signup
53-
├── README.md # Project documentation
54-
├── .gitignore # Files and folders should be ignored by Git
55-
├── requirements.txt # List of dependencies needed to run the project
39+
├── helpers/ # Helpers needed to run the tests, including fixtures and locators
40+
└── fixtures/ # Static data files used during test execution
41+
└── signup/ # Signup Fixtures
42+
└── alerts.json # JSON file that stores all error messages from the user registration
43+
└── users/ # Users Fixtures
44+
└── response.json # JSON file that stores all response messages returned from the user API
45+
└── locators/ # Locators used to interact with page elements
46+
└── locators.py # Python file containing the mapped locators
47+
├── resources/ # Reusable keywords
48+
└── api/ # API Keywords
49+
└── users/ # API Users Folder
50+
└── users.resource # API Users Keywords
51+
└── api_common.resource # Common API Keywords
52+
└── e2e/ # E2E Keywords
53+
└── signup/ # Signup Folder
54+
└── signup.resource # Signup Keywords
55+
└── e2e_common.resource # Common E2E Keywords
56+
├── tests/ # Test Suites
57+
└── api/ # API Test Suite
58+
└── users/ # API Users Suite
59+
└── delete/ # API Users - DELETE Suite
60+
└── delete_invalid_users.robot # Test Suite for Delete User With Invalid Data
61+
└── delete_users.robot # Test Suite for Delete Users
62+
└── get/ # API Users - GET Suite
63+
└── get_invalid_users.robot # Test Suite for Search User With Invalid Data
64+
└── get_users.robot # Test Suite for Search Users
65+
└── post/ # API Users - POST Suite
66+
└── post_invalid_users.robot # Test Suite for Create User With Invalid Data
67+
└── post_users.robot # Test Suite for Create Users
68+
└── put/ # API Users - PUT Suite
69+
└── put_invalid_users.robot # Test Suite for Update User With Invalid Data
70+
└── put_users.robot # Test Suite for Update User
71+
└── e2e/ # End-to-end Test Suite
72+
└── signup/ # Signup Suite
73+
└── invalid_login.robot # Test Suite for Invalid Signup
74+
└── login.robot # Test Suite for Valid Signup
75+
├── .gitignore # Files and folders should be ignored by Git
76+
├── README.md # Project documentation
77+
├── requirements.txt # List of dependencies needed to run the project
5678
```
5779

5880
# Test Execution Scripts
5981

60-
- **Running E2E Tests:**
82+
- **Run E2E Tests:**
6183
```
62-
robot -d ./logs tests/e2e/ # Running all the E2E tests
63-
robot -d ./logs tests/e2e/<folder> # Running a specific E2E test folder
64-
robot -d ./logs tests/e2e/<folder>/<file>.robot # Running a specific E2E test file
84+
robot -d ./logs tests/e2e/ # Run all the E2E tests
85+
robot -d ./logs tests/e2e/<folder> # Run all the tests of a specific E2E folder
86+
robot -d ./logs tests/e2e/<folder>/<file>.robot # Run a specific E2E test file
87+
```
88+
89+
- **Run API Tests:**
90+
```
91+
robot -d ./logs tests/api/ # Run all the API tests
92+
robot -d ./logs tests/api/<folder> # Run all the tests of a specific API folder
93+
robot -d ./logs tests/api/<folder>/<folder>/<file>.robot # Run a specific API test file
6594
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"success": {
3+
"successRegistration": "Cadastro realizado com sucesso",
4+
"successUpdate": "Registro alterado com sucesso",
5+
"successDelete": "Registro excluído com sucesso"
6+
},
7+
"errors": {
8+
"emptyName": "nome não pode ficar em branco",
9+
"invalidName": "nome deve ser uma string",
10+
"emptyEmail": "email não pode ficar em branco",
11+
"invalidEmail": "email deve ser um email válido",
12+
"emailShouldBeString": "email deve ser uma string",
13+
"duplicatedEmail": "Este email já está sendo usado",
14+
"emptyPassword": "password não pode ficar em branco",
15+
"invalidPassword": "password deve ser uma string",
16+
"invalidAdmin": "administrador deve ser 'true' ou 'false'",
17+
"noRegistration": "Nenhum registro excluído"
18+
}
19+
}

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
robotframework==7.2
22
robotframework-faker==5.0.0
33
robotframework-jsonlibrary==0.5
4+
robotframework-requests==0.9.7
45
robotframework-seleniumlibrary==6.7.0

resources/api/api_common.resource

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
*** Settings ***
2+
Documentation This file contains API common variables and keywords that are
3+
... used across all the API test cases.
4+
5+
Library RequestsLibrary
6+
7+
Resource ../../resources/e2e/e2e_common.resource
8+
Resource ../../resources/api/users/users.resource
9+
10+
*** Variables ***
11+
${API_URL} https://serverest.dev
12+
${INVALID_EMAIL} lucascandidoqa.com.br
13+
${INVALID_DATA} ${{12345}}
14+
15+
*** Keywords ***
16+
Start Api Session
17+
${headers} Create Dictionary
18+
... accept=application/json
19+
... Content-Type=application/json
20+
Create Session alias=ServeRest
21+
... url=${API_URL} verify=True
22+
... headers=${headers}
23+
24+
Close Api Session
25+
Delete All Sessions
26+
27+
Send POST Request
28+
[Arguments] ${url} ${body} ${status_code}
29+
${response} POST On Session
30+
... alias=ServeRest
31+
... url=${url}
32+
... json=${body}
33+
... expected_status=${status_code}
34+
Set Global Variable ${POST_RESPONSE} ${response.json()}
35+
36+
Send GET Request
37+
[Arguments] ${status_code} ${url} ${id}=${None} ${params}=${None}
38+
${url} Set Variable If '${id}' != 'None' ${url}/${id} ${url}
39+
${response} GET On Session
40+
... alias=ServeRest
41+
... url=${url}
42+
... params=${params}
43+
... expected_status=${status_code}
44+
Set Global Variable ${GET_RESPONSE} ${response.json()}
45+
RETURN ${response}
46+
47+
Send PUT Request
48+
[Arguments] ${url} ${body} ${status_code}
49+
${response} PUT On Session
50+
... alias=ServeRest
51+
... url=${url}
52+
... json=${body}
53+
... expected_status=${status_code}
54+
Set Global Variable ${PUT_RESPONSE} ${response.json()}
55+
56+
Send DELETE Request
57+
[Arguments] ${url} ${status_code}
58+
${response} DELETE On Session
59+
... alias=ServeRest
60+
... url=${url}
61+
... expected_status=${status_code}
62+
Set Global Variable ${DELETE_RESPONSE} ${response.json()}

resources/api/users/users.resource

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
*** Settings ***
2+
Library RequestsLibrary
3+
Library Collections
4+
5+
Resource ../../../resources/api/api_common.resource
6+
7+
*** Variables ***
8+
${USERS} /usuarios
9+
10+
*** Keywords ***
11+
Create User
12+
Generate User Data true
13+
Send POST Request ${USERS} ${DATA} 201
14+
15+
Update User Data
16+
[Arguments] ${name} ${email} ${password} ${is_admin}
17+
18+
${body} Create Dictionary
19+
... nome=${name}
20+
... email=${email}
21+
... password=${password}
22+
... administrador=${is_admin}
23+
RETURN ${body}
24+
25+
Delete Users
26+
Send DELETE Request ${USERS}/${POST_RESPONSE}[_id] 200
27+
28+
Response Should Contain Message
29+
[Arguments] ${response_type} ${field} ${expected_message}
30+
Dictionary Should Contain Item ${response_type} ${field} ${expected_message}
31+
Should Not Be Empty ${expected_message}
32+
33+
Dictionary Should Contain
34+
[Arguments] ${response} @{expected_keys}
35+
FOR ${key} IN @{expected_keys}
36+
Dictionary Should Contain Key ${response} ${key}
37+
${value} Get From Dictionary ${response} ${key}
38+
Should Not Be Empty ${value} Field ${key} should not be empty
39+
END
40+
41+
Dictionary List Should Contain
42+
[Arguments] ${response} @{expected_keys}
43+
Dictionary Should Contain Key ${response} quantidade
44+
${user_count} Get Length ${response}[usuarios]
45+
Should Be Equal As Integers ${user_count} ${response}[quantidade]
46+
FOR ${user} IN @{response}[usuarios]
47+
Dictionary Should Contain ${user} @{expected_keys}
48+
END
Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
*** Settings ***
2-
Documentation This file contains common variables and keywords that are used across all test cases.
2+
Documentation This file contains E2E common variables and keywords that are
3+
... used across all the E2E test cases.
34
45
Library SeleniumLibrary
56
Library FakerLibrary
67
Library JSONLibrary
78

8-
Resource ../resources/signup.resource
9+
Resource ../../resources/e2e/signup/signup.resource
910

10-
Variables ../helpers/locators/locators.py
11+
Variables ../../helpers/locators/locators.py
1112

1213
*** Variables ***
1314
${BASE_URL} https://front.serverest.dev
15+
${USER_NAME} Lucas Candido
16+
${USER_EMAIL} beltrano@qa.com.br
1417
${USER_PASSWORD} password2025
1518

1619
*** Keywords ***
@@ -25,19 +28,28 @@ Navigate To
2528
Go To ${BASE_URL}/${endpoint}
2629
Title Should Be Front - ServeRest
2730

28-
Generate Dynamic Data
29-
${random_name} FakerLibrary.Name
30-
${format_name} Evaluate '${random_name}'.lower().replace(' ', '')
31-
${random_number} Evaluate random.randint(1000, 9999) random
32-
${random_email} Set Variable ${format_name}${random_number}@teste.com
33-
34-
${dynamic_data} Create Dictionary name=${random_name} email=${random_email}
35-
RETURN ${dynamic_data}
31+
Generate User Data
32+
[Arguments] ${is_admin}=${None}
33+
${name} FakerLibrary.Name
34+
${format_name} Evaluate '${name}'.lower().replace(' ', '')
35+
${number} Evaluate random.randint(1000, 9999) random
36+
${random_email} Set Variable ${format_name}${number}@automation.com
37+
${password} FakerLibrary.Password
38+
${administrator} Set Variable ${is_admin}
39+
40+
${data} Create Dictionary
41+
... nome=${name}
42+
... email=${random_email}
43+
... password=${password}
44+
... administrador=${administrator}
45+
Set Global Variable ${DATA} ${data}
46+
RETURN ${DATA}
3647

3748
Get Fixture
3849
[Arguments] ${path} ${fixture_name} ${field}
3950
${data} Load JSON From File
40-
... ${EXECDIR}/helpers/fixtures/${path}/${fixture_name}.json encoding=UTF-8
51+
... ${EXECDIR}/helpers/fixtures/${path}/${fixture_name}.json
52+
... encoding=UTF-8
4153
RETURN ${data}[${field}]
4254

4355
Check Element State
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Library SeleniumLibrary
33
Library String
44

5-
Resource ../resources/common.resource
5+
Resource ../../../resources/e2e/e2e_common.resource
66

77
*** Keywords ***
88
Input Name
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*** Settings ***
2+
Documentation Test suite to verify a deletion of users in the API with invalid
3+
... data. Ensuring that the application returns appropriate error
4+
... messages when attempting to delete a user with invalid ID.
5+
6+
Resource ../../../../resources/api/api_common.resource
7+
8+
Suite Setup Start Api Session
9+
Test Setup Create User
10+
Suite Teardown Close Api Session
11+
Test Template Delete User With Invalid Data
12+
13+
*** Test Cases *** ID
14+
Invalid Id ${INVALID_DATA}
15+
16+
*** Keywords ***
17+
Delete User With Invalid Data
18+
[Arguments] ${id}
19+
${messages} Get fixture users response errors
20+
Send DELETE Request ${USERS}/${id} 200
21+
Response Should Contain Message ${DELETE_RESPONSE} message ${messages}[noRegistration]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*** Settings ***
2+
Documentation Test suite to verify a deletion of users in the API with valid
3+
... data. Ensuring that the application returns appropriate success
4+
... messages when attempting to delete a user with valid ID.
5+
6+
Resource ../../../../resources/api/api_common.resource
7+
8+
Suite Setup Start Api Session
9+
Test Setup Create User
10+
Suite Teardown Close Api Session
11+
12+
*** Test Cases ***
13+
Delete User
14+
${messages} Get fixture users response success
15+
Send DELETE Request /${USERS}/${POST_RESPONSE}[_id] 200
16+
Response Should Contain Message ${DELETE_RESPONSE} message ${messages}[successDelete]
17+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
*** Settings ***
2+
Documentation Test suite to verify a search of users in the API with invalid
3+
... data. Ensuring that the application returns appropriate error
4+
... messages when attempting to search a user with empty and invalid
5+
... parameters.
6+
7+
Resource ../../../../resources/api/api_common.resource
8+
9+
Suite Setup Start Api Session
10+
Test Setup Create User
11+
Test Teardown Delete Users
12+
Suite Teardown Close Api Session
13+
Test Template Search Users With Invalid Data
14+
15+
*** Test Cases *** KEY VALUE FIELD MESSAGE
16+
Empty Email email ${EMPTY} email emailShouldBeString
17+
Invalid Email email ${INVALID_EMAIL} email invalidEmail
18+
Invalid Email As A Number email ${INVALID_DATA} email emailShouldBeString
19+
Empty Administrator administrador ${EMPTY} administrador invalidAdmin
20+
Invalid Administrator administrador yes administrador invalidAdmin
21+
Invalid Administrator As A Number administrador ${{1}} administrador invalidAdmin
22+
23+
*** Keywords ***
24+
Search Users With Invalid Data
25+
[Arguments] ${key} ${value} ${field} ${expected_message}
26+
${params} Create Dictionary ${key}=${value}
27+
${message} Get fixture users response errors
28+
Send GET Request 400 ${USERS} params=${params}
29+
Response Should Contain Message ${GET_RESPONSE} ${field} ${message}[${expected_message}]

0 commit comments

Comments
 (0)