1
+ import logging
1
2
import os
2
3
import time
3
4
@@ -50,15 +51,27 @@ def is_text_visible(self, text):
50
51
if self .type is DeviceType .EMU or self .type is DeviceType .ANDROID :
51
52
is_visible = Adb .is_text_visible (id = self .id , text = text )
52
53
if self .type is DeviceType .SIM :
53
- # Try to find text with macOS automation
54
54
is_visible = SimAuto .is_text_visible (self , text )
55
- # Retry find with ORC if macOS automation fails
56
- if not is_visible :
57
- is_visible = Simctl .is_text_visible (id = self .id , text = text )
58
55
if self .type is DeviceType .IOS :
59
56
is_visible = IDevice .is_text_visible (id = self .id , text = text )
57
+
58
+ # Retry find with ORC if macOS automation fails
59
+ if not is_visible :
60
+ actual_text = self .get_text ()
61
+ if text in actual_text :
62
+ is_visible = True
63
+ else :
64
+ Log .info ('Current text on {0}: {1}{2}' .format (self .id , os .linesep , actual_text ))
65
+
60
66
return is_visible
61
67
68
+ def get_text (self ):
69
+ img_name = "actual_{0}_{1}.png" .format (self .id , time .time ())
70
+ actual_image_path = os .path .join (Settings .TEST_OUT_IMAGES , img_name )
71
+ File .clean (actual_image_path )
72
+ self .get_screen (path = actual_image_path , log_level = logging .DEBUG )
73
+ return ImageUtils .get_text (image_path = actual_image_path )
74
+
62
75
def wait_for_text (self , text , timeout = 30 , retry_delay = 1 ):
63
76
t_end = time .time () + timeout
64
77
found = False
@@ -72,12 +85,16 @@ def wait_for_text(self, text, timeout=30, retry_delay=1):
72
85
else :
73
86
Log .info (error_msg + ' Waiting ...' )
74
87
time .sleep (retry_delay )
88
+ if not found :
89
+ text = self .get_text ()
90
+ Log .info ('Current text: {0}' .format (text ))
75
91
assert found , error_msg
76
92
77
- def get_screen (self , path ):
93
+ def get_screen (self , path , log_level = logging . INFO ):
78
94
"""
79
95
Save screen of mobile device.
80
96
:param path: Path to image that will be saved.
97
+ :param log_level: Log level.
81
98
"""
82
99
File .clean (path )
83
100
base_path , file_name = os .path .split (path )
@@ -96,7 +113,8 @@ def get_screen(self, path):
96
113
if size > 10 :
97
114
image_saved = True
98
115
if image_saved :
99
- Log .info ("Image of {0} saved at {1}" .format (self .id , path ))
116
+ message = "Image of {0} saved at {1}" .format (self .id , path )
117
+ Log .log (level = log_level , message = message )
100
118
else :
101
119
message = "Failed to save image of {0} saved at {1}" .format (self .id , path )
102
120
Log .error (message )
@@ -117,7 +135,7 @@ def screen_match(self, expected_image, tolerance=0.1, timeout=30):
117
135
diff_image = None
118
136
while time .time () < t_end :
119
137
actual_image = expected_image .replace ('.png' , '_actual.png' )
120
- self .get_screen (path = actual_image )
138
+ self .get_screen (path = actual_image , log_level = logging . DEBUG )
121
139
result = ImageUtils .image_match (actual_image = actual_image ,
122
140
expected_image = expected_image ,
123
141
tolerance = tolerance )
@@ -139,13 +157,13 @@ def screen_match(self, expected_image, tolerance=0.1, timeout=30):
139
157
Log .info ('Expected image not found!' )
140
158
Log .info ('Actual image will be saved as expected: ' + expected_image )
141
159
time .sleep (timeout )
142
- self .get_screen (path = expected_image )
160
+ self .get_screen (path = expected_image , log_level = logging . DEBUG )
143
161
assert False , "Expected image not found!"
144
162
145
163
def get_pixels_by_color (self , color ):
146
164
image_path = os .path .join (Settings .TEST_OUT_IMAGES , self .name ,
147
165
'screen_{0}.png' .format (int (time .time () * 1000 )))
148
- self .get_screen (image_path )
166
+ self .get_screen (image_path , log_level = logging . DEBUG )
149
167
return ImageUtils .get_pixels_by_color (image_path , color )
150
168
151
169
# noinspection PyShadowingBuiltins
@@ -170,7 +188,7 @@ def wait_for_color(self, color, pixel_count, delta=10, timeout=30):
170
188
171
189
def get_main_color (self ):
172
190
image_path = os .path .join (Settings .TEST_OUT_IMAGES , self .name , 'screen_{0}.png' .format (int (time .time () * 1000 )))
173
- self .get_screen (image_path )
191
+ self .get_screen (image_path , log_level = logging . DEBUG )
174
192
return ImageUtils .get_main_color (image_path )
175
193
176
194
# noinspection PyUnresolvedReferences
0 commit comments