class ActionPage(BasePage):
    _page_locator = (By.XPATH, "//h2[contains(text(), '{}')]".format(
        Config().localization["action"]))

    _tabbtn_discount_locator = "//div[@class='tabbar_ctn']//div[contains(text(), '{}')]".format(
        Config().localization['discount'])  # ID "tab_select_Discounts"

    _game_label_locator = "//div[@id='DiscountsRows']//a"

    tabDiscount = Find(Tab, By.XPATH, _tabbtn_discount_locator)
    lblsGames = Finds(Label, By.XPATH, _game_label_locator)

    def __init__(self):
        super().__init__(self._page_locator,
                         Config().config['steam']['url']['actionPage'])

    def open_discount_tab(self):
        self.tabDiscount.click()
        self.scroll_window_to_top()

    def choose_game_by_max_discount(self):
        games = self.lblsGames
        lst = [int(re.search(r'\d\d', g.text).group()) for g in games]
        for g in games:
            if int(re.search(r'\d\d', g.text).group()) == max(lst):
                discount = max(lst)
                g.click()
                return discount
def setup_class(request):
    browser = Browser(Config().config['main']['browserName'])
    Config().driver = browser.driver

    def teardown_class():
        browser.driver.quit()

    request.addfinalizer(teardown_class)
	def _search_car():
		main_page = MainPage(Config().driver)
		main_page.go()
		main_page.click_tab()
		main_page.select_car_options()
		car_page = CarPage(Config().driver)
		car_page.go_to_trim_comparison()
		trim_page = TrimPage(Config().driver)
		trim_page.remember_car_info()
 def __call__(self, *args, **kwargs):
     if self.element is not None:
         return self.element
     else:
         self.element = WebDriverWait(
             Config().driver,
             Config().explicitly_wait).until(
                 EC.element_to_be_clickable(self.locator),
                 "Couldn't find element {}".format(self.__class__))
         return self.element
	def test_cars(self):
		self._search_car()
		self._search_car()

		trim_page = TrimPage(Config().driver)
		trim_page.go_to_research()
		research_page = ResearchPage(Config().driver)
		research_page.go_to_compare()
		compare_page = ComparePage(Config().driver)
		compare_page.select_first_car_to_compare()
		compare_page.select_second_car_to_compare()
		compare_page.assert_cars_info()
Exemplo n.º 6
0
 def _search_element(self):
     self._target_element = WebDriverWait(
         self.context.driver,
         Config().explicitly_wait).until(
             EC.visibility_of_all_elements_located((self.by, self.locator)))
     for item in self._target_element:
         item.__class__ = self.ui_type
Exemplo n.º 7
0
class CarPage(BasePage):
    __page_locator = (By.XPATH, "//nav[contsins(class, 'mmy-jumpnav')]")
    __url = Config().config['cars']['url']['carPage']

    _label_trim_locator = (By.XPATH, "//div[@id='mmy-trims']//a")

    def __init__(self, driver):
        super().__init__(self.__page_locator, self.__url, driver)
        self.lblTrims = Label(self._label_trim_locator)

    def go_to_trim_comparison(self):
        self.lblTrims().click()
 def __init__(self, brwsr_name):
     if brwsr_name == 'Firefox':
         if sys.platform == 'linux':
             self.driver = webdriver.Firefox(executable_path=Config(
             ).config['main']['pathToDriver']['geckoLinux'])
         elif sys.platform == 'win64':
             self.driver = webdriver.Firefox(executable_path=Config(
             ).config['main']['pathToDriver']['geckoWin64'])
         elif sys.platform == 'win32':
             self.driver = webdriver.Firefox(executable_path=Config(
             ).config['main']['pathToDriver']['geckoWin32'])
     elif brwsr_name == 'Chrome':
         if sys.platform == 'linux':
             self.driver = webdriver.Chrome(executable_path=Config(
             ).config['main']['pathToDriver']['chromeLinux'])
         elif sys.platform == 'win32':
             self.driver = webdriver.Chrome(executable_path=Config(
             ).config['main']['pathToDriver']['chromeWin32'])
     else:
         raise NameError(
             'Not support this browser or wrong name. Please try another browser.'
         )
