class ProductPage(BasePage): quantity_field = UiElement(By.ID, "quantity_wanted") size_dropdown = UiElement(By.ID, "group_1") black_color_piker_link = UiElement(By.NAME, "Black") add_to_cart_button = UiElement(By.NAME, "Submit") product_price_label = UiElement(By.ID, "our_price_display") def __init__(self, driver): BasePage.__init__( self, driver, "http://automationpractice.com/index.php?id_product=*&controller=product" ) def pick_black_color(self, color: str): if color.lower() == 'black': self.black_color_piker_link.click() def select_size(self, size): self.size_dropdown.select_dropdown_value_by_text("M") def set_quantity(self, value): self.quantity_field.set_text(str(value)) def click_add_to_cart(self): self.add_to_cart_button.click()
class LoginPage(BasePage): email_field = UiElement(By.ID, "email") password_field = UiElement(By.ID, "passwd") sign_in_button = UiElement(By.ID, "SubmitLogin") def __init__(self, driver): BasePage.__init__( self, driver, "http://www.automationpractice.com/index.php?controller=authentication&back=my-account" ) def input_email(self, email): self.email_field.set_text(email) def input_password(self, password): self.password_field.set_text((password)) def press_sin_in_button(self): self.sign_in_button.click() def login_to_website(self, email, password): self.input_email(email) self.input_password(password) self.press_sin_in_button()
def __init__(self, x, y, w, h): UiElement.__init__(self, x, y, w, h) self.color = (0, 0, 255) UiElement.set_event(self, "hover_in", self.on_hover_in) UiElement.set_event(self, "hover_out", self.on_hover_out) UiElement.set_event(self, "click", self.on_click) UiElement.set_event(self, "release", self.on_release) self.is_hover = False self.is_clicked = False
def __init__(self, x, y, w, h, filename): UiElement.__init__(self, x, y, w, h) UiElement.set_event(self, "hover_in", self.on_hover_in) UiElement.set_event(self, "hover_out", self.on_hover_out) UiElement.set_event(self, "click", self.on_click) UiElement.set_event(self, "release", self.on_release) self.is_hover = False self.is_clicked = False self.sprite_idle = Sprite(x, y, filename + "_idle.png", False) self.sprite_hover = Sprite(x, y, filename + "_hover.png", False) self.sprite_click = Sprite(x, y, filename + "_click.png", False) self.current_sprite = self.sprite_idle
def __init__(self, x, y, w, h, filename): UiElement.__init__(self, x, y, w, h) #self.color = (0, 0, 255) UiElement.set_event(self, "hover_in", self.on_hover_in) UiElement.set_event(self, "hover_out", self.on_hover_out) UiElement.set_event(self, "click", self.on_click) UiElement.set_event(self, "release", self.on_release) self.is_hover = False self.is_clicked = False self.sprite_idle = Sprite(x, y, 'Button_idle.png', False) self.sprite_hover = Sprite(x, y, 'Button_hover.png', False) self.sprite_click = Sprite(x, y, 'Button_click.png', False) self.current_sprite = self.sprite_idle #defines the current button that will be drawn
class AddressPage(BasePage): message_field = UiElement(By.NAME, "message") proceed_to_checkout_button = UiElement(By.NAME, "processAddress") def __init__(self, driver): BasePage.__init__( self, driver, "http://www.automationpractice.com/index.php?controller=authentication&back=my-account" ) def write_message(self, message): self.message_field.set_text(message) def proceed_to_checkout(self): self.proceed_to_checkout_button.click()
class BasePage: sign_in_link = UiElement( By.XPATH, "//a[@title = 'Log in to your customer account']") search_bar = UiElement(By.ID, "search_query_top") search_button = UiElement(By.NAME, "submit_search") def __init__(self, driver, expected_url): self.driver = driver self.expected_url = expected_url def click_sign_in_link(self): self.sign_in_link.click() def search(self, search_text): self.search_bar.set_text(search_text) self.search_button.click()
class ShippingPage(BasePage): my_carrier_delivery_option = UiElement(By.XPATH, "//td[contains(., 'My carrier') and contains(. , 'Delivery next day!')]") price = UiElement(By.XPATH, "//div[@class='delivery_option_price']") agree_to_terms_checkbox = UiElement(By.XPATH, "//label[@for='cgv']") proceed_to_checkout_button = UiElement(By.NAME, "processCarrier") def __init__(self, driver): BasePage.__init__(self, driver, "http://automationpractice.com/index.php?controller=order&step=2&multi-shipping=") def delivery_option_exists(self): return self.my_carrier_delivery_option.exists() def delivery_price_exists(self): return self.price.exists() def agree_to_terms(self): if not self.agree_to_terms_checkbox.is_checked(): self.agree_to_terms_checkbox.click() def proceed_to_checkout(self): self.proceed_to_checkout_button.click()
class CartComponent(UiComponent): dress_name_label = UiElement(By.ID, 'layer_cart_product_title') attributes_label = UiElement(By.ID, 'layer_cart_product_attributes') product_info_total_product_price = UiElement(By.ID, "layer_cart_product_price") product_info_quantity = UiElement(By.ID, "layer_cart_product_quantity") cart_info_price = UiElement(By.CLASS_NAME, "ajax_block_products_total") cart_info_shipping_price = UiElement(By.CLASS_NAME, "ajax_cart_shipping_cost") cart_info_total_price = UiElement(By.CLASS_NAME, "ajax_block_cart_total") proceed_to_checkout_button = UiElement(By.XPATH, ".//*[@title = 'Proceed to checkout']") def __init__(self,): UiComponent.__init__(self, By.ID, "layer_cart") self.wait_to_appear() self.wait_to_be_clickable() def proceed_to_checkout(self): self.proceed_to_checkout_button.click() def get_child_element_text(self, ui_element: UiElement): return self.get_child_element(ui_element).get_attribute("textContent")
class ProductComponent(UiComponent): BLACK_COLOR = 'background: rgb(241, 196, 15);' add_to_cart_button = UiElement(By.XPATH, "//span[text()='Add to cart']//parent::a") colors = UiElement(By.CLASS_NAME, "color_pick") in_stock_indication = UiElement(By.CLASS_NAME, "available-now") product_name_label = UiElement(By.CLASS_NAME, "product-name") product_price_label = UiElement(By.XPATH, "//span[@class = 'price product-price' and @itemprop = 'price']") product_link = UiElement(By.CLASS_NAME, "product_img_link") def __init__(self, index): locator = f"//ul[contains(@class, 'product_list')]/li[{str(index)}]" UiComponent.__init__(self, By.XPATH, locator) def is_in_stock(self): return self.child_element_exists(self.in_stock_indication) def color_available(self, color): colors = self.get_child_elements(self.colors) for a_color in colors: if color in str(a_color.get_attribute("href")): return True return False def click_product_link(self): self.get_child_element(self.product_link).click()
class SummaryPage(BasePage): dress_name_label = UiElement(By.CLASS_NAME, 'product-name') attributes_label = UiElement(By.XPATH, "//td[@class='cart_description']/small/a") product_availibility = UiElement(By.XPATH, "//td[@class='cart_avail']/span") product_unit_price = UiElement(By.XPATH, "//td[@class='cart_unit']/span/span") product_quantity = UiElement(By.CLASS_NAME, "cart_quantity_input") product_total_price = UiElement(By.XPATH, "//td[@class='cart_total']/span") cart_info_price = UiElement(By.ID, "ajax_block_products_total") cart_info_shipping_price = UiElement(By.ID, "total_shipping") cart_info_total_price_without_tax = UiElement(By.ID, "total_price_without_tax") cart_info_tax = UiElement(By.ID, "total_tax") cart_info_total_price = UiElement(By.ID, "total_price") proceed_to_checkout_button = UiElement(By.CLASS_NAME, "standard-checkout") def __init__(self, driver): BasePage.__init__( self, driver, "http://automationpractice.com/index.php?controller=order") def proceed_to_checkout(self): self.proceed_to_checkout_button.click()
def __init__(self, x, y, w, h): UiElement.__init__(self, x, y, w, h) self.color = (255, 255, 255)
def __init__(self): UiElement.__init__(self, By.XPATH, "//ul[contains(@class, 'product_list')]/li")
def __init__(self, by, locator): UiElement.__init__(self, by, locator)
class PaymentPage(BasePage): dress_name_label = UiElement(By.CLASS_NAME, 'product-name') attributes_label = UiElement(By.XPATH, "//td[@class='cart_description']/small/a") product_availibility = UiElement(By.XPATH, "//td[@class='cart_avail']/span") product_unit_price = UiElement(By.XPATH, "//td[@class='cart_unit']/span/span") product_quantity = UiElement( By.XPATH, "//td[contains(@class,'cart_quantity')]/span") product_total_price = UiElement(By.XPATH, "//td[@class='cart_total']/span") cart_info_price = UiElement(By.ID, "ajax_block_products_total") cart_info_shipping_price = UiElement(By.ID, "total_shipping") cart_info_total_price_without_tax = UiElement(By.ID, "total_price_without_tax") cart_info_tax = UiElement(By.ID, "total_tax") cart_info_total_price = UiElement(By.ID, "total_price") proceed_to_checkout_button = UiElement(By.CLASS_NAME, "standard-checkout") bank_wire_link = UiElement(By.XPATH, "//*[@title='Pay by bank wire']") order_summary = UiElement(By.CLASS_NAME, "cheque-box") order_confirmation = UiElement(By.CLASS_NAME, "box") confirm_order_button = UiElement( By.XPATH, "//button[contains(., 'I confirm my order')]") def __init__(self, driver): BasePage.__init__( self, driver, "http://automationpractice.com/index.php?controller=order") def proceed_to_checkout(self): self.proceed_to_checkout_button.click() def pay_by_bank_wire(self): self.bank_wire_link.click() def verify_order_summary(self, total_price): actual = self.order_summary.get_attribute("innerHTML") with open( pathlib.Path(__file__).parent.absolute().joinpath( "..\\data\\order_summary.txt")) as f: expected = f.read() expected = expected.replace("{total_amount}", total_price) assert actual.strip() == expected.strip() def verify_order_confirmation(self, total_price): actual = self.order_confirmation.get_attribute("innerHTML") with open( pathlib.Path(__file__).parent.absolute().joinpath( "..\\data\\order_confirmation.txt")) as f: expected = f.read() expected = expected.replace("{total_amount}", total_price) actual = re.sub("reference.*in", "reference in", actual) assert actual.strip() == expected.strip() def confirm_order(self): self.confirm_order_button.click()
def __init__(self, x, y, w, h): UiElement.__init__(self, x, y, w, h) self.color = (255, 255, 255) UiElement.set_event(self, "hover_in", self.on_hover_in) UiElement.set_event(self, "hover_out", self.on_hover_out) self.is_hover = False