Skip to content

Commit 8a4e6d1

Browse files
add .env file
1 parent 1b943ed commit 8a4e6d1

File tree

7 files changed

+29
-34
lines changed

7 files changed

+29
-34
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ Note: Don't forget to run the bat file inside an environment with all requiremen
6767
- BDD test development make tests more readable;
6868
- To run the same test with different data, scenario outline is the best option;
6969

70+
The .env file is committed because this project is only to demonstration purposes.
71+
In real projects the .env file, containing critical info, must be add to .gitignore
72+
7073
Hope you enjoyed!
7174

7275

credentials.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
eve.holt@reqres.in=QpwL5tke4Pnpja7X4
2+
michael.lawson@reqres.in=QpwL5tke4Pnpja7X7
3+
lindsay.ferguson@reqres.in=QpwL5tke4Pnpja7X8

requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
requests==2.28.0
2-
selenium==4.1.0
3-
pytest==6.2.4
4-
pytest-bdd==5.0.0
5-
pytest-html==3.1.1
6-
pytest-xdist==2.5.0
1+
requests>=2.28.0
2+
selenium>=4.1.0
3+
pytest>=6.2.4
4+
pytest-bdd>=5.0.0
5+
pytest-html>=3.1.1
6+
pytest-xdist>=2.5.0

tests/features/registration.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ Feature: Registration
55
Given email and password are definied as <email> and <password>
66
When registration is executed
77
Then registration is completed
8-
And the correct <token> is returned
8+
And the correct token is returned
99

1010
Examples:
11-
| email | password | token |
12-
| eve.holt@reqres.in | xpto | QpwL5tke4Pnpja7X4 |
13-
| michael.lawson@reqres.in | xpto | QpwL5tke4Pnpja7X7 |
14-
| lindsay.ferguson@reqres.in | xpto | QpwL5tke4Pnpja7X8 |
11+
| email | password |
12+
| eve.holt@reqres.in | xpto |
13+
| michael.lawson@reqres.in | xpto |
14+
| lindsay.ferguson@reqres.in | xpto |
1515

1616

1717
Scenario Outline: Unsuccessful Registration

tests/pages/todo_list_page.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,15 @@ def mark_task_as_completed(self, task_name):
5151
locator = (By.XPATH, f'//li[text()="{task_name}"]')
5252
self.click_element(locator)
5353

54-
# take screenshot
55-
#self.browser.save_screenshot(self.path + task + '_task_marked.png')
56-
57-
# validate task was marked
58-
#assert self.validate_if_task_marked(task_name) is True, f"Task '{task_name}' not marked"
5954

6055
def unmark_task_as_completed(self, task_name):
6156

6257
locator = (By.XPATH, f'//li[text()="{task_name}" and @class="completed"]')
6358
#COLOCAR TRATAMENTO DE ERRO AQUI
6459
self.click_element(locator)
6560

66-
# take screenshot
67-
#self.browser.save_screenshot(self.path + task + '_task_unmarked.png')
68-
69-
# validate task was unmarked
70-
#assert self.validate_if_task_marked(task_name) is False, f"Task '{task_name}' still marked"
7161

7262
def delete_task(self, task_name):
7363

7464
locator = (By.XPATH, f'//li[text()="{task_name}"]/span')
75-
"COLOCAR TRATAMENTO DE ERRO AQUI"
7665
self.click_element(locator)
77-
78-
# take screenshot
79-
#self.browser.save_screenshot(self.path + task + '_task_deleted.png')
80-
81-
# validate task was deleted
82-
#assert self.validate_if_task_exist(task_name) is False, f"Task '{task_name}' not deleted"

tests/step_defs/test_registration_steps.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import pytest
22
from pytest_bdd import scenarios, given, when, then, parsers
33
import requests
4-
from utilities.settings import HOST, REGISTRATION_ENDPOINT
4+
from utilities.settings import HOST, REGISTRATION_ENDPOINT, CREDENTIALS_FILE
5+
from dotenv import dotenv_values
56

67

78
scenarios('../features/registration.feature')
@@ -41,10 +42,14 @@ def assert_response_code(registration, status):
4142
pytest.fail(f"Status '{status}' not valid")
4243

4344

44-
@then(parsers.cfparse("the correct {token} is returned"))
45-
def returned_token(registration, token):
46-
assert registration.json()["token"] == token, f"Token returned isn't the expected: {token}"
47-
print("Token: " + registration.json()["token"])
45+
@then(parsers.cfparse("the correct token is returned"))
46+
def returned_token(registration, payload):
47+
48+
tokens_dict = dotenv_values(CREDENTIALS_FILE)
49+
email = payload["email"]
50+
expected_token = tokens_dict[email]
51+
token = registration.json()["token"]
52+
assert token == expected_token, f"Token returned {token} isn't the expected"
4853

4954

5055
@then(parsers.cfparse("an {error_message} is returned"))

utilities/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
REGISTRATION_ENDPOINT = 'api/register'
88
USER_LIST_ENDPOINT = 'api/users'
99
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
10-
SCREENSHOT_PATH=f'{PROJECT_DIR}//reports//evidences//'
10+
SCREENSHOT_PATH=f'{PROJECT_DIR}/reports/evidences/'
11+
CREDENTIALS_FILE = f'{PROJECT_DIR}/credentials.env'
1112

1213
os.makedirs(SCREENSHOT_PATH, exist_ok=True)
1314

0 commit comments

Comments
 (0)