def set_local_storage_key(self, key, value): try: self.driver.execute_script( "window.localStorage.setItem({}, {});".format(key, value)) except Exception: log_message("Setting local storage key failed")
def scroll_to_element(self, element): try: self.driver.execute_script("arguments[0].scrollIntoView();", element) except Exception: log_message("Scrolling to {} failed".format(element))
def hover_over_element(self, element): try: hover = ActionChains(self.driver).move_to_element(element) hover.perform() except Exception: log_message("Hovering on {} failed".format(element))
def test_successful_login(self): log_message("TEST 6 - Logirati se u aplikaciju") self.account_page.navigate_to_page() self.account_page.login(test_data.VALID_STORE_NAME, test_data.VALID_PASSWORD) self.shop_page.wait_for_shop_to_load() self.shop_page.save_screenshot("test_successful_login") self.assertTrue(self.shop_page.empty_order_button)
def test_navigate_to_shameless_posts(self): log_message( "Navigates to Shameless blog posts and verifies that the topic label is Shameless." ) self.blog_page.navigate_to_page() self.blog_page.shameless_link.click() self.blog_page.save_screenshot("shameless") self.assertTrue(self.blog_page.topic_label.text == "Shameless")
def test_login_without_store_name(self): log_message("Test without store name") self.account_page.navigate_to_page() self.account_page.password_input.send_keys(test_data.VALID_PASSWORD) self.account_page.register_button.click() time.sleep(5) self.assertTrue(self.account_page.info_label.text == "Input fields can't be blank")
def test_deletion_incorrect_password(self): log_message("Test 5 - Cannot delete account with incorrect password") self.account_page.navigate_to_page() self.account_page.store_name_input.send_keys(test_data.VALID_STORE_NAME) self.account_page.password_input.send_keys(test_data.INVALID_PASSWORD) self.account_page.delete_button.click() time.sleep(5) self.assertTrue(self.account_page.info_label.text == "Wrong password, try again.")
def test_cant_login_with_wrong_pass(self): log_message("Cannot login with wrong password") self.account_page.navigate_to_page() self.account_page.store_name_input.send_keys(test_data.VALID_STORE_NAME) self.account_page.password_input.send_keys(test_data.INVALID_PASSWORD) self.account_page.login_button.click() time.sleep(5) self.assertTrue(self.account_page.info_label.text == "Wrong password, try again.")
def save_screenshot(self, title): timestamp = str(int(time.time())) image_name = title + "_" + timestamp + ".png" image_path = constants.SCREENSHOT_DIR + image_name try: self.driver.save_screenshot(image_path) log_screenshot(image_path) except Exception: log_message("Saving screenshot failed")
def __get_elements(self, locator_value, expected_condition, timeout): locator = locator_value[0] value = locator_value[1] condition = expected_condition try: elements: [WebElement] = WebDriverWait(self.driver, timeout).until( condition((locator, value))) return elements except Exception: log_message("Getting {} failed".format(value))
def test_registration_with_same_user(self): log_message("Test registration with existing username") timestamp_random = helpers.get_timestamp() self.account_page.navigate_to_page() self.account_page.store_name_input.send_keys(test_data.VALID_STORE_NAME) self.account_page.password_input.send_keys(test_data.VALID_PASSWORD) self.account_page.register_button.click() time.sleep(5) self.assertTrue(self.account_page.info_label.text == "User already exists")
def test_register_new_user(self): log_message("Register new user") timestamp_random = helpers.get_timestamp() self.account_page.navigate_to_page() self.account_page.store_name_input.send_keys("Andrej" + timestamp_random) self.account_page.password_input.send_keys(test_data.VALID_PASSWORD) self.account_page.register_button.click() time.sleep(5) self.assertTrue(self.account_page.info_label.text == "User registered")
def browser_go_back(self): try: self.driver.execute_script("window.history.go(-1)") except Exception: log_message("Going back failed")