1515import base64
1616import unittest
1717
18- import pytest
1918from selenium .common .exceptions import NoSuchElementException , TimeoutException
20- from selenium .webdriver .common .by import By
2119from selenium .webdriver .support import expected_conditions as EC
2220from selenium .webdriver .support .ui import WebDriverWait
2321
2422from appium import webdriver
23+ from appium .webdriver .common .mobileby import MobileBy
2524from test .functional .android .helper import desired_capabilities
2625
26+ from ..helper .test_helper import wait_for_element
27+
2728
28- @pytest .mark .skip (reason = "Need to fix broken test" )
2929class FindByImageTests (unittest .TestCase ):
3030
3131 def setUp (self ):
32- desired_caps = desired_capabilities .get_desired_capabilities ('ApiDemos-debug.apk' )
32+ desired_caps = desired_capabilities .get_desired_capabilities ('ApiDemos-debug.apk.zip ' )
3333 self .driver = webdriver .Remote ('http://localhost:4723/wd/hub' , desired_caps )
3434
3535 # relax template matching
@@ -42,13 +42,10 @@ def tearDown(self):
4242
4343 def test_find_based_on_image_template (self ):
4444 image_path = desired_capabilities .PATH ('file/find_by_image_success.png' )
45- print (image_path )
4645 with open (image_path , 'rb' ) as png_file :
4746 b64_data = base64 .b64encode (png_file .read ()).decode ('UTF-8' )
4847
49- el = WebDriverWait (self .driver , 3 ).until (
50- EC .presence_of_element_located ((By .IMAGE , b64_data ))
51- )
48+ el = wait_for_element (self .driver , MobileBy .IMAGE , b64_data )
5249 size = el .size
5350 self .assertIsNotNone (size ['width' ])
5451 self .assertIsNotNone (size ['height' ])
@@ -62,16 +59,14 @@ def test_find_based_on_image_template(self):
6259 self .assertIsNotNone (rect ['y' ])
6360 self .assertTrue (el .is_displayed ())
6461 el .click ()
65- self .driver . find_element_by_accessibility_id ( "Alarm" )
62+ wait_for_element ( self .driver , MobileBy . ACCESSIBILITY_ID , "Alarm" )
6663
6764 def test_find_multiple_elements_by_image_just_returns_one (self ):
68- WebDriverWait (self .driver , 3 ).until (
69- EC .presence_of_element_located ((By .ACCESSIBILITY_ID , "App" ))
70- )
65+ wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , "App" )
7166 image_path = desired_capabilities .PATH ('file/find_by_image_success.png' )
7267 els = self .driver .find_elements_by_image (image_path )
7368 els [0 ].click ()
74- self .driver . find_element_by_accessibility_id ( "Alarm" )
69+ wait_for_element ( self .driver , MobileBy . ACCESSIBILITY_ID , "Alarm" )
7570
7671 def test_find_throws_no_such_element (self ):
7772 image_path = desired_capabilities .PATH ('file/find_by_image_failure.png' )
@@ -80,7 +75,7 @@ def test_find_throws_no_such_element(self):
8075
8176 with self .assertRaises (TimeoutException ):
8277 WebDriverWait (self .driver , 3 ).until (
83- EC .presence_of_element_located ((By .IMAGE , b64_data ))
78+ EC .presence_of_element_located ((MobileBy .IMAGE , b64_data ))
8479 )
8580 with self .assertRaises (NoSuchElementException ):
8681 self .driver .find_element_by_image (image_path )
0 commit comments