def clear_object(driver, locator): """ Clear and object field :param driver: browser web driver :param locator: object locator """ wait_for_element(driver, locator) driver.find_element(*locator).clear()
def click_on_object(driver, locator): """ Click on object by locator :param driver: browser web driver :param locator: object locator """ wait_for_element(driver, locator) driver.find_element(*locator).click()
def send_keys(driver, locator, some_keys): """ Send keys to the object :param locator: object locator :param driver: browser web driver :param some_keys: keys we want to send """ wait_for_element(driver, locator) driver.find_element(*locator).send_keys(some_keys)
def check_images_names(driver, images_names): """ Check that images with names in 'image_names' are used in product :param driver: browser web driver :param images_names: list of images names """ opencart_url = "'http://192.168.110.60/opencart/image/cache/catalog/" for image in images_names: image_xpath = "//img[@src=" + opencart_url + image + "-100x100.jpg']" wait_for_element(driver, (By.XPATH, image_xpath)) driver.find_element(By.XPATH, image_xpath) log.info("All elements has been found")
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 click_on_all_object_from_many(driver, locator, attribute, attribute_value): """ Find and click on object from many objects by it attribute value :param driver: browser web driver :param locator: object locator :param attribute: object attribute :param attribute_value: object attribute value """ wait_for_element(driver, locator) buttons = driver.find_elements(*locator) for button in buttons: data = button.get_attribute(str(attribute)) if data == attribute_value: button.click() else: continue
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)