pumapy 2.0.2__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. {pumapy-2.0.2/pumapy.egg-info → pumapy-2.2.0}/PKG-INFO +8 -3
  2. {pumapy-2.0.2 → pumapy-2.2.0}/puma/apps/android/appium_actions.py +27 -0
  3. pumapy-2.2.0/puma/apps/android/google_maps/google_maps.py +80 -0
  4. {pumapy-2.0.2 → pumapy-2.2.0}/puma/apps/android/telegram/telegram.py +4 -3
  5. pumapy-2.2.0/puma/apps/android/whatsapp/__init__.py +0 -0
  6. {pumapy-2.0.2 → pumapy-2.2.0}/puma/apps/android/whatsapp/whatsapp.py +28 -20
  7. pumapy-2.2.0/puma/version.py +1 -0
  8. {pumapy-2.0.2 → pumapy-2.2.0/pumapy.egg-info}/PKG-INFO +8 -3
  9. {pumapy-2.0.2 → pumapy-2.2.0}/pumapy.egg-info/SOURCES.txt +2 -0
  10. pumapy-2.2.0/pumapy.egg-info/requires.txt +10 -0
  11. {pumapy-2.0.2 → pumapy-2.2.0}/setup.py +7 -2
  12. pumapy-2.0.2/puma/version.py +0 -1
  13. pumapy-2.0.2/pumapy.egg-info/requires.txt +0 -5
  14. {pumapy-2.0.2 → pumapy-2.2.0}/LICENSE.txt +0 -0
  15. {pumapy-2.0.2 → pumapy-2.2.0}/README.md +0 -0
  16. {pumapy-2.0.2 → pumapy-2.2.0}/puma/__init__.py +0 -0
  17. {pumapy-2.0.2 → pumapy-2.2.0}/puma/apps/__init__.py +0 -0
  18. {pumapy-2.0.2 → pumapy-2.2.0}/puma/apps/android/__init__.py +0 -0
  19. {pumapy-2.0.2/puma/apps/android/snapchat → pumapy-2.2.0/puma/apps/android/google_maps}/__init__.py +0 -0
  20. {pumapy-2.0.2/puma/apps/android/telegram → pumapy-2.2.0/puma/apps/android/snapchat}/__init__.py +0 -0
  21. {pumapy-2.0.2 → pumapy-2.2.0}/puma/apps/android/snapchat/snapchat.py +0 -0
  22. {pumapy-2.0.2/puma/apps/android/whatsapp → pumapy-2.2.0/puma/apps/android/telegram}/__init__.py +0 -0
  23. {pumapy-2.0.2 → pumapy-2.2.0}/puma/computer_vision/__init__.py +0 -0
  24. {pumapy-2.0.2 → pumapy-2.2.0}/puma/computer_vision/ocr.py +0 -0
  25. {pumapy-2.0.2 → pumapy-2.2.0}/puma/utils/__init__.py +0 -0
  26. {pumapy-2.0.2 → pumapy-2.2.0}/puma/utils/route_simulator.py +0 -0
  27. {pumapy-2.0.2 → pumapy-2.2.0}/puma/utils/video_utils.py +0 -0
  28. {pumapy-2.0.2 → pumapy-2.2.0}/pumapy.egg-info/dependency_links.txt +0 -0
  29. {pumapy-2.0.2 → pumapy-2.2.0}/pumapy.egg-info/top_level.txt +0 -0
  30. {pumapy-2.0.2 → pumapy-2.2.0}/setup.cfg +0 -0
@@ -1,17 +1,22 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pumapy
3
- Version: 2.0.2
3
+ Version: 2.2.0
4
4
  Home-page: https://github.com/NetherlandsForensicInstitute/puma
5
5
  Author: Netherlands Forensic Institute
6
6
  Author-email: netherlandsforensicinstitute@users.noreply.github.com
