Exemplo n.º 1
0
 def __init__(self, browser):
     if browser == 'Firefox':
         self.driver = webdriver.Firefox()
     elif browser == 'Chrome':
         self.driver = webdriver.Chrome()
     elif browser == 'IE':
         self.driver = webdriver.Ie()
     else:
         raise ValueError("Unrecognized browser %s" % browser)
     self.driver.implicitly_wait(3)
     self.wait = WebDriverWait(self.driver, 5)
     self.myjson = JsonActions()
     self.main_page = MainPage(self.driver)
     self.header_block = AllPagesCommonHeader(self.driver)
     self.login_page = LoginPage(self.driver)
     self.footer_block = AllPagesCommonFooter(self.driver)
     self.job_page = JobPage(self.driver)
     self.country_list_page = CountryListPage(self.driver)
     self.favorites_page = FavoritesPage(self.driver)
     self.bag_page = BagPage(self.driver)
     self.iphone_page = IphonePage(self.driver)
     self.mac_page = MacPage(self.driver)
     self.imac_pro_buy_page = ImacProBuyPage(self.driver)
     self.customize_imac_pro_buy_page = CustomizeImacProPage(self.driver)
     self.imac_pro_accessories_page = ImacProAccessoriesPage(self.driver)
     self.gift_card_block = GiftCardBlock(self.driver)
     self.check_out_page = CheckOutPage(self.driver)
Exemplo n.º 2
0
class CountryListPage():
    def __init__(self, driver):
        self.driver = driver
        self.locators = CountryListPageLocators
        self.wait = WebDriverWait(driver, 5)
        self.myjson = JsonActions()

    def checking_country_links(self):
        for link in self.driver.find_elements(*self.locators.select_country):
            ActionChains(self.driver).key_down(Keys.CONTROL) \
                .click(link) \
                .key_up(Keys.CONTROL) \
                .perform()
            self.driver.switch_to_window(self.driver.window_handles[1])
            jsonfile = self.myjson.read_json_file(
                "countries_url_title_standart.json")
            assert jsonfile[self.driver.current_url[8:]] == self.driver.title
            self.driver.close()
            self.driver.switch_to_window(self.driver.window_handles[0])

    def test(self):
        dict = {}
        for link in self.driver.find_elements(*self.locators.select_country):
            ActionChains(self.driver).key_down(Keys.CONTROL) \
                .click(link) \
                .key_up(Keys.CONTROL) \
                .perform()
            self.driver.switch_to_window(self.driver.window_handles[1])
            dict[self.driver.current_url[8:]] = self.driver.title
            self.driver.close()
            self.driver.switch_to_window(self.driver.window_handles[0])
        self.myjson.write_json_file("countries_url_title_standart.json")
Exemplo n.º 3
0
 def __init__(self, driver):
     self.driver = driver
     self.wait = WebDriverWait(driver, 5)
     self.locators = BagPageLocators
     self.gift_locators = GiftCardBlockLocators
     self.myjson = JsonActions()
     self.convert = ConvertingPrice()
     self.item_prices = []
     self.subtotal_prices = []
