def test_find_multiple_elements_by_image_just_returns_one(self): WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ACCESSIBILITY_ID, "App"))) image_path = desired_capabilities.PATH('find_by_image_success.png') els = self.driver.find_elements_by_image(image_path) els[0].click() self.driver.find_element_by_accessibility_id("Alarm")
def test_find_throws_no_such_element(self): image_path = desired_capabilities.PATH('find_by_image_failure.png') with self.assertRaises(TimeoutException): WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.IMAGE, image_path))) with self.assertRaises(NoSuchElementException): self.driver.find_element_by_image(image_path)
def test_find_throws_no_such_element(self): image_path = desired_capabilities.PATH('find_by_image_failure.png') with open(image_path, 'rb') as png_file: b64_data = base64.b64encode(png_file.read()).decode('UTF-8') with self.assertRaises(TimeoutException): WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.IMAGE, b64_data))) with self.assertRaises(NoSuchElementException): self.driver.find_element_by_image(image_path)
def test_find_based_on_image_template(self): image_path = desired_capabilities.PATH('find_by_image_success.png') el = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.IMAGE, image_path))) size = el.size self.assertIsNotNone(size['width']) self.assertIsNotNone(size['height']) loc = el.location self.assertIsNotNone(loc['x']) self.assertIsNotNone(loc['y']) rect = el.rect self.assertIsNotNone(rect['width']) self.assertIsNotNone(rect['height']) self.assertIsNotNone(rect['x']) self.assertIsNotNone(rect['y']) self.assertTrue(el.is_displayed()) el.click() self.driver.find_element_by_accessibility_id("Alarm")
def test_find_based_on_image_template(self): image_path = desired_capabilities.PATH('find_by_image_success.png') with open(image_path, 'rb') as png_file: b64_data = base64.b64encode(png_file.read()).decode('UTF-8') el = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.IMAGE, b64_data))) size = el.size self.assertIsNotNone(size['width']) self.assertIsNotNone(size['height']) loc = el.location self.assertIsNotNone(loc['x']) self.assertIsNotNone(loc['y']) rect = el.rect self.assertIsNotNone(rect['width']) self.assertIsNotNone(rect['height']) self.assertIsNotNone(rect['x']) self.assertIsNotNone(rect['y']) self.assertTrue(el.is_displayed()) el.click() self.driver.find_element_by_accessibility_id("Alarm")