Examples
Simple script which will connect to an android device via the local appium server.
from gptdriver_client import GptDriver
if __name__ == "__main__":
gptd = GptDriver(
api_key="...",
device_config={
"platform": "Android",
"device_name": "Pixel",
"platform_version": "14.0"
}
)
gptd.start_session()
gptd.execute("Tap on the Gmail app")
gptd.assert_condition("The Gmail app is open")
gptd.stop_session("success")
Sample when you already have an existing webdriver object and pass it to GPT Driver.
from gptdriver_client import GptDriver
from appium import webdriver
if __name__ == "__main__":
options = UiAutomator2Options()
options.load_capabilities({
"platformName": "Android",
"platformVersion": "14.0",
"deviceName": "emulator-5556",
"automationName": "UiAutomator2",
})
driver = webdriver.Remote(
command_executor="http://127.0.0.1:4723",
options=options
)
gptd = GptDriver(
api_key="...",
driver=driver
)
gptd.start_session()
gptd.execute("Tap on the Gmail app")
gptd.assert_condition("The Gmail app is open")
gptd.stop_session("success")
PyTest Example
conftest.py
import pytest
from gptdriver_client import GptDriver
@pytest.fixture()
def with_gpt_driver(request):
# Code executed before the test
gptd = GptDriver(api_key="...", driver=request.param)
gptd.start_session()
yield gptd
# Code executed after the test
gptd.stop_session("success")
test_example.py
import pytest
from appium.options.android import UiAutomator2Options
from appium import webdriver
from conftest import with_gpt_driver
options = UiAutomator2Options()
options.load_capabilities({
"platformName": "Android",
"platformVersion": "15.0",
"deviceName": "my_driver_1",
"automationName": "UiAutomator2",
})
my_driver = webdriver.Remote(command_executor="http://127.0.0.1:4723", options=options)
@pytest.mark.parametrize("with_gpt_driver", [my_driver], indirect=True)
def test_example_1(with_gpt_driver):
gptd = with_gpt_driver
gptd.execute("Tap on the Gmail app and succeed the task immediately")
gptd.assert_condition("The Gmail app is opened")
extracted_data = gptd.extract(["Text visible on the screen"])
print(f"Extracted data: {extracted_data}")
assert len(extracted_data) > 0
@pytest.mark.parametrize("with_gpt_driver", [my_driver], indirect=True)
def test_example_2(with_gpt_driver):
gptd = with_gpt_driver
gptd.execute("Tap on Got it and succeed the task immediately")
gptd.assert_bulk(["Add an email address is visible", "Take me to Gmail is visible"])
extracted_data = gptd.extract(["Text visible on the screen"])
print(f"Extracted data: {extracted_data}")
assert len(extracted_data) > 0
Last updated