15
15
import base64
16
16
import unittest
17
17
18
- import pytest
19
18
from selenium .common .exceptions import NoSuchElementException , TimeoutException
20
- from selenium .webdriver .common .by import By
21
19
from selenium .webdriver .support import expected_conditions as EC
22
20
from selenium .webdriver .support .ui import WebDriverWait
23
21
24
22
from appium import webdriver
23
+ from appium .webdriver .common .mobileby import MobileBy
25
24
from test .functional .android .helper import desired_capabilities
26
25
26
+ from ..helper .test_helper import wait_for_element
27
+
27
28
28
- @pytest .mark .skip (reason = "Need to fix broken test" )
29
29
class FindByImageTests (unittest .TestCase ):
30
30
31
31
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 ' )
33
33
self .driver = webdriver .Remote ('http://localhost:4723/wd/hub' , desired_caps )
34
34
35
35
# relax template matching
@@ -42,13 +42,10 @@ def tearDown(self):
42
42
43
43
def test_find_based_on_image_template (self ):
44
44
image_path = desired_capabilities .PATH ('file/find_by_image_success.png' )
45
- print (image_path )
46
45
with open (image_path , 'rb' ) as png_file :
47
46
b64_data = base64 .b64encode (png_file .read ()).decode ('UTF-8' )
48
47
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 )
52
49
size = el .size
53
50
self .assertIsNotNone (size ['width' ])
54
51
self .assertIsNotNone (size ['height' ])
@@ -62,16 +59,14 @@ def test_find_based_on_image_template(self):
62
59
self .assertIsNotNone (rect ['y' ])
63
60
self .assertTrue (el .is_displayed ())
64
61
el .click ()
65
- self .driver . find_element_by_accessibility_id ( "Alarm" )
62
+ wait_for_element ( self .driver , MobileBy . ACCESSIBILITY_ID , "Alarm" )
66
63
67
64
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" )
71
66
image_path = desired_capabilities .PATH ('file/find_by_image_success.png' )
72
67
els = self .driver .find_elements_by_image (image_path )
73
68
els [0 ].click ()
74
- self .driver . find_element_by_accessibility_id ( "Alarm" )
69
+ wait_for_element ( self .driver , MobileBy . ACCESSIBILITY_ID , "Alarm" )
75
70
76
71
def test_find_throws_no_such_element (self ):
77
72
image_path = desired_capabilities .PATH ('file/find_by_image_failure.png' )
@@ -80,7 +75,7 @@ def test_find_throws_no_such_element(self):
80
75
81
76
with self .assertRaises (TimeoutException ):
82
77
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 ))
84
79
)
85
80
with self .assertRaises (NoSuchElementException ):
86
81
self .driver .find_element_by_image (image_path )
0 commit comments