Exemplo n.º 9
0
class MainPage(BasePage):
    _page_locator = (By.XPATH, "//div[@class=\"home_page_gutter\"]")
    _cmbx_lang_locator = "language_pulldown"
    _lbl_lang_locator = "//div[@id='language_dropdown']//a[contains(text(), '{}')]".format(
        Config().localization['language'])

    _cmbx_games_locator = "genre_tab"
    _action_label_locator = "//div[@id='genre_flyout']//a[contains(text(), '{}')]".format(
        Config().localization["action"])

    cmbxGames = Find(ComboBox, By.ID, _cmbx_games_locator)
    cmbxLanguage = Find(ComboBox, By.ID, _cmbx_lang_locator)

    def __init__(self):
        super().__init__(self._page_locator, Config().config['steam']['url']['mainPage'])

    def find_and_click_actions(self):
        self.cmbxGames.hover_and_click_on_lbl(By.XPATH, self._action_label_locator)

    def change_language(self):
        self.cmbxLanguage.click_self_and_lbl(By.XPATH, self._lbl_lang_locator)
        Config().language = 'en'
        self.refresh()
Exemplo n.º 10
0
 def _search_element(self):
     if not self.context:
         raise ValueError(
             "Search context should be defined with dynamic Find usage." +
             " Please define context in __init__.")
     if (self.by is not None) and (self.locator is not None):
         web_element = WebDriverWait(
             self.context.driver,
             Config().explicitly_wait).until(
                 EC.presence_of_element_located((self.by, self.locator)),
                 "Couldn't find element through {}".format(self.locator))
         web_element.__class__ = self.ui_type
         web_element.driver = self.context.driver
         self._target_element = web_element
class TrimPage(BasePage):
	__page_locator = ()
	__url = Config().config['cars']['url']['trimPage']

	_trim_engine_locator = (By.XPATH, "//div[@class='cell cell-bg grow-2']")
	_trim_transmission_locator = (By.XPATH, "//div[@class='cell grow-2']")

	_buy_label_locator = (By.XPATH, "//div[@class='global-nav']//a[@menu-name='Buy']")
	_research_label_locator = (By.XPATH, "//div[@id='user-setting']//li/a[contains(text(), 'Research Car Models')]")

	def __init__(self, driver):
		super().__init__(self.__page_locator, self.__url, driver)
		self.txtCarEngine = TextField(self._trim_engine_locator)
		self.txtCarTransmission = TextField(self._trim_transmission_locator)
		self.lblBuy = Label(self._buy_label_locator)
		self.lblResearch = Label(self._research_label_locator)

	def remember_car_info(self):
		Car.remembered_cars[-1].engine = self.txtCarEngine().text
		Car.remembered_cars[-1].transmission = self.txtCarTransmission().text

	def go_to_research(self):
		self.lblBuy().click()
		self.lblResearch().click()
Exemplo n.º 12
0
class BasePage():
    def __init__(self, locator, url):
        self.driver = Config().driver
        self._page_locator = locator
        self.url = url

    def go(self):
        self.driver.get(self.url)
        self._assert_page_load()

    def _assert_page_load(self):
        WebDriverWait(self.driver,
                      Config().explicitly_wait).until(
                          EC.presence_of_element_located(self._page_locator),
                          "Couldn't load page {}".format(self.url))

    def scroll_window_to_top(self):
        self.driver.execute_script("window.scrollTo(0, 0);")

    def refresh(self):
        self.driver.refresh()
Exemplo n.º 13
0
 def click_and_wait(self):
     self.click()
     WebDriverWait(self.driver,
                   Config().explicitly_wait).until(
                       EC.url_changes(self.driver.current_url))
 def __init__(self):
     super().__init__(self._page_locator,
                      Config().config['steam']['url']['actionPage'])
Exemplo n.º 15
0
 def change_language(self):
     self.cmbxLanguage.click_self_and_lbl(By.XPATH, self._lbl_lang_locator)
     Config().language = 'en'
     self.refresh()