7
7
  License: EUPL-1.2
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE.txt
10
- Requires-Dist: appium-python-client==3.1.0
10
+ Requires-Dist: appium-python-client~=4.2.0
11
11
  Requires-Dist: selenium==4.14.0
12
- Requires-Dist: Pillow==10.1.0
12
+ Requires-Dist: Pillow==10.4.0
13
13
  Requires-Dist: pytesseract==0.3.10
14
14
  Requires-Dist: adb-pywrapper==1.0.1
15
+ Requires-Dist: geopy~=2.4.1
16
+ Requires-Dist: setuptools~=75.1.0
17
+ Requires-Dist: gpxpy~=1.6.2
18
+ Requires-Dist: adb_pywrapper~=1.0.1
19
+ Requires-Dist: requests~=2.32.3
15
20
 
16
21
  # Puma - Programmable Utility for Mobile Automation
17
22
 
@@ -1,4 +1,5 @@
1
1
  import os
2
+ import time
2
3
  from datetime import datetime
3
4
  from pathlib import Path
4
5
  from typing import Dict
@@ -12,6 +13,7 @@ from appium.webdriver import WebElement
12
13
  from appium.webdriver.common.appiumby import AppiumBy
13
14
  from appium.webdriver.extensions.android.nativekey import AndroidKey
14
15
  from appium.webdriver.webdriver import WebDriver
16
+ from selenium.common import NoSuchElementException
15
17
 
16
18
  from puma.apps.android import logger
17
19
  from puma.computer_vision import ocr
@@ -89,6 +91,9 @@ class AndroidAppiumActions:
89
91
  def activate_app(self):
90
92
  self.driver.activate_app(self.app_package)
91
93
 
94
+ def app_open(self) -> bool:
95
+ return str(self.driver.current_package) == self.app_package
96
+
92
97
  def __enter__(self):
93
98
  return self
94
99
 
@@ -134,6 +139,28 @@ class AndroidAppiumActions:
134
139
  java_code = f'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector(){resource_id_part}{text_part}{text_contains_part}.instance(0))'
135
140
  return self.driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value=java_code)
136
141
 
142
+ def swipe_to_find_element(self, xpath: str, max_swipes: int = 10) -> WebElement:
143
+ for attempt in range(max_swipes):
144
+ if self.is_present(xpath):
145
+ return self.driver.find_element(AppiumBy.XPATH, xpath)
146
+ else:
147
+ # Element not found, perform swipe down
148
+ print(f"Attempt {attempt + 1}: Element not found, swiping down")
149
+ # Get the window size to determine the swipe dimensions
150
+ window_size = self.driver.get_window_size()
151
+ start_x = window_size['width'] / 2
152
+ start_y = window_size['height'] * 0.8
153
+ end_y = window_size['height'] * 0.2
154
+
155
+ # Perform the swipe down
156
+ self.driver.swipe(start_x, start_y, start_x, end_y, 500)
157
+
158
+ # Wait a bit before the next attempt
159
+ time.sleep(0.5)
160
+
161
+ # If the loop completes, the element was not found
162
+ raise NoSuchElementException(msg=f'After {max_swipes} swipes, cannot find element with xpath {xpath}')
163
+
137
164
  def is_present(self, xpath: str, implicit_wait: int = 0) -> bool:
138
165
  self.driver.implicitly_wait(implicit_wait)
139
166
  found = self.driver.find_elements(by=AppiumBy.XPATH, value=xpath)
