Skip to content

Commit 099e394

Browse files
Merge pull request #1 from Jmateusribeiro/pylint-refactoring
refactoring code
2 parents 8a4e6d1 + 3c9ed77 commit 099e394

File tree

12 files changed

+556
-83
lines changed

12 files changed

+556
-83
lines changed

.github/workflows/pylint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Pylint
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.8", "3.9", "3.10"]
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@v3
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install pylint
21+
- name: Analyzing the code with pylint
22+
run: |
23+
pylint **/*.py

reports/API_And_WEB_Testing

Lines changed: 150 additions & 0 deletions
Large diffs are not rendered by default.

run_tests.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ set dir=%CD%
22
set report_dir=%CD%\reports
33
set test_dir=%CD%\tests
44

5-
set browser="Headless Chrome"
5+
set browser=Chrome
66

77
echo The test directory is %test_dir%
88

9-
python -m pytest -s -vv --gherkin-terminal-reporter %test_dir%\step_defs --html=%report_dir%\report.html -n 4 --capture sys --browser %browser%
9+
python -m pytest -s -vv --gherkin-terminal-reporter %test_dir%\step_defs --html=%report_dir%\report.html -n 4 --capture=tee-sys --Browser="%browser%" --full-trace
1010

11-
Pause
11+
pause

tests/features/add_task.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Created by Admin at 16/10/2022
21
Feature: Add task
32

43
Scenario Outline: Add New Task Successfully

tests/pages/base_page.py

Lines changed: 132 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,37 @@
55
from utilities.settings import SCREENSHOT_PATH
66
from selenium.webdriver.chrome.options import Options
77

8-
98
headless_options = Options()
109
headless_options.add_argument("--headless")
1110

12-
1311
class WebBrowser:
14-
15-
def __init__(self, browser, implicit_wait=3, screenshot_path=SCREENSHOT_PATH ):
12+
"""
13+
Class representing a web browser instance.
14+
"""
15+
16+
def __init__(self, browser: str, implicit_wait: int = 3, screenshot_path: str = SCREENSHOT_PATH):
17+
"""
18+
Initialize the WebBrowser instance.
19+
20+
Args:
21+
browser (str): The browser to use.
22+
implicit_wait (int): The implicit wait time.
23+
screenshot_path (str): The path to save screenshots.
24+
"""
1625
self.driver = self.initialize_browser(browser)
1726
self.implicit_wait = implicit_wait
1827
self.screenshot_path = screenshot_path
1928

20-
def initialize_browser(self, browser):
21-
# Initialize the WebDriver instance
29+
def initialize_browser(self, browser: str) -> webdriver:
30+
"""
31+
Initialize the WebDriver instance.
32+
33+
Args:
34+
browser (str): The browser to initialize.
35+
36+
Returns:
37+
webdriver: The WebDriver instance.
38+
"""
2239
if browser == 'Chrome':
2340
return webdriver.Chrome()
2441
elif browser == 'Edge':
@@ -32,43 +49,139 @@ def initialize_browser(self, browser):
3249
else:
3350
raise Exception(f'Browser "{browser}" is not supported')
3451

35-
def open_browser(self, url):
52+
def open_browser(self, url: str) -> None:
53+
"""
54+
Open the browser and navigate to the given URL.
55+
56+
Args:
57+
url (str): The URL to navigate to.
58+
59+
Returns:
60+
None
61+
"""
3662
self.driver.get(url)
3763
self.driver.maximize_window()
3864

39-
def close_browser(self):
65+
def close_browser(self) -> None:
66+
"""
67+
Close the browser.
68+
69+
Returns:
70+
None
71+
"""
4072
self.driver.quit()
4173

42-
def get_element(self, by_locator):
74+
def get_element(self, by_locator: tuple):
75+
"""
76+
Get the web element identified by the locator.
77+
78+
Args:
79+
by_locator (tuple): The locator strategy and value.
80+
81+
Returns:
82+
web element: The web element.
83+
"""
4384
return WebDriverWait(self.driver, self.implicit_wait).until(EC.visibility_of_element_located(by_locator))
4485

45-
def get_element_text(self, by_locator):
86+
def get_element_text(self, by_locator: tuple) -> str:
87+
"""
88+
Get the text of the web element identified by the locator.
89+
90+
Args:
91+
by_locator (tuple): The locator strategy and value.
92+
93+
Returns:
94+
str: The text of the web element.
95+
"""
4696
return self.get_element(by_locator).text
4797

48-
def type_element(self, by_locator, text):
98+
def type_element(self, by_locator: tuple, text: str) -> None:
99+
"""
100+
Type text into the web element identified by the locator.
101+
102+
Args:
103+
by_locator (tuple): The locator strategy and value.
104+
text (str): The text to type into the web element.
105+
106+
Returns:
107+
None
108+
"""
49109
self.get_element(by_locator).send_keys(text)
50110

51-
def click_element(self, by_locator):
111+
def click_element(self, by_locator: tuple) -> None:
112+
"""
113+
Click on the web element identified by the locator.
114+
115+
Args:
116+
by_locator (tuple): The locator strategy and value.
117+
118+
Returns:
119+
None
120+
"""
52121
self.get_element(by_locator).click()
53122

54-
def send_keys(self, by_locator, key):
123+
def send_keys(self, by_locator: tuple, key) -> None:
124+
"""
125+
Send keys to the web element identified by the locator.
126+
127+
Args:
128+
by_locator (tuple): The locator strategy and value.
129+
key: The keys to send.
130+
131+
Returns:
132+
None
133+
"""
55134
self.get_element(by_locator).send_keys(key)
56135

57-
def is_element_visible(self, by_locator):
136+
def is_element_visible(self, by_locator: tuple) -> bool:
137+
"""
138+
Check if the web element identified by the locator is visible.
139+
140+
Args:
141+
by_locator (tuple): The locator strategy and value.
142+
143+
Returns:
144+
bool: True if the element is visible, False otherwise.
145+
"""
58146
return self.get_element(by_locator).is_displayed()
59147

60-
def check_if_element_exists(self, by_locator):
148+
def check_if_element_exists(self, by_locator: tuple) -> bool:
149+
"""
150+
Check if the web element identified by the locator exists.
151+
152+
Args:
153+
by_locator (tuple): The locator strategy and value.
154+
155+
Returns:
156+
bool: True if the element exists, False otherwise.
157+
"""
61158
try:
62159
self.driver.find_element(*by_locator)
63160
return True
64161

65-
# NoSuchElementException thrown if not present
66162
except NoSuchElementException:
67163
return False
68164

69-
def find_elements(self, by_locator):
165+
def find_elements(self, by_locator: tuple):
166+
"""
167+
Find all web elements identified by the locator.
168+
169+
Args:
170+
by_locator (tuple): The locator strategy and value.
171+
172+
Returns:
173+
list: List of web elements.
174+
"""
70175
return self.driver.find_elements(*by_locator)
71176

72-
def take_screenshot(self, name):
73-
# take screenshot
177+
def take_screenshot(self, name: str) -> None:
178+
"""
179+
Take a screenshot and save it with the given name.
180+
181+
Args:
182+
name (str): The name to save the screenshot.
183+
184+
Returns:
185+
None
186+
"""
74187
self.driver.save_screenshot(self.screenshot_path + name + '.png')

tests/pages/todo_list_page.py

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,38 @@
33
from selenium.webdriver.common.keys import Keys
44

55
class ToDoListLocators:
6-
todo_list_url = 'http://webdriveruniversity.com/To-Do-List/index.html'
7-
title = 'WebDriver | To Do List'
8-
input_element = (By.XPATH, '//input[@placeholder="Add new todo" and not(@style="display: none;")]')
9-
tasks_list = (By.TAG_NAME, 'li')
10-
plus_icon = (By.ID, 'plus-icon')
11-
6+
todo_list_url: str = 'http://webdriveruniversity.com/To-Do-List/index.html'
7+
title: str = 'WebDriver | To Do List'
8+
input_element: tuple = (By.XPATH, '//input[@placeholder="Add new todo" and not(@style="display: none;")]')
9+
tasks_list: tuple = (By.TAG_NAME, 'li')
10+
plus_icon: tuple = (By.ID, 'plus-icon')
1211

1312
class ToDOList(WebBrowser):
13+
"""
14+
Class representing the ToDoList page.
15+
"""
1416

15-
def open_page(self):
17+
def open_page(self) -> None:
18+
"""
19+
Open the ToDoList page and verify the title.
1620
21+
Returns:
22+
None
23+
"""
1724
self.open_browser(ToDoListLocators.todo_list_url)
1825
assert self.driver.title == ToDoListLocators.title
1926

20-
def validate_if_task_exist(self, task_name):
27+
def validate_if_task_exist(self, task_name: str) -> bool:
28+
"""
29+
Validate if a task exists in the tasks list.
30+
31+
Args:
32+
task_name (str): The name of the task to validate.
2133
22-
task_exist_flag = False
34+
Returns:
35+
bool: True if the task exists, False otherwise.
36+
"""
37+
task_exist_flag: bool = False
2338
tasks_list_elements = self.find_elements(ToDoListLocators.tasks_list)
2439
for task in tasks_list_elements:
2540
if task.text != task_name:
@@ -28,38 +43,72 @@ def validate_if_task_exist(self, task_name):
2843

2944
return task_exist_flag
3045

31-
def validate_if_task_marked(self, task_name):
46+
def validate_if_task_marked(self, task_name: str) -> bool:
47+
"""
48+
Validate if a task is marked as completed.
3249
50+
Args:
51+
task_name (str): The name of the task to validate.
52+
53+
Returns:
54+
bool: True if the task is marked as completed, False otherwise.
55+
"""
3356
locator = (By.XPATH, f'//li[text()="{task_name}" and @class="completed"]')
3457
return self.check_if_element_exists(locator)
3558

36-
def add_new_task(self, task_name):
59+
def add_new_task(self, task_name: str) -> None:
60+
"""
61+
Add a new task to the ToDoList.
62+
63+
Args:
64+
task_name (str): The name of the task to add.
3765
38-
# validate in input field is visible
66+
Returns:
67+
None
68+
"""
3969
if self.check_if_element_exists(ToDoListLocators.input_element) is False:
4070
self.click_element(ToDoListLocators.plus_icon)
4171

4272
self.type_element(ToDoListLocators.input_element, task_name)
4373
self.send_keys(ToDoListLocators.input_element, Keys.ENTER)
4474

45-
#take screenshot
4675
self.take_screenshot(f'{task_name}_task_added')
4776

77+
def mark_task_as_completed(self, task_name: str) -> None:
78+
"""
79+
Mark a task as completed.
4880
49-
def mark_task_as_completed(self, task_name):
81+
Args:
82+
task_name (str): The name of the task to mark as completed.
5083
84+
Returns:
85+
None
86+
"""
5187
locator = (By.XPATH, f'//li[text()="{task_name}"]')
5288
self.click_element(locator)
5389

90+
def unmark_task_as_completed(self, task_name: str) -> None:
91+
"""
92+
Unmark a completed task.
5493
55-
def unmark_task_as_completed(self, task_name):
94+
Args:
95+
task_name (str): The name of the task to unmark.
5696
97+
Returns:
98+
None
99+
"""
57100
locator = (By.XPATH, f'//li[text()="{task_name}" and @class="completed"]')
58-
#COLOCAR TRATAMENTO DE ERRO AQUI
59101
self.click_element(locator)
60102

103+
def delete_task(self, task_name: str) -> None:
104+
"""
105+
Delete a task from the ToDoList.
61106
62-
def delete_task(self, task_name):
107+
Args:
108+
task_name (str): The name of the task to delete.
63109
110+
Returns:
111+
None
112+
"""
64113
locator = (By.XPATH, f'//li[text()="{task_name}"]/span')
65114
self.click_element(locator)

0 commit comments

Comments
 (0)