Skip to content

Commit

Permalink
fixing tests on new site
Browse files Browse the repository at this point in the history
  • Loading branch information
vklonin committed Mar 13, 2024
1 parent d9ef025 commit cb77e07
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 31 deletions.
11 changes: 8 additions & 3 deletions JDI/core/settings/jdi_settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from pathlib import Path, PurePath
import logging
from pathlib import Path

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -47,7 +46,13 @@ def get_driver_path():
def get_setting_by_name(setting_name):
if not JDISettings._jdi_settings:
JDISettings._read_jdi_settings()
return JDISettings._jdi_settings.get(setting_name, None)
value = JDISettings._jdi_settings.get(setting_name, None)
if value.lower() in ("true", "yes", "1"):
return True
elif value.lower() in ("false", "no", "0"):
return False
else:
return value

@staticmethod
def get_current_timeout_sec():
Expand Down
2 changes: 1 addition & 1 deletion JDI/web/selenium/driver/selenium_driver_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def set_driver_options_and_capabilities(self, driver_name, options, capabilities
self.capabilities = capabilities

def add_options(self, options):
for arg in options:
for arg in options.arguments:
self.options.add_argument(arg)

def register_chrome_driver(self):
Expand Down
10 changes: 10 additions & 0 deletions JDI/web/selenium/settings/web_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from JDI.core.settings.jdi_settings import JDISettings
from JDI.web.selenium.driver.selenium_driver_factory import \
SeleniumDriverFactory
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.firefox.options import Options as FirefoxOptions


class WebSettings(JDISettings):
Expand All @@ -21,6 +23,14 @@ def set_driver_factory(driver_factory):

@staticmethod
def use_driver(options=None, capabilities=None, executor=None):
if options is None:
options = ChromeOptions() if JDISettings.get_setting_by_name(
"driver") == "chrome" else FirefoxOptions()

headless = JDISettings.get_setting_by_name("headless")

if headless:
options.add_argument("--headless")
driver_name = JDISettings.get_setting_by_name("driver")
JDISettings._driver_factory = SeleniumDriverFactory()
WebSettings.set_driver_factory(JDISettings._driver_factory)
Expand Down
3 changes: 2 additions & 1 deletion jdi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ domain=https://jdi-testing.github.io/jdi-light
timeout_wait_element=5
timeout_wait_pageLoad=5
drivers_folder=.\
driver_getLatest=true
driver_getLatest=true
headless=False
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from JDI.web.selenium.elements.complex.base_selector import BaseSelector
from JDI.web.selenium.elements.complex.dropdown import Dropdown
from selenium.webdriver.common.by import By as Strategy


class TreeDropdown(Dropdown):
Expand All @@ -27,5 +28,5 @@ def select_action(self, names):
el.set_parent(self)

web_el = el.get_element(split[i])
if "dropdown-invisible-group" not in web_el.find_element_by_xpath("..").get_attribute("class"):
if "dropdown-invisible-group" not in web_el.find_element(Strategy.XPATH, "..").get_attribute("class"):
web_el.click()
2 changes: 1 addition & 1 deletion tests/jdi_uitests_webtests/main/entities/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ def __init__(self, name, last_name, description):
self.description = description

def __str__(self):
return "Summary: 3\nName: {0}\nLast Name: {1}\nDescription: {2}".format(
return "Summary: 3\nLast Name: {1}\nDescription: {2}\nVegetables:".format(
self.first_name, self.last_name, self.description
)
2 changes: 1 addition & 1 deletion tests/jdi_uitests_webtests/main/enums/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Nature(Enum):


class Metals(Enum):
COL = "Col"
METALS = "Metals"
GOLD = "Gold"
SILVER = "Silver"
BRONZE = "Bronze"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
from JDI.web.selenium.elements.common.text_area import TextArea
from JDI.web.selenium.elements.common.text_field import TextField
from JDI.web.selenium.elements.composite.web_page import WebPage
from tests.jdi_uitests_webtests.main.entities.contact import Contact
from tests.jdi_uitests_webtests.main.page_objects.sections.contact_form import ContactForm, ContactFormTwoButtons


class ContactFormPage(WebPage):
def __init__(self, url, title):
super(ContactFormPage, self).__init__(url=url, title=title)

description = TextArea(By.id("Description"))
description = TextArea(By.id("description"))

name_text_field = TextField(By.id("Name"))
name_text_field = TextField(By.id("first-name"))

contact_form = ContactForm(By.css("main form"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
from JDI.web.selenium.elements.complex.dropdown import Dropdown
from JDI.web.selenium.elements.composite.web_page import WebPage
from tests.jdi_uitests_webtests.main.page_objects.sections.summary import Summary
from selenium.webdriver.common.by import By as strategy
from selenium.webdriver.common.by import By as Strategy


class CheckBoxMetalColor(CheckBox):
def is_check_action(self):
driver = JDISettings.get_driver_factory().get_driver()
return (
False
if driver.find_element(strategy.XPATH, "//*[@id='elements-checklist']//*[*[text()='Water']]/input").get_attribute(
if driver.find_element(Strategy.XPATH, "//*[@id='elements-checklist']//*[*[text()='Water']]/input").get_attribute(
"checked"
)
is None
Expand All @@ -27,7 +27,7 @@ def is_check_action(self):

class CheckListMetalColor(CheckList):
def is_element_selected(self, el):
return el.find_element(strategy.XPATH, "../input").is_selected()
return el.find_element(Strategy.XPATH, "../input").is_selected()


class ComboBoxMetalColor(ComboBox):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class ContactForm(Form):
def __init__(self, by_locator=None):
super(ContactForm, self).__init__(by_locator)

first_name = TextField(By.id("Name"))
last_name = TextField(By.id("LastName"))
description = TextArea(By.id("Description"))
first_name = TextField(By.id("first-name"))
last_name = TextField(By.id("last-name"))
description = TextArea(By.id("description"))

submit = Button(By.xpath("//*[text()='Submit']"))

Expand All @@ -23,9 +23,9 @@ class ContactFormTwoButtons(Form):
def __init__(self, by_locator=None):
super(ContactFormTwoButtons, self).__init__(by_locator)

first_name = TextField(By.id("Name"))
last_name = TextField(By.id("LastName"))
description = TextArea(By.id("Description"))
first_name = TextField(By.id("first-name"))
last_name = TextField(By.id("last-name"))
description = TextArea(By.id("description"))

submit = Button(By.xpath("//*[text()='Submit']"))
calculate = Button(By.xpath("//*[text()='Calculate']"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from JDI.web.selenium.elements.complex.radio_buttons import RadioButtons
from JDI.web.selenium.elements.complex.selector import Selector
from JDI.web.selenium.elements.composite.section import Section
from selenium.webdriver.common.by import By as Strategy

ERROR_MSG = "No elements selected. Override getSelectedAction or place locator to <select> tag"

Expand All @@ -18,11 +19,11 @@ def get_selected(self):
element = list(filter(lambda x: x.is_selected(), self.get_input_web_elements()))
if len(element) == 0:
raise ValueError(ERROR_MSG)
return element[0].find_element_by_xpath("..").text
return element[0].find_element(Strategy.XPATH, "..").text

def is_selected_action(self, element) -> bool:
actual_text = (
list(filter(lambda x: x.is_selected(), self.get_input_web_elements()))[0].find_element_by_xpath("..").text
list(filter(lambda x: x.is_selected(), self.get_input_web_elements()))[0].find_element(Strategy.XPATH, "..").text
)
if isinstance(element, str):
return actual_text == element
Expand All @@ -40,14 +41,14 @@ def get_selected_index(self):
class RadioButtonsSummary(SelectElements, RadioButtons):
def get_input_web_elements(self):
return list(
map(lambda el: el.find_element_by_tag_name("input"), super(RadioButtonsSummary, self).get_web_elements())
map(lambda el: el.find_element(Strategy.TAG_NAME, "input"), super(RadioButtonsSummary, self).get_web_elements())
)


class SelectorSummary(SelectElements, Selector):
def get_input_web_elements(self):
return list(
map(lambda el: el.find_element_by_tag_name("input"), super(SelectorSummary, self).get_web_elements())
map(lambda el: el.find_element(Strategy.TAG_NAME, "input"), super(SelectorSummary, self).get_web_elements())
)


Expand Down
10 changes: 5 additions & 5 deletions tests/jdi_uitests_webtests/test/complex/combo_box_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@pytest.mark.web
class ComboBoxTests(InitTests):

add_options = ["Col", "Gold", "Silver", "Bronze", "Selen"]
add_options_string = "Col, Gold, Silver, Bronze, Selen"
add_options = ["Metals", "Gold", "Silver", "Bronze", "Selen"]
add_options_string = "Metals, Gold, Silver, Bronze, Selen"

combo_box = EpamJDISite.metals_colors_page.combo_box

Expand Down Expand Up @@ -59,10 +59,10 @@ def test_get_selected_index(self):
)

def test_is_selected(self):
Assert.assert_equal(self.combo_box.is_selected("Col"), True)
Assert.assert_equal(self.combo_box.is_selected("Metals"), True)

def test_is_selected_enum(self):
Assert.assert_equal(self.combo_box.is_selected(Metals.COL), True)
Assert.assert_equal(self.combo_box.is_selected(Metals.METALS), True)

def test_get_value(self):
Assert.assert_equal(self.combo_box.get_value(), "Col")
Assert.assert_equal(self.combo_box.get_value(), "Metals")
3 changes: 1 addition & 2 deletions tests/jdi_uitests_webtests/test/composite/form_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from tests.jdi_uitests_webtests.main.enums.entities import Buttons
from tests.jdi_uitests_webtests.main.enums.preconditions import Preconditions
from tests.jdi_uitests_webtests.main.page_objects.epam_jdi_site import EpamJDISite
from tests.jdi_uitests_webtests.main.utils.common_action_data import CommonActionsData
from tests.jdi_uitests_webtests.test.init_tests import InitTests


Expand Down Expand Up @@ -38,7 +37,7 @@ def test_submit_string(self):
self.form.submit_form(self.contact.description)
Assert.assert_equal(
EpamJDISite.contact_form_page.result.get_text(),
"Summary: 3\nDescription: {0}".format(self.contact.description),
"Summary: 3\nDescription: {0}\nVegetables:".format(self.contact.description),
)

def test_verify(self):
Expand Down

0 comments on commit cb77e07

Please sign in to comment.