@@ -0,0 +1,80 @@
1
+ from enum import Enum
2
+ from time import sleep
3
+ from typing import Dict
4
+
5
+ from appium.webdriver.common.appiumby import AppiumBy
6
+
7
+ from puma.apps.android.appium_actions import AndroidAppiumActions, supported_version
8
+ from puma.utils.route_simulator import RouteSimulator
9
+
10
+ GOOGLE_MAPS_PACKAGE = 'com.google.android.apps.maps'
11
+
12
+
13
+ class TransportType(Enum):
14
+ CAR = "car"
15
+ BIKE = "bike"
16
+
17
+
18
+ @supported_version("11.119.0101")
19
+ class GoogleMapsActions(AndroidAppiumActions):
20
+ def __init__(self,
21
+ device_udid,
22
+ desired_capabilities: Dict[str, str] = None,
23
+ implicit_wait=1,
24
+ appium_server='http://localhost:4723'):
25
+ AndroidAppiumActions.__init__(self,
26
+ device_udid,
27
+ GOOGLE_MAPS_PACKAGE,
28
+ desired_capabilities=desired_capabilities,
29
+ implicit_wait=implicit_wait,
30
+ appium_server=appium_server)
31
+ self.route_simulator = RouteSimulator(self, 0)
32
+
33
+ def _has_search_box(self):
34
+ return self.app_open() and self.is_present('//android.widget.TextView[@text="Search here"]')
35
+
36
+ def _ensure_at_start(self):
37
+ while not self._has_search_box():
38
+ self.driver.back()
39
+ if not self.app_open():
40
+ self.activate_app()
41
+
42
+ def search_place(self, search_string: str):
43
+ self._ensure_at_start()
44
+ self.driver.find_element(by=AppiumBy.XPATH, value='//android.widget.TextView[@text="Search here"]').click()
45
+ search_box_xpath = '//android.widget.EditText[@resource-id="com.google.android.apps.maps:id/search_omnibox_edit_text"]'
46
+ self.driver.find_element(by=AppiumBy.XPATH, value=search_box_xpath).send_keys(search_string)
47
+ first_result = '//android.support.v7.widget.RecyclerView[@resource-id="com.google.android.apps.maps:id/typed_suggest_container"]/android.widget.LinearLayout[1]'
48
+ self.driver.find_element(by=AppiumBy.XPATH, value=first_result).click()
49
+
50
+ def start_navigation(self, search_string: str, transport_type: TransportType = TransportType.CAR, time_to_wait=10):
51
+ self.search_place(search_string)
52
+ directions_xpath = '//android.widget.Button[starts-with(@content-desc, "Directions to")]'
53
+ self.driver.find_element(by=AppiumBy.XPATH, value=directions_xpath).click()
54
+ if transport_type == TransportType.CAR:
55
+ mode = 'Driving mode'
56
+ elif transport_type == TransportType.BIKE:
57
+ mode = 'Bicycling mode'
58
+ multiple_choices_header = '//android.widget.LinearLayout[@resource-id="com.google.android.apps.maps:id/destination_list_header"]'
59
+ if self.is_present(multiple_choices_header):
60
+ # select first option
61
+ first_option = '//android.support.v7.widget.RecyclerView[@resource-id="com.google.android.apps.maps:id/recycler_view"]/android.widget.LinearLayout[1]'
62
+ self.driver.find_element(by=AppiumBy.XPATH, value=first_option).click()
63
+ mode_xpath = f'//android.widget.LinearLayout[starts-with(@content-desc, "{mode}")]'
64
+ self.driver.find_element(by=AppiumBy.XPATH, value=mode_xpath).click()
65
+ start_xpath = '//android.widget.Button[@content-desc="Start driving navigation"]'
66
+ for i in range(time_to_wait):
67
+ if self.is_present(start_xpath):
68
+ self.driver.find_element(by=AppiumBy.XPATH, value=start_xpath).click()
69
+ return
70
+ else:
71
+ sleep(1)
72
+ raise Exception(f'Route was not loaded after {time_to_wait} seconds')
73
+
74
+ def start_route(self, from_query: str, to_query: str, speed: int,
75
+ transport_type: TransportType = TransportType.CAR):
76
+ self.route_simulator.update_speed(0)
77
+ osm_mode = 'car' if transport_type == TransportType.CAR else 'bike'
78
+ self.route_simulator.execute_route_with_queries(from_query, to_query, osm_mode)
79
+ self.start_navigation(to_query, transport_type)
80
+ self.route_simulator.update_speed(speed)
@@ -9,7 +9,7 @@ TELEGRAM_PACKAGE = 'org.telegram.messenger'
9
9
  TELEGRAM_WEB_PACKAGE = 'org.telegram.messenger.web'
