def click_on_image_tab(driver): """ Click on image tab in create new product menu :param driver: browser web driver """ BasePage.click_on_object(driver, locator=Locators.image_tab_button_locator)
def input_download_file_name(driver, name): """ Input file name to the Download Name field :param driver: browser web driver :param name: name for file that we will download """ BasePage.send_keys(driver, Locators.download_name_field_locator, some_keys=name)
def click_downloads_button(driver): """ Click on downloads button in the catalog :param driver: browser web driver """ BasePage.click_on_object( driver, locator=Locators.downloads_menu_products_locator)
def click_delete_all_products_button(driver): """ Delete all choosed products :param driver: browser web driver """ BasePage.click_on_object(driver, locator=Locators.delete_products_locator)
def click_filter_button(driver): """ Click on filter assert button :param driver: browser web driver """ BasePage.click_on_object(driver, locator=Locators.filter_button_locator)
def password_input(driver, password): """ Input password to password field :param driver: browser web driver :param password: user password """ BasePage.send_keys(driver, locator=Locators.password_input_locator, some_keys=password)
def login_input(driver, login): """ Input email address to login field :param driver: browser web driver :param login: user email address """ BasePage.send_keys(driver, locator=Locators.login_input_locator, some_keys=login)
def click_menu_constructor(driver): """ Click on menu constructor in main menu :param driver: browser web driver """ BasePage.click_on_object(driver, locator=Locators.menu_constructor_locator)
def save_new_product_button_click(driver): """ Click on save new product button :param driver: browser web driver """ BasePage.click_on_object( driver, locator=Locators.save_new_product_button_locator)
def click_on_image(driver): """ Click on image in create new product menu :param driver: browser web driver """ BasePage.click_on_object(driver, locator=Locators.product_image_locator)
def clear_product_name_field(driver): """ Clear the product name field :param driver: browser web driver """ BasePage.clear_object(driver, locator=Locators.name_input_field_locator)
def message_close_button_click(driver): """ Click on close button of the message :param driver: browser web driver """ BasePage.click_on_object(driver, locator=Locators.message_close_button_locator)
def clear_filter_name_filed(driver): """ Clear product filter name field :param driver: browser web driver """ BasePage.clear_object(driver, locator=Locators.product_name_filter_locator)
def open_product_catalog(driver): """ Open product catalog combobox :param driver: browser web driver """ BasePage.click_on_object(driver, locator=Locators.product_catalog_locator)
def click_product_button(driver): """ Click on product button in the catalog :param driver: browser web driver """ BasePage.click_on_object(driver, locator=Locators.product_button_locator)
def click_on_edit_image_button(driver): """ Click on image edit button in new product menu :param driver: browser web driver """ BasePage.click_on_object(driver, locator=Locators.image_edit_button_locator)
def input_product_name(driver, product_name): """ Input product name in add new product menu :param driver: browser web driver :param product_name: name of the product that we want to add """ BasePage.send_keys(driver, locator=Locators.name_input_field_locator, some_keys=product_name)
def delete_selected_file(driver): """ Delete file that was selected by checkbox :param driver: browser web driver """ BasePage.click_on_object(driver, Locators.delete_file_button_locator) alert_message = "Are you sure?" wait_for_alert(driver, alert_message, delay=3) BasePage.alert_accept_click(driver)
def input_meta_tag(driver, meta_tag): """ Input meta tag for new product :param driver: browser web driver :param meta_tag: meta tag of product that we want to add """ BasePage.send_keys(driver, locator=Locators.meta_title_locator, some_keys=meta_tag)
def input_model(driver, model): """ Input model to the model field for product that we want to add :param driver: browser web driver :param model: model of the new product """ BasePage.send_keys(driver, locator=Locators.model_input_field_locator, some_keys=model)
def select_downloaded_file(driver): """ Select first file checkbox :param driver: browser web driver """ BasePage.click_on_first_object_from_many(driver, Locators.check_box_type_locator, attribute="name", attribute_value="selected[]")
def drug_computer_drop_components(driver): """ In the menu constructor drug computer menu and drop it to components :param driver: browser web driver """ BasePage.drug_and_drop_element( driver, source_locator=Locators.computer_menu_locator, target_locator=Locators.components_menu_locator)
def input_product_name_to_filter(driver, product_name): """ Enter product name to the product filter :param driver: browser web driver :param product_name: product name by that we will filter products """ BasePage.send_keys(driver, locator=Locators.product_name_filter_locator, some_keys=product_name)
def click_choose_all_products_checkbox(driver): """ Iter all checkboxes and found checkbox for choose all products :param driver: browser web driver """ BasePage.click_on_first_object_from_many( driver, locator=Locators.checkboxes_locator, attribute='type', attribute_value='checkbox')
def find_and_click_edit_button(driver): """ Find from buttons edit button and click it :param driver: browser web river """ BasePage.click_on_first_object_from_many( driver, locator=Locators.edit_product_button_locator, attribute='data-original-title', attribute_value='Edit')
def click_on_add_image_button(driver): """ Click on add new image button in new product menu :param driver: browser web driver """ BasePage.click_on_first_object_from_many( driver, locator=Locators.add_image_locator, attribute="data-original-title", attribute_value="Add Image")
def choose_remove_images_by_names(driver, file_names): """ Delete all images by names :param driver: browser web driver :param file_names: names of images that we wanna delete """ for arg in file_names: BasePage.click_on_all_object_from_many( driver, locator=Locators.checkboxes_locator, attribute="value", attribute_value="catalog/{}".format(arg))
def add_images_to_product(driver, *file_names): """ Add images to product from opencart store :param driver: browser web driver :param file_names: names of images that we loaded before it """ if len(file_names) == 1: ProductPage.click_on_image(driver) ProductPage.click_on_edit_image_button(driver) BasePage.click_on_object(driver, locator=(By.XPATH, '//*[@title="%s"]', str(file_names))) ProductPage.close_add_image_menu() if len(file_names) > 1: ProductPage.click_on_image(driver) ProductPage.click_on_edit_image_button(driver) BasePage.click_on_object(driver, locator=(By.XPATH, '//*[@title="%s"]', str(file_names[0]))) ProductPage.close_add_image_menu() thumb_image_number = 0 for name in range(1, len(file_names)): ProductPage.click_on_add_image_button(driver) BasePage.click_on_object(driver, locator=(By.ID, 'thumb-image%s', thumb_image_number)) thumb_image_number += 1 ProductPage.click_on_edit_image_button(driver) BasePage.click_on_object(driver, locator=(By.XPATH, '//*[@title="%s"]', str(file_names[name]))) else: log.error('Number of file names out of >= 1 - %s', file_names)
def download_file(driver, file_url): """ Download file :param file_url: full url to downloadable file :param driver: browser web driver """ wait_for_element(driver, Locators.file_upload_button_locator, delay=3) driver.find_element(*Locators.file_upload_button_locator).click() keyboard = Controller() keyboard.press(Key.esc) keyboard.release(Key.esc) driver.find_element(*Locators.file_download_dynamic_locator).send_keys(file_url) alert_message = "Your file was successfully uploaded!" wait_for_alert(driver, alert_message, delay=3) BasePage.alert_accept_click(driver) BasePage.click_on_object(driver, Locators.save_downloaded_file)
def add_new_images_to_store(driver, images_path, *file_names): """ Add images to the opencart store :param driver: browser web driver :param images_path: path to images tuple :param file_names: names of images we wanna to load """ dirname = os.path.dirname(images_path) for arg in file_names: filename = os.path.join(str(dirname), str(arg)) wait_for_element(driver, Locators.image_download_button_locator, delay=3) driver.find_element( *Locators.image_download_button_locator).click() keyboard = Controller() keyboard.press(Key.esc) keyboard.release(Key.esc) driver.find_element( *Locators.image_download_dynamic_locator).send_keys(filename) alert_message = "Success: Your file has been uploaded!" wait_for_alert(driver, alert_message, delay=3) BasePage.alert_accept_click(driver)