Exemplo n.º 16
0
 def _assert_page_load(self):
     WebDriverWait(self.driver, Config().explicitly_wait).until(
         EC.presence_of_element_located(self._page_locator), "Couldn't load page {}".format(self.url))
Exemplo n.º 17
0
 def __init__(self, locator, url):
     self.driver = Config().driver
     self._page_locator = locator
     self.url = url
class ComparePage(BasePage):
    __page_locator = (By.XPATH,
                      "//h1[contains(text(), 'Compare Cars Side-by-Side')]")
    __url = Config().config['cars']['url']['comparePage']

    _formCompareLocator = (By.ID, "mainAddCarForm")
    _selectsLocators = (By.TAG_NAME, "select")
    _btnFormCompareLocator = (By.XPATH,
                              "//button[contains(@class, 'done-button')]")
    _btnFormModalLocator = (By.XPATH,
                            "//button[contains(class, 'modal-button')]")

    _labelAddCarLocator = (By.ID, "icon-div")
    _formAddCarLocator = (By.ID, "addCarFormModal")

    _templateCompareLocators = "//cars-compare-compare-info[@header='{}']{}"
    _cntrCompareEngineLocator = (By.XPATH,
                                 _templateCompareLocators.format('Engine', ''))
    _cntrCompareTransmissionLocator = (By.XPATH,
                                       _templateCompareLocators.format(
                                           'Transmission', ''))
    _lblCompareEngineLocator = (
        By.XPATH, "//cars-compare-compare-info[@header='Engine']//p")
    _lblCompareTransmissionLocator = (
        By.XPATH, "//cars-compare-compare-info[@header='Transmission']//p")

    def __init__(self, driver):
        super().__init__(self.__page_locator, self.__url, driver)
        self.formCompare = Form(
            self._formCompareLocator
        )  # первая форма сравнения форма сравнения (выбор машины)
        self.lblAddCar = Label(
            self._labelAddCarLocator
        )  # ссылка на окрытие формы добавления машины для сравнения
        self.formAddCar = Form(self._formAddCarLocator
                               )  # вторая форма сравнения (добавление машины)
        self.cntrCompareEngine = Container(
            self._cntrCompareEngineLocator)  # контейнер
        self.cntrCompareTransmission = Container(
            self._cntrCompareTransmissionLocator)  # контейнер
        self.btnFormCompare = Button(
            self._btnFormCompareLocator)  # кнопка подтверждения первой формы
        self.btnFormModal = Button(
            self._btnFormModalLocator)  # кнопка подтвержения второй формы

    def select_first_car_to_compare(self):
        self.formCompare.append_elements(self._selectsLocators, cls=Select)
        self.formCompare.select_values(Car.remembered_cars[0].make,
                                       Car.remembered_cars[0].model,
                                       Car.remembered_cars[0].year)
        self.btnFormCompare().click()

    def select_second_car_to_compare(self):
        self.lblAddCar().click()
        self.formAddCar.append_elements(self._selectsLocators, cls=Select)
        self.formAddCar.select_values(Car.remembered_cars[1].make,
                                      Car.remembered_cars[1].model,
                                      Car.remembered_cars[1].year)
        self.btnFormModal().click()

    # поиск текстовых элементов, содержащих информация о машинах и добавление в соответствующие контейнеры
    def _found_compare_info(self):
        self.cntrCompareEngine.append_elements(self._lblCompareEngineLocator,
                                               TextField)
        self.cntrCompareTransmission.append_elements(
            self._lblCompareTransmissionLocator, TextField)

    def assert_cars_info(self):
        self._found_compare_info()
        Engines = [
            re.sub(r'liter', 'L',
                   x().text) for x in self.cntrCompareEngine.get_elements()
        ]
        Transmissions = [
            t().text for t in self.cntrCompareTransmission.get_elements()[1:]
        ]
        # для избавления от лишних запятых, чтобы не падали assert'ы
        if Transmissions[0][-1] == ',':
            Transmissions[0] = Transmissions[0][:-1]

        assert Car.remembered_cars[0].engine in Engines
        assert Car.remembered_cars[1].engine in Engines
        assert Car.remembered_cars[0].transmission in Transmissions
        assert Car.remembered_cars[1].transmission in Transmissions