10
10
 
11
11
 
12
- @supported_version("10.13.4")
12
+ @supported_version("11.2.2")
13
13
  class TelegramActions(AndroidAppiumActions):
14
14
 
15
15
  def __init__(self,
@@ -234,8 +234,9 @@ class TelegramActions(AndroidAppiumActions):
234
234
  raise Exception('Tried to answer call, but couldn\'t find notification to answer any calls')
235
235
  self.driver.find_element(by=AppiumBy.XPATH,
236
236
  value='//android.widget.Button[lower-case(@content-desc)="answer"]').click()
237
- self.driver.find_element(by=AppiumBy.XPATH,
238
- value='//android.widget.TextView[@resource-id="android:id/title" and @text="Ongoing Telegram call"]').click()
237
+ open_call_button = '//android.widget.TextView[@resource-id="android:id/title" and @text="Ongoing Telegram call"]'
238
+ if self.is_present(open_call_button):
239
+ self.driver.find_element(by=AppiumBy.XPATH, value=open_call_button).click()
239
240
 
240
241
  def decline_call(self):
241
242
  """
File without changes
@@ -3,7 +3,6 @@ from time import sleep
3
3
  from typing import Dict, List, Union
4
4
 
5
5
  from appium.webdriver.common.appiumby import AppiumBy
6
- from appium.webdriver.common.touch_action import TouchAction
7
6
  from selenium.webdriver.common.by import By
8
7
 
9
8
  from puma.apps.android.appium_actions import supported_version, AndroidAppiumActions
@@ -11,7 +10,7 @@ from puma.apps.android.appium_actions import supported_version, AndroidAppiumAct
11
10
  WHATSAPP_PACKAGE = 'com.whatsapp'
12
11
 
13
12
 
14
- @supported_version("2.24.11.79")
13
+ @supported_version("2.24.20.89")
15
14
  class WhatsappActions(AndroidAppiumActions):
16
15
  def __init__(self,
17
16
  device_udid,
@@ -152,7 +151,7 @@ class WhatsappActions(AndroidAppiumActions):
152
151
  message_element = self.driver.find_element(by=AppiumBy.XPATH, value=
153
152
  f"//*[@resource-id='com.whatsapp:id/conversation_text_row']//*[@text='{message_text}']")
154
153
  self._long_press_element(message_element)
155
- self.driver.find_element(by=AppiumBy.XPATH, value='//android.widget.TextView[@content-desc="Delete"]').click()
154
+ self.driver.find_element(by=AppiumBy.XPATH, value='//*[@content-desc="Delete"]').click()
156
155
  self.driver.find_element(by=AppiumBy.XPATH,
157
156
  value="//*[@resource-id='com.whatsapp:id/buttonPanel']//*[@text='Delete for everyone']").click()
158
157
 
@@ -168,7 +167,7 @@ class WhatsappActions(AndroidAppiumActions):
168
167
  self._if_chat_go_to_chat(chat)
169
168
  message_element = self.scroll_to_find_element(text_contains=message_to_reply_to)
170
169
  self._long_press_element(message_element)
171
- self.driver.find_element(by=AppiumBy.XPATH, value='//android.widget.TextView[@content-desc="Reply"]').click()
170
+ self.driver.find_element(by=AppiumBy.XPATH, value='//*[@content-desc="Reply"]').click()
172
171
  text_box = self.driver.find_element(by=AppiumBy.ID, value="com.whatsapp:id/entry")
173
172
  text_box.send_keys(reply_text)
174
173
  self.driver.find_element(by=AppiumBy.ID, value="com.whatsapp:id/send").click()
@@ -213,8 +212,10 @@ class WhatsappActions(AndroidAppiumActions):
213
212
  self.driver.find_element(by=AppiumBy.ID, value="com.whatsapp:id/pickfiletype_gallery_holder").click()
214
213
  self.driver.find_element(by=AppiumBy.XPATH,
215
214
  value='//android.widget.LinearLayout[@content-desc="Gallery"]').click()
216
- self.scroll_to_find_element(text_contains=directory_name).click()
217
- sleep(1)
215
+ directory_tile = f'//android.widget.TextView[@resource-id="com.whatsapp:id/title" and @text="{directory_name}"]'
216
+ self.swipe_to_find_element(xpath=directory_tile).click()
217
+
218
+ sleep(0.5)
218
219
  self.driver.find_element(by=By.CLASS_NAME, value="android.widget.ImageView").click()
219
220
 
220
221
  if caption:
@@ -242,19 +243,16 @@ class WhatsappActions(AndroidAppiumActions):
242
243
  # Press sticker tab
243
244
  # TODO: make coordinates configurable or calculate what they should be
244
245
  # self.press_coordinates(663, 2136) # Pixel 5
245
- self._press_coordinates(663, 2032) # Samsung G955F
246
+ self._click_coordinates(663, 2032) # Samsung G955F
246
247
  sleep(1)
247
248
  # Press sticker
248
249
  # self.press_coordinates(150, 1600) # Pixel 5
249
- self._press_coordinates(128, 1502) # Samsung G955F
250
+ self._click_coordinates(128, 1502) # Samsung G955F
250
251
 
251
- def _press_coordinates(self, x, y):
252
- actions = TouchAction(self.driver)
253
- actions.press(x=x, y=y)
254
- actions.release()
255
- actions.perform()
252
+ def _click_coordinates(self, x, y):
253
+ self.driver.execute_script('mobile: clickGesture', {'x': x, 'y': y})
256
254
 
257
- def send_voice_recording(self, duration: int = 1000, chat: str = None):
255
+ def send_voice_recording(self, duration: int = 2000, chat: str = None):
258
256
  """
259
257
  Sends a voice message in the current conversation.
260
258
  Assumes we are in the conversation in which we want to send the voice message.
@@ -331,6 +329,9 @@ class WhatsappActions(AndroidAppiumActions):
331
329
  self.open_settings_you()
332
330
  self.driver.find_element(by=AppiumBy.ID, value="com.whatsapp:id/change_photo_btn").click()
333
331
  self.driver.find_element(by=AppiumBy.XPATH, value="//*[@text='Gallery']").click()
332
+ gallery_tab = '//android.widget.LinearLayout[@content-desc="Gallery"]'
333
+ if self.is_present(gallery_tab):
334
+ self.driver.find_element(by=AppiumBy.XPATH, value=gallery_tab).click()
334
335
  self.scroll_to_find_element(text_contains=photo_dir_name).click()
335
336
  sleep(1)
336
337
  self.driver.find_element(by=By.CLASS_NAME, value="android.widget.ImageView").click()
@@ -438,7 +439,12 @@ class WhatsappActions(AndroidAppiumActions):
438
439
  """
439
440
  Ends the current call. Assumes the call screen is open.
440
441
  """
441
- self.driver.find_element(by=AppiumBy.ID, value="com.whatsapp:id/footer_end_call_btn").click()
442
+ end_call_button = '//android.widget.Button[@resource-id="com.whatsapp:id/end_call_button"]'
443
+ if not self.is_present(end_call_button):
444
+ # tap screen to make call button visible
445
+ background = '//android.widget.RelativeLayout[@resource-id="com.whatsapp:id/call_screen"]'
446
+ self.driver.find_element(by=AppiumBy.XPATH, value=background).click()
447
+ self.driver.find_element(by=AppiumBy.XPATH, value=end_call_button).click()
442
448
 
443
449
  def answer_call(self):
444
450
  """
@@ -552,11 +558,13 @@ class WhatsappActions(AndroidAppiumActions):
552
558
  :param duration: Duration of the press in millisec.
553
559
  :return:
554
560
  """
555
- long_press = TouchAction(self.driver)
556
- print(f"holding down button for {duration}ms")
557
- long_press.long_press(element, duration=duration)
558
- long_press.release()
559
- long_press.perform()
561
+ location = element.location
562
+ size = element.size
563
+
564
+ # Calculate the center of the element
565
+ x = location['x'] + size['width'] // 2
566
+ y = location['y'] + size['height'] // 2
567
+ self.driver.execute_script('mobile: longClickGesture', {'x': x, 'y': y, 'duration': duration})
560
568
 
561
569
  def leave_group(self, group_name):
562
570
  """
@@ -0,0 +1 @@
1
+ version = "2.2.0"
@@ -1,17 +1,22 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pumapy
3
- Version: 2.0.2
3
+ Version: 2.2.0
4
4
  Home-page: https://github.com/NetherlandsForensicInstitute/puma
5
5
  Author: Netherlands Forensic Institute
6
6
  Author-email: netherlandsforensicinstitute@users.noreply.github.com
7
7
  License: EUPL-1.2
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE.txt
10
- Requires-Dist: appium-python-client==3.1.0
10
+ Requires-Dist: appium-python-client~=4.2.0
11
11
  Requires-Dist: selenium==4.14.0
12
- Requires-Dist: Pillow==10.1.0
12
+ Requires-Dist: Pillow==10.4.0
13
13
  Requires-Dist: pytesseract==0.3.10
14
14
  Requires-Dist: adb-pywrapper==1.0.1
15
+ Requires-Dist: geopy~=2.4.1
16
+ Requires-Dist: setuptools~=75.1.0
17
+ Requires-Dist: gpxpy~=1.6.2
18
+ Requires-Dist: adb_pywrapper~=1.0.1
19
+ Requires-Dist: requests~=2.32.3
15
20
 
16
21
  # Puma - Programmable Utility for Mobile Automation
17
22
 
@@ -6,6 +6,8 @@ puma/version.py
6
6
  puma/apps/__init__.py
7
7
  puma/apps/android/__init__.py
8
8
  puma/apps/android/appium_actions.py
9
+ puma/apps/android/google_maps/__init__.py
10
+ puma/apps/android/google_maps/google_maps.py
9
11
  puma/apps/android/snapchat/__init__.py
10
12
  puma/apps/android/snapchat/snapchat.py
11
13
  puma/apps/android/telegram/__init__.py
@@ -0,0 +1,10 @@
1
+ appium-python-client~=4.2.0
2
+ selenium==4.14.0
3
+ Pillow==10.4.0
4
+ pytesseract==0.3.10
5
+ adb-pywrapper==1.0.1
6
+ geopy~=2.4.1
7
+ setuptools~=75.1.0
8
+ gpxpy~=1.6.2
9
+ adb_pywrapper~=1.0.1
10
+ requests~=2.32.3
@@ -16,10 +16,15 @@ setup(
16
16
  packages=find_packages(include=['puma*']),
17
17
  test_suite="test",
18
18
  install_requires=[
19
- "appium-python-client==3.1.0",
19
+ "appium-python-client~=4.2.0",
20
20
  "selenium==4.14.0",
21
- "Pillow==10.1.0",
21
+ "Pillow==10.4.0",
22
22
  "pytesseract==0.3.10",
23
23
  "adb-pywrapper==1.0.1",
24
+ "geopy~=2.4.1",
25
+ "setuptools~=75.1.0",
26
+ "gpxpy~=1.6.2",
27
+ "adb_pywrapper~=1.0.1",
28
+ "requests~=2.32.3"
24
29
  ],
25
30
  )
@@ -1 +0,0 @@
1
- version = "2.0.2"
@@ -1,5 +0,0 @@
1
- appium-python-client==3.1.0
2
- selenium==4.14.0
3
- Pillow==10.1.0
4
- pytesseract==0.3.10
5
- adb-pywrapper==1.0.1
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes