-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
baf92ee
commit ea2d3b5
Showing
14 changed files
with
986 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,58 @@ | ||
import asyncio | ||
import base64 | ||
from mobileadapt import mobileadapt | ||
from datetime import datetime | ||
from PIL import Image | ||
import io | ||
import os | ||
from datetime import datetime | ||
|
||
from loguru import logger | ||
''' From the root directory use the following command to start the script: | ||
from PIL import Image | ||
|
||
from mobileadapt import mobileadapt | ||
|
||
""" From the root directory use the following command to start the script: | ||
python example-scripts/examplescript.py | ||
''' | ||
""" | ||
|
||
|
||
async def save_screenshot(screenshot_data, filename): | ||
# Open the screenshot data as an image and save it | ||
image = Image.open(io.BytesIO(screenshot_data)) | ||
image.save(filename) | ||
|
||
|
||
async def main(): | ||
# Create an Android device instance | ||
android_device = mobileadapt(platform="android") | ||
|
||
# Initialize the device (starts the Appium session) | ||
await android_device.start_device() | ||
|
||
# Get the current state of the device | ||
encoded_ui, screenshot, ui = await android_device.get_state() | ||
logger.info(f"Current state: {encoded_ui}") | ||
|
||
# Save the first screenshot | ||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | ||
# filename1 = os.path.join(os.path.dirname(__file__), f"screenshot_before_{timestamp}.png") | ||
#await save_screenshot(screenshot, filename1) | ||
# await save_screenshot(screenshot, filename1) | ||
# print(f"Screenshot saved as {filename1}") | ||
|
||
# Perform a tap action at coordinates (100, 100) | ||
await android_device.tap(100, 100) | ||
|
||
# Get the state again after the tap action | ||
new_encoded_ui, new_screenshot, new_ui = await android_device.get_state() | ||
print("New state after tap:", new_encoded_ui) | ||
|
||
# Save the second screenshot | ||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | ||
filename2 = os.path.join(os.path.dirname(__file__), f"screenshot_after_{timestamp}.png") | ||
filename2 = os.path.join( | ||
os.path.dirname(__file__), f"screenshot_after_{timestamp}.png" | ||
) | ||
await save_screenshot(new_screenshot, filename2) | ||
print(f"Screenshot saved as {filename2}") | ||
|
||
|
||
if __name__ == "__main__": | ||
# Run the main function asynchronously | ||
asyncio.run(main()) | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
from .core import MobileAdapt | ||
from .device.device_factory import DeviceFactory | ||
|
||
def mobileadapt(platform: str, app_url: str = None, state_representation='aria', download_directory='default', session_id=None): | ||
return DeviceFactory.create_device(platform, app_url, state_representation, download_directory, session_id) | ||
|
||
__all__ = ['mobileadapt'] | ||
def mobileadapt( | ||
platform: str, | ||
app_url: str = None, | ||
state_representation="aria", | ||
download_directory="default", | ||
session_id=None, | ||
): | ||
return DeviceFactory.create_device( | ||
platform, app_url, state_representation, download_directory, session_id | ||
) | ||
|
||
|
||
__all__ = ["mobileadapt", "MobileAdapt"] |
File renamed without changes.
Oops, something went wrong.