Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object oriented #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]

steps:
- name: Start Selenoid Server
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
max-line-length=120

# Docstrings
disable=C0114,C0115,C0116,R0903,W1514,R1720,R1705,R1723
disable=C0114,C0115,C0116,R0903,W1514,R1720,R1705,R1723,W0707

[MASTER]
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"
92 changes: 59 additions & 33 deletions lib/driver_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,85 @@

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.webdriver import WebDriver
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.firefox import GeckoDriverManager
from webdriver_manager.microsoft import IEDriverManager

from configuration.config_parse import IMPLICIT_SEC


class Driver:
class DriverManager:

_driver = None

@staticmethod
def get_chrome_options():
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
options.add_experimental_option('w3c', False)
options.add_argument('--no-sandbox')
options.add_argument("--headless")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
return options

def get_driver(self):
@classmethod
def set_driver(cls) -> WebDriver:
driver = None
browser = os.getenv('browser', 'chrome')
if os.getenv('GITHUB_RUN'):
options = self.get_chrome_options()
capabilities = {'browserName': browser, 'sessionTimeout': '5m'}
browser = os.getenv("browser", "chrome")
if os.getenv("GITHUB_RUN"):
options = cls.get_chrome_options()
capabilities = {"browserName": browser, "sessionTimeout": "5m"}
capabilities.update(options.to_capabilities())
driver = webdriver.Remote(command_executor=os.getenv('SELENIUM_HUB_HOST'),
desired_capabilities=capabilities)
return self.add_driver_settings(driver)
if browser == 'chrome':
driver = webdriver.Remote(
command_executor=os.getenv("SELENIUM_HUB_HOST"),
desired_capabilities=capabilities,
)
return cls.add_driver_settings(driver)
if browser == "chrome":
options = Options()
if os.getenv('HEADLESS', 'false').lower() == 'true' or os.getenv('DOCKER_RUN'):
options = self.get_chrome_options()
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options,
desired_capabilities={'goog:loggingPrefs': {'performance': 'ALL'}})
if os.getenv("HEADLESS", "false").lower() == "true" or os.getenv(
"DOCKER_RUN"
):
options = cls.get_chrome_options()
driver = webdriver.Chrome(
ChromeDriverManager(version="105.0.5195.52").install(),
options=options,
desired_capabilities={"goog:loggingPrefs": {"performance": "ALL"}},
)

elif browser == 'firefox':
elif browser == "firefox":
operation_system = platform.system()
arch = platform.architecture()
if operation_system in ('Darwin', 'Linux'):
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
if operation_system in ("Darwin", "Linux"):
driver = webdriver.Firefox(
executable_path=GeckoDriverManager().install()
)
else:
if arch[0] == '32bit':
driver = webdriver.Firefox(executable_path=GeckoDriverManager(os_type='win32').install())
elif arch[0] == '64bit':
driver = webdriver.Firefox(executable_path=GeckoDriverManager(os_type='win64').install())
elif browser == 'safari':
driver = webdriver.Safari(executable_path='/usr/bin/safaridriver')
elif browser == 'ie':
if arch[0] == "32bit":
driver = webdriver.Firefox(
executable_path=GeckoDriverManager(os_type="win32").install()
)
elif arch[0] == "64bit":
driver = webdriver.Firefox(
executable_path=GeckoDriverManager(os_type="win64").install()
)
elif browser == "safari":
driver = webdriver.Safari(executable_path="/usr/bin/safaridriver")
elif browser == "ie":
arch = platform.architecture()
if arch[0] == '32bit':
driver = webdriver.Ie(executable_path=IEDriverManager(os_type='Win32').install())
elif arch[0] == '64bit':
driver = webdriver.Ie(executable_path=IEDriverManager(os_type='x64').install())
return self.add_driver_settings(driver)
if arch[0] == "32bit":
driver = webdriver.Ie(
executable_path=IEDriverManager(os_type="Win32").install()
)
elif arch[0] == "64bit":
driver = webdriver.Ie(
executable_path=IEDriverManager(os_type="x64").install()
)
cls._driver = cls.add_driver_settings(driver)
return cls._driver

@classmethod
def get_driver(cls) -> WebDriver:
return getattr(cls, "_driver", None) or cls.set_driver()

@staticmethod
def add_driver_settings(driver):
Expand Down
Empty file added lib/elemets/__init__.py
Empty file.
97 changes: 97 additions & 0 deletions lib/elemets/base_element.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from functools import cached_property

from configuration.config_parse import TIMEOUT_SEC
from lib.selenium_driver import Driver


class BaseElement:
def __init__(self, locator: tuple):
self.locator = locator

@cached_property
def driver(self) -> Driver:
return Driver()

@property
def is_selected(self) -> bool:
return self.driver.is_element_selected(*self.locator)

@property
def is_checked(self) -> bool:
return self.driver.is_checked_checkbox(*self.locator)

@property
def is_enabled(self) -> bool:
return self.driver.is_element_enabled(*self.locator)

@property
def is_present(self) -> bool:
return self.driver.is_element_present(*self.locator)

@property
def is_invisible(self) -> bool:
return self.driver.is_element_invisible(*self.locator)

@property
def is_visible(self) -> bool:
return self.driver.is_element_visible(*self.locator)

@property
def text(self) -> str:
return self.driver.get_text(*self.locator)

@property
def text_of_all(self) -> list[str]:
return self.driver.get_text_of_many_elements(*self.locator)

def click(self, timeout: float = TIMEOUT_SEC):
self.driver.click(*self.locator, timeout=timeout)

def hover(self):
self.driver.hover(*self.locator)

def click_last_element(self):
self.driver.click_last_element(*self.locator)

def click_element_with_js(self):
self.driver.click_element_with_js()

# Click on web element and check that another element appear
def click_and_check(self, check_locator: tuple):
self.driver.click_and_check(self.locator, check_locator)

# Click on web element and check that element missed
def click_and_wait_for_element_to_be_hidden(self):
self.driver.click_and_wait_for_element_to_be_hidden(*self.locator)

def click_and_wait_for_element_to_be_not_clickable(self):
self.driver.click_and_wait_for_element_to_be_not_clickable(*self.locator)

def click_and_wait_for_other_element_to_be_hidden(self, check_locator: tuple):
self.driver.click_and_wait_for_other_element_to_be_hidden(
self.locator, check_locator
)

def click_if_element_visible(self):
self.driver.click_if_element_visible(*self.locator)

def type(self, text: str):
self.driver.type(text, *self.locator)

def type_without_clearing(self, text: str):
self.driver.type_without_clearing(text, self.locator)

def upload_file(self, filename: str):
self.driver.upload_file(filename, *self.locator)

def clear(self):
self.driver.clear(*self.locator)

def defocus_element(self):
self.driver.defocus_element(self.locator)

def drag_element_to_element(self, destination_element: tuple):
self.driver.drag_element_to_element(*self.locator, *destination_element)

def get_attribute_value(self, attribute: str) -> str:
return self.driver.get_attribute_value(attribute, *self.locator)
Loading