Exemplo n.º 4
0
class BagPage:
    def __init__(self, driver):
        self.driver = driver
        self.wait = WebDriverWait(driver, 5)
        self.locators = BagPageLocators
        self.gift_locators = GiftCardBlockLocators
        self.myjson = JsonActions()
        self.convert = ConvertingPrice()
        self.item_prices = []
        self.subtotal_prices = []

    @property
    def main_text(self):
        self.wait.until(
            EC.presence_of_element_located(self.locators.continue_shopping))
        return self.driver.find_element(*self.locators.bag_main_text).text

    @property
    def items(self):
        item_list = []
        for item in self.driver.find_elements(*self.locators.items_name):
            item_list.append(item.text)
        return item_list

    @property
    def item(self):
        return self.driver.find_element(*self.locators.items_name).text

    @property
    def quantity(self):
        try:
            return self.driver.find_element(
                *self.locators.quantity_less_ten).get_attribute("value")
        except:
            return self.driver.find_element(
                *self.locators.quantity_more_ten).get_attribute("value")

    def remove_item(self):
        item = self.driver.find_element(*self.locators.items_name)
        self.driver.find_element(*self.locators.remove).click()
        self.wait.until(EC.staleness_of(item))

    @property
    def item_price(self):
        return self.driver.find_element(*self.locators.item_price).text

    @property
    def items_prices(self):
        prices = []
        for i in self.driver.find_elements(*self.locators.item_price):
            prices.append(i.text)
        return prices

    @property
    def subtotal_price(self):
        return self.driver.find_element(*self.locators.subtotal_price).text

    @property
    def tax_price(self):
        price = self.driver.find_element(*self.locators.summary_tax_value).text
        if price == "$ –":
            return None
        else:
            return price

    @property
    def total_price(self):
        return self.driver.find_element(*self.locators.total_price).text

    def summary_price(self, *price):
        result_price = 0
        for i in price:
            result_price += self.convert.convert_price_to_float(i)
        return self.convert.convert_float_to_price(result_price)

    def item_quantity_less_than_ten(self):
        select = Select(
            self.driver.find_element(*self.locators.quantity_less_ten))
        one_item_price = self.item_price
        for i in range(1, 10):
            select.select_by_value(str(i))
            self.wait.until(
                EC.text_to_be_present_in_element(
                    self.locators.item_price,
                    self.convert.converting_price(one_item_price, i)))
            self.item_prices.append(self.item_price)
            self.subtotal_prices.append(self.subtotal_price)

    @property
    def current_item_quantity(self):
        try:
            return self.driver.find_element(
                *self.locators.quantity_less_ten).get_attribute("value")
        except:
            return self.driver.find_element(
                *self.locators.quantity_more_ten).get_attribute("value")

    def choose_item_quantity(self, quantity):
        if len(self.driver.find_elements(
                *self.locators.quantity_more_ten)) == 0:
            if quantity in range(1, 10) or quantity is '10+':
                Select(
                    self.driver.find_element(
                        *self.locators.quantity_less_ten)).select_by_value(
                            str(quantity))
            else:
                Select(
                    self.driver.find_element(*self.locators.quantity_less_ten)
                ).select_by_value("10+")
                self.driver.find_element(
                    *self.locators.quantity_more_ten).clear()
                self.driver.find_element(
                    *self.locators.quantity_more_ten).send_keys(quantity)
                self.driver.find_element(
                    *self.locators.quantity_more_ten).send_keys(Keys.ENTER)
        else:
            self.driver.find_element(*self.locators.quantity_more_ten).click()
            self.driver.find_element(*self.locators.quantity_more_ten).clear()
            self.driver.find_element(
                *self.locators.quantity_more_ten).send_keys(quantity)
            self.driver.find_element(
                *self.locators.quantity_more_ten).send_keys(Keys.ENTER)

    @property
    def quantity_field(self):
        if len(self.driver.find_elements(
                *self.locators.quantity_more_ten)) != 0:
            return "Input"
        else:
            return "Select"

    def enter_zip_code(self, zip):
        jsonfile = self.myjson.read_json_file("zip_codes.json")
        self.driver.find_element(*self.locators.enter_zip_code).click()
        self.driver.find_element(*self.locators.zip_code_field).clear()
        self.driver.find_element(*self.locators.zip_code_field).send_keys(
            jsonfile[zip])
        self.driver.find_element(*self.locators.zip_code_apply).click()
        price = self.driver.find_element(*self.locators.summary_tax_value).text
        if len(self.driver.find_elements(*self.locators.zip_code_apply)) == 0:
            self.wait.until_not(
                EC.text_to_be_present_in_element(
                    self.locators.summary_tax_value, price))

    def showing_zip_code(self, zip):
        jsonfile = self.myjson.read_json_file("zip_codes.json")
        try:
            self.wait.until(
                EC.text_to_be_present_in_element(self.locators.enter_zip_code,
                                                 jsonfile[zip]))
            return True
        except:
            return False

    @property
    def zip_code_error(self):
        self.wait.until(
            EC.presence_of_element_located(self.locators.zip_code_error))
        return self.driver.find_element(*self.locators.zip_code_error).text

    def cancel_zip_code(self):
        self.driver.find_element(*self.locators.zip_code_cancel).click()

    def add_applecare_plus(self):
        self.driver.find_element(*self.locators.applecare_plus_add).click()
        self.wait.until(
            EC.presence_of_element_located(
                self.locators.applecare_plus_remove))

    def remove_applecare_plus(self):
        self.driver.find_element(*self.locators.applecare_plus_remove).click()
        self.wait.until(
            EC.presence_of_element_located(self.locators.applecare_plus_add))

    @property
    def applecare_plus_price(self):
        if len(self.driver.find_elements(
                *self.locators.applecare_plus_price)) == 0:
            return None
        else:
            return self.driver.find_element(
                *self.locators.applecare_plus_price).text

    def open_gift_card(self):
        self.driver.find_element(*self.locators.gift_message_add).click()

    def edit_gift_card(self):
        self.driver.find_element(*self.locators.gift_message_edit).click()

    @property
    def gift_message_text(self):
        self.wait.until(
            EC.invisibility_of_element_located(self.gift_locators.gift_header))
        try:
            return self.driver.find_element(
                *self.locators.gift_message_text).text
        except:
            return None

    @property
    def alert_message(self):
        try:
            self.wait.until(
                EC.presence_of_element_located(self.locators.alert_message))
            return self.driver.find_element(*self.locators.alert_message).text
        except:
            return "Alert message is not presence"

    @property
    def alert_message_is_not_presence(self):
        try:
            self.wait.until_not(
                EC.presence_of_element_located(self.locators.alert_message))
            return True
        except:
            return "Alert message is not presence:", self.driver.find_element(
                *self.locators.alert_message).text

    def continue_shopping(self):
        self.driver.find_element(*self.locators.continue_shopping).click()

    def add_second_item(self):
        self.driver.find_element(*self.locators.add_first_extra_item).click()
        self.wait.until_not(
            EC.presence_of_element_located(self.locators.add_first_extra_item))

    @property
    def notification_banner(self):
        self.wait.until(
            EC.presence_of_element_located(self.locators.notification_banner))
        return self.driver.find_element(
            *self.locators.notification_banner).text

    def return_product_in_bag(self):
        self.driver.find_element(*self.locators.undo_remove_item).click()

    def open_stores_menu(self):
        self.driver.find_element(*self.locators.more_stores).click()
        self.wait.until(
            EC.presence_of_element_located(self.locators.select_location))

    @property
    def stores_menu_header(self):
        return self.driver.find_element(*self.locators.select_location).text

    def close_stores_menu(self):
        self.driver.find_element(*self.locators.close_stores_menu).click()

    def check_out(self):
        self.driver.find_element(*self.locators.check_out).click()
