Skip to content

Commit c63204d

Browse files
committed
android fixes
1 parent 0b70f58 commit c63204d

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

toolium/driver_wrapper.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,13 @@ def connect_selenium(self):
244244
# Save app_strings in mobile tests
245245
if (self.is_mobile_test() and not self.is_web_test()
246246
and self.config.getboolean_optional('Driver', 'appium_app_strings')):
247-
self.app_strings = self.driver.app_strings()
247+
try:
248+
self.app_strings = self.driver.app_strings()
249+
self.logger.debug('App strings retrieved successfully: %d strings found', len(self.app_strings))
250+
except Exception as exc:
251+
# app_strings() may not be available in some Appium/UIAutomator2 versions or configurations
252+
self.logger.warning("Could not retrieve app_strings: %s. Continuing without app strings.", str(exc))
253+
self.app_strings = {}
248254

249255
# Resize and move browser
250256
self.resize_window()

toolium/utils/driver_utils.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,39 @@ def swipe(self, element, x, y, duration=0):
343343
if self.driver_wrapper.is_web_test() or initial_context != 'NATIVE_APP':
344344
center = self.get_native_coords(center)
345345

346-
# Android needs absolute end coordinates and ios needs movement
347-
end_x = x if self.driver_wrapper.is_ios_test() else center['x'] + x
348-
end_y = y if self.driver_wrapper.is_ios_test() else center['y'] + y
349-
self.driver_wrapper.driver.swipe(center['x'], center['y'], end_x, end_y, duration)
346+
if self.driver_wrapper.is_android_test():
347+
end_x = center['x'] + x
348+
end_y = center['y'] + y
349+
350+
width = abs(end_x - center['x'])
351+
height = abs(end_y - center['y'])
352+
353+
if abs(x) > abs(y):
354+
direction = 'right' if x > 0 else 'left'
355+
else:
356+
direction = 'down' if y > 0 else 'up'
357+
358+
self.driver_wrapper.driver.execute_script('mobile: swipeGesture', {
359+
'left': int(center['x'] - width/2) if width > 0 else int(center['x']),
360+
'top': int(center['y'] - height/2) if height > 0 else int(center['y']),
361+
'width': int(width) if width > 0 else 100,
362+
'height': int(height) if height > 0 else 100,
363+
'direction': direction,
364+
'percent': 1.0,
365+
'speed': max(500, 5000 - duration) if duration > 0 else 5000
366+
})
367+
else:
368+
if abs(x) > abs(y):
369+
direction = 'right' if x > 0 else 'left'
370+
else:
371+
direction = 'down' if y > 0 else 'up'
372+
373+
web_element = self.get_web_element(element)
374+
375+
self.driver_wrapper.driver.execute_script('mobile: swipe', {
376+
'direction': direction,
377+
'element': web_element
378+
})
350379

351380
if self.driver_wrapper.is_web_test() or initial_context != 'NATIVE_APP':
352381
self.driver_wrapper.driver.switch_to.context(initial_context)

0 commit comments

Comments
 (0)