Skip to content

Commit 972641f

Browse files
committed
bumped dependencies and changed test site
1 parent ca179df commit 972641f

File tree

12 files changed

+66
-75
lines changed

12 files changed

+66
-75
lines changed

CONTRIBUTING.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Getting started
44

55
Before you begin:
6-
- Python 3.8 is used for this project.
6+
- Python 3.11 is used for this project.
77
- For EPAM employees only: have you read the [Best Practices for Managing Secrets](https://elearn.epam.com/courses/course-v1:EPAM+5SCSS+0620/courseware/4b94c749c309409ea878fb7916be316b/ae4553f7cd524229b42f260b0ac692ed/1?activate_block_id=block-v1%3AEPAM%2B5SCSS%2B0620%2Btype%40vertical%2Bblock%40c04f1498c7d04ac4bf87b652741d90bb)?
88
- Check out the [existing issues](https://github.com/jdi-testing/jdi-python/issues).
99

@@ -19,10 +19,6 @@ When you're done making changes, open your PR and get it reviewed.
1919

2020
In order to test the project, run pytest.
2121

22-
Please don't forget to set up the environment variable `TEST_PASSWORD`. For example:
23-
24-
For Windows `set TEST_PASSWORD=<password>`
25-
2622
```bash
2723
pytest <path to the project>/tests --no-header --no-summary -q
2824
```

JDI/core/settings/jdi_settings.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
import os
2+
from pathlib import Path, PurePath
13
import logging
2-
from pathlib import Path
3-
4-
logger = logging.Logger(__name__)
54

5+
logger = logging.getLogger(__name__)
66

77
class PropertyPath:
88
def __init__(self, filename="jdi.properties"):
9-
self._filename = Path(filename)
9+
project_root = Path(__file__).parents[3]
10+
self._filename = project_root / filename
1011

1112
def get_property_file(self):
12-
logger.info("Directory to search {dir_to_search}".format(dir_to_search=self._filename))
13+
logger.info(f"Directory to search {self._filename.parent}")
1314
if self._filename.exists():
1415
return self._filename
1516
else:
16-
raise FileNotFoundError("There is not property file with name '" + self._filename + "' in your project")
17+
raise FileNotFoundError(f"There is no property file with name '{self._filename}' in your project")
1718

1819

1920
class JDISettings:
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import os
2-
1+
from selenium.webdriver.chrome.service import Service
32
from selenium.webdriver.chrome.options import Options as ChromeOptions
43
from selenium.webdriver.chrome.webdriver import WebDriver as ChromeDriver
4+
from webdriver_manager.chrome import ChromeDriverManager
55
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
6-
from selenium.webdriver.firefox.options import Options as FirefoxOptions
76
from selenium.webdriver.remote.webdriver import WebDriver as RemoteDriver
87

98
from JDI.core.settings.jdi_settings import JDISettings
109
from JDI.web.selenium.driver.driver_types import DriverTypes
11-
from JDI.web.selenium.driver.web_driver_provider import WebDriverProvider
1210

1311

1412
class SeleniumDriverFactory:
@@ -17,7 +15,6 @@ def __init__(self):
1715
self.options = None
1816
self.current_driver = None
1917
self.browser_size = None
20-
self.drivers_path = JDISettings.get_driver_path()
2118
self.capabilities = {}
2219

2320
def register_driver(self, driver_name, options, capabilities, executor):
@@ -28,24 +25,17 @@ def register_driver(self, driver_name, options, capabilities, executor):
2825
else:
2926
if driver_name == DriverTypes.chrome.name:
3027
self.current_driver = self.register_chrome_driver()
31-
if driver_name == DriverTypes.firefox.name:
32-
self.current_driver = self.register_firefox_driver()
3328
return driver_name
3429

3530
def set_driver_options_and_capabilities(self, driver_name, options, capabilities, executor):
3631
if driver_name == DriverTypes.chrome.name:
3732
self.options = ChromeOptions()
38-
# TODO: move hardcoded arguments to params
3933
self.options.add_argument("start-maximized")
4034
self.options.add_argument("disable-gpu")
41-
self.add_options(options) if options else True
42-
if not capabilities and executor is not None:
35+
if options:
36+
self.add_options(options)
37+
if not capabilities and executor is None:
4338
self.capabilities = DesiredCapabilities.CHROME
44-
if driver_name == DriverTypes.firefox.name:
45-
self.options = FirefoxOptions()
46-
self.add_options(options) if options else True
47-
if not capabilities and executor is not None:
48-
self.capabilities = DesiredCapabilities.FIREFOX
4939
if capabilities:
5040
self.capabilities = capabilities
5141

@@ -54,38 +44,28 @@ def add_options(self, options):
5444
self.options.add_argument(arg)
5545

5646
def register_chrome_driver(self):
57-
chrome_driver = WebDriverProvider.get_chrome_driver_path()
58-
os.environ["webdriver.chrome.driver"] = chrome_driver
59-
return self.__web_driver_settings(ChromeDriver(executable_path=chrome_driver,
60-
options=self.options,
61-
desired_capabilities=self.capabilities))
62-
63-
def register_firefox_driver(self):
64-
raise NotImplementedError
47+
service = Service(ChromeDriverManager().install())
48+
return self.__web_driver_settings(ChromeDriver(service=service,
49+
options=self.options))
6550

6651
def register_remote_driver(self, executor):
67-
chrome_driver = WebDriverProvider.get_chrome_driver_path()
68-
os.environ["webdriver.chrome.driver"] = chrome_driver
6952
driver = self.__web_driver_settings(RemoteDriver(command_executor=executor,
7053
options=self.options,
71-
desired_capabilities=self.capabilities,
7254
keep_alive=True))
7355
return driver
7456

7557
def __web_driver_settings(self, driver):
76-
if self.browser_size is None:
77-
driver.maximize_window()
58+
if self.browser_size:
59+
driver.set_window_size(*self.browser_size)
7860
else:
79-
driver.set_window_size(self.browser_size)
61+
driver.maximize_window()
8062
driver.implicitly_wait(JDISettings.get_current_timeout_sec())
8163
return driver
8264

8365
def get_driver(self, options=None, capabilities=None, executor=None):
84-
if self.current_driver is not None:
85-
return self.current_driver
86-
else:
66+
if not self.current_driver:
8767
self.register_driver(driver_name=DriverTypes.chrome.name,
8868
options=options,
8969
capabilities=capabilities,
9070
executor=executor)
91-
return self.current_driver
71+
return self.current_driver
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import os
1+
from webdriver_manager.chrome import ChromeDriverManager
22
import sys
33

4-
from JDI.core.settings.jdi_settings import JDISettings
5-
6-
74
class WebDriverProvider:
85
@staticmethod
96
def get_chrome_driver_path():
10-
chrome = "/chromedriver.exe" if sys.platform.startswith("win") else "chromedriver"
11-
return os.path.join(JDISettings.get_driver_path(), chrome)
7+
chrome = ChromeDriverManager().install()
8+
return chrome
9+

JDI/web/selenium/elements/common/text_field.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, by_locator=None, by_label=None, web_element=None):
1111
def input(self, text):
1212
self.input_action(text)
1313

14-
def input_action(self,text):
14+
def input_action(self, text):
1515
self.get_web_element().send_keys(text)
1616

1717
@scenario(action_name="Send keys to the element")

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,17 @@
44

55
# JDI 2.0
66
Powerful Framework for UI Automation Testing on Python
7+
8+
## Getting started
9+
Before you begin:
10+
- Python 3.11 is used for this project. To install Python on MacOs you can use [Homebrew](https://brew.sh/), on Windows you can use [Chocolatey](https://chocolatey.org/).
11+
- run git clone https://github.com/jdi-testing/jdi-python.git or fork the repository and clone it afterwards.
12+
- create a virtual environment for the project. You can use [virtualenv](https://virtualenv.pypa.io/en/latest/) or [venv](https://docs.python.org/3/library/venv.html) for that.
13+
- set up Python interpreter to use Python 3.11 in your IDE.
14+
- run `pip install -r requirements.txt` to install all required dependencies.
15+
16+
## You can simply run tests to see how it works
17+
1. inside your IDE
18+
2. using pytest
19+
- activate your virtual environment by running `source venv/bin/activate` on MacOs or `venv\Scripts\activate` on Windows
20+
- run `pytest` in the terminal

jdi.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
driver=chrome
22
; domain=https://www.epam.com/
3-
domain=https://jdi-framework.github.io/tests
3+
domain=https://jdi-testing.github.io/jdi-light
44
timeout_wait_element=5
55
timeout_wait_pageLoad=5
66
drivers_folder=.\

requirements.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
pywin32==302
2-
selenium==3.141.0
3-
requests==2.25.1
1+
selenium==4.18.1
2+
requests==2.31.0
3+
pytest==8.1.1
4+
webdriver_manager==4.0.1

tests/jdi_uitests_webtests/main/entities/user.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,5 @@ def default():
77
return User()
88

99
def __init__(self):
10-
self.login = "epam"
11-
self.password = os.getenv("TEST_PASSWORD")
12-
self.name = "Name"
13-
self.last_name = "Last Name"
14-
self.description = "Description"
10+
self.login = "Roman"
11+
self.password = "Jdi1234"

tests/jdi_uitests_webtests/main/enums/preconditions.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
from JDI.web.selenium.preconditions.web_preconditions import WebPreconditions
77

88

9-
class Preconditions(Enum):
10-
HOME_PAGE = ("/index.htm",)
11-
CONTACT_PAGE = ("/page1.htm",)
12-
METALS_AND_COLORS_PAGE = ("/page2.htm",)
13-
SUPPORT_PAGE = ("/page3.htm",)
14-
DATES_PAGE = "/page4.htm"
15-
SIMPLE_TABLE_PAGE = "/page6.htm"
9+
class Preconditions(str, Enum):
10+
HOME_PAGE = ("/index.html",)
11+
CONTACT_PAGE = ("/contacts.html",)
12+
METALS_AND_COLORS_PAGE = ("/metals-colors.html",)
13+
SUPPORT_PAGE = ("/support.html",)
14+
DATES_PAGE = "/dates.html"
15+
SIMPLE_TABLE_PAGE = "/simple-table.html"
1616

1717
def is_in_state(self):
1818
str_value = self.value[0] if isinstance(self.value, tuple) else self.value

tests/jdi_uitests_webtests/main/page_objects/epam_jdi_site.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from JDI.web.selenium.elements.api_interact.find_element_by import By
22
from JDI.web.selenium.elements.complex.text_list import TextList
33
from JDI.web.selenium.elements.composite.web_site import WebSite
4+
from tests.jdi_uitests_webtests.main.enums.preconditions import Preconditions
45
from tests.jdi_uitests_webtests.main.page_objects.pages import (
56
ContactFormPage,
67
DatesPage,
@@ -16,12 +17,15 @@
1617

1718
class EpamJDISite(WebSite):
1819
# pages
19-
home_page = HomePage(url="/index.htm", title="Index Page")
20-
metals_colors_page = MetalColorPage(url="/page2.htm", title="Metal and Colors")
21-
contact_form_page = ContactFormPage(url="/page1.htm", title="Contact Form")
22-
support_page = SupportPage(url="/page3.htm", title="Support")
23-
dates_page = DatesPage(url="/page4.htm", title="Simple Table")
24-
simple_table_page = SimpleTablePage(url="/page6.htm", title="Simple Table")
20+
home_page = HomePage(url=Preconditions.HOME_PAGE.value, title="Index Page")
21+
metals_colors_page = MetalColorPage(url=Preconditions.METALS_AND_COLORS_PAGE.value,
22+
title="Metal and Colors")
23+
contact_form_page = ContactFormPage(url=Preconditions.CONTACT_PAGE.value,
24+
title="Contact Form")
25+
support_page = SupportPage(url=Preconditions.SUPPORT_PAGE.value, title="Support")
26+
dates_page = DatesPage(url=Preconditions.DATES_PAGE.value, title="Simple Table")
27+
simple_table_page = SimpleTablePage(url=Preconditions.SIMPLE_TABLE_PAGE.value,
28+
title="Simple Table")
2529

2630
# elements
2731
actions_log = TextList(By.css(".logs li"))

tests/jdi_uitests_webtests/main/page_objects/pages/login.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
class Login(Form):
99

10-
login = TextField(By.id("Login"))
10+
login = TextField(By.id("name"))
1111

12-
password = TextField(By.id("Password"))
12+
password = TextField(By.id("password"))
1313

1414
button = Button(By.css(".btn-login"))
1515

0 commit comments

Comments
 (0)