Exemplo n.º 5
0
class CheckOutPage:

    def __init__(self, driver):
        self.driver = driver
        self.wait = WebDriverWait(driver, 5)
        self.locators = CheckOutPageLocators
        self.convert = ConvertingPrice()
        self.myjson = JsonActions()

    def bad_button(self, locator):
        self.driver.execute_script("window.scrollTo(0, 0)")
        button_user = self.driver.find_element(*locator)
        ActionChains(self.driver).move_to_element(button_user).click().perform()

    @property
    def total_price(self):
        return self.driver.find_element(*self.locators.summary_price).text

    def show_order_summary(self):
        self.driver.find_element(*self.locators.show_order_summary).click()
        self.wait.until(EC.visibility_of_element_located(self.locators.order_menu_header))

    @property
    def order_menu_total_price(self):
        return self.driver.find_element(*self.locators.order_menu_total_price).text

    @property
    def order_menu_header(self):
        return self.driver.find_element(*self.locators.order_menu_header).text

    def edit_bag(self):
        self.driver.find_element(*self.locators.edit_bag).click()

    @property
    def secure_message(self):
        return self.driver.find_element(*self.locators.secure_message).text

    def continue_to_bag(self):
        self.driver.find_element(*self.locators.secure_message_continue).click()

    def close_order_menu(self):
        self.driver.find_element(*self.locators.close_order_menu).click()

    def choose_delivery(self):
        self.bad_button(self.locators.delivery)

    def choose_pick_up(self):
        self.bad_button(self.locators.pick_up)

    @property
    def delivery_header(self):
        hidden = self.driver.find_element(*self.locators.hidden_header).text
        return self.driver.find_element(*self.locators.delivery_header).text.replace('\n'+hidden, "")

    @property
    def pick_up_header(self):
        return self.driver.find_element(*self.locators.pick_up_header).text

    @property
    def delivery_product(self):
        return self.driver.find_element(*self.locators.delivery_product).text

    def delivery_tommorow(self):
        self.driver.find_element(*self.locators.delivery_tommorow).click()
        self.wait.until_not(EC.text_to_be_present_in_element(self.locators.summary_price, self.total_price))

    @property
    def delivery_tommorow_price(self):
        return self.driver.find_element(*self.locators.delivery_tommorow_price).text

    @property
    def pick_up_zip_message(self):
        return self.driver.find_element(*self.locators.pick_up_zip_message).text

    def add_zip_code(self, zip):
        jsonfile = self.myjson.read_json_file("zip_codes.json")
        self.driver.find_element(*self.locators.enter_zip_code).clear()
        self.driver.find_element(*self.locators.enter_zip_code).send_keys(jsonfile[zip])
        self.bad_button(self.locators.zip_code_apply)

    def change_zip_code(self, zip):
        jsonfile = self.myjson.read_json_file("zip_codes.json")
        self.driver.find_element(*self.locators.zip_edit_button).click()
        self.wait.until(EC.element_to_be_clickable(self.locators.enter_zip_code))
        self.driver.find_element(*self.locators.enter_zip_code).clear()
        self.driver.find_element(*self.locators.enter_zip_code).send_keys(jsonfile[zip])
        self.bad_button(self.locators.zip_code_apply)

    def showing_zip_code(self, zip):
        jsonfile = self.myjson.read_json_file("zip_codes.json")
        try:
            self.wait.until(EC.text_to_be_present_in_element(self.locators.zip_edit_button, jsonfile[zip]))
            return True
        except:
            return False

    @property
    def wrong_zip_error_message(self):
        return self.driver.find_element(*self.locators.wrong_zip).text

    def summary_price(self, *price):
        result_price = 0
        for i in price:
            result_price += self.convert.convert_price_to_float(i)
        return self.convert.convert_float_to_price(result_price)
