Example #1
0
    def find_products_name_price(self, browser):
        product_names_list = []
        product_prices_list = []
        # wait for the product names elements to be visible in the UI
        LIB.wait_for_elements(self, browser, self.product_names)
        # locate the product names elements
        product_names = self.browser.find_elements(*self.product_names)
        # iterate in product names and append the elements' texts to the list
        for i in product_names:
            product_names_list.append(i.text)

        # locate the product prices elements
        product_prices = self.browser.find_elements(*self.product_prices)
        # iterate in product prices and append the elements' texts to the list
        for i in product_prices:
            product_prices_list.append(i.text)
        # delete every second element counting from the first one
        #del product_prices_list[1::2]
        # create dictionary from the 2 lists and return it
        return dict(zip(product_names_list, product_prices_list))
def test_4():

    try:
        # create lib page object
        obj_lib = LIB()

        # open browser
        browser = obj_lib.open_browser()

        # navigate to the url
        obj_lib.page_load(browser)

        # wait for the Women tab to be visible in Home page, locate it and click on it
        obj_home = Home(browser)
        obj_lib.wait_for_element(browser, obj_home.women)
        browser.find_element(*obj_home.women).click()

        # wait for the product names and prices in Women tab to be visible in Home page
        obj_lib.wait_for_elements(browser, obj_home.product_names)
        obj_lib.wait_for_elements(browser, obj_home.product_prices)

        # return dictionary with Women tab's products names and prices
        products_names_prices = obj_home.find_products_name_price(browser)

        # write the products names and prices in log.txt file
        obj_lib.write_to_file(products_names_prices)

    except Exception as e:
        # save the screenshot of the test file which has failed
        obj_lib.save_screenshot(browser)
        pytest.fail(e)
        print('Test 4 failed!')

    finally:
        # close the browser
        obj_lib.close_browser(browser)