Exemplo n.º 6
0
 def __init__(self, driver):
     self.driver = driver
     self.wait = WebDriverWait(driver, 5)
     self.locators = CheckOutPageLocators
     self.convert = ConvertingPrice()
     self.myjson = JsonActions()
Exemplo n.º 7
0
class Application:
    def __init__(self, browser):
        if browser == 'Firefox':
            self.driver = webdriver.Firefox()
        elif browser == 'Chrome':
            self.driver = webdriver.Chrome()
        elif browser == 'IE':
            self.driver = webdriver.Ie()
        else:
            raise ValueError("Unrecognized browser %s" % browser)
        self.driver.implicitly_wait(3)
        self.wait = WebDriverWait(self.driver, 5)
        self.myjson = JsonActions()
        self.main_page = MainPage(self.driver)
        self.header_block = AllPagesCommonHeader(self.driver)
        self.login_page = LoginPage(self.driver)
        self.footer_block = AllPagesCommonFooter(self.driver)
        self.job_page = JobPage(self.driver)
        self.country_list_page = CountryListPage(self.driver)
        self.favorites_page = FavoritesPage(self.driver)
        self.bag_page = BagPage(self.driver)
        self.iphone_page = IphonePage(self.driver)
        self.mac_page = MacPage(self.driver)
        self.imac_pro_buy_page = ImacProBuyPage(self.driver)
        self.customize_imac_pro_buy_page = CustomizeImacProPage(self.driver)
        self.imac_pro_accessories_page = ImacProAccessoriesPage(self.driver)
        self.gift_card_block = GiftCardBlock(self.driver)
        self.check_out_page = CheckOutPage(self.driver)

    def home_page(self):
        self.driver.get("https://www.apple.com/")

    def quit(self):
        self.driver.quit()

    @property
    def url(self):
        return self.driver.current_url

    @property
    def page_title(self):
        return self.driver.title

    def current_page(self, page):
        try:
            self.wait.until(
                EC.title_is(
                    self.myjson.read_json_file("pages_title_standart.json")
                    [page]))
            return True
        except:
            print("This is other page, check 'pages_title_standart.json'")
            return False

    @property
    def login_data(self):
        try:
            return self.myjson.read_json_file("login_data.json")
        except:
            print(
                "File not found, check 'data' directory and found jsonfile with 'sign in' data"
            )

    def save_screenshot(self, i):
        self.driver.get_screenshot_as_file(r"C:\Users\Home\Downloads\screen" +
                                           str(i) + ".png")
Exemplo n.º 8
0
 def __init__(self, driver):
     self.driver = driver
     self.locators = CountryListPageLocators
     self.wait = WebDriverWait(driver, 5)
     self.myjson = JsonActions()