Skip to main content

Basic Test Case

In this tutorial we will walk through converting an existing Appium script to use AI with SmartDriver

Install Dependencies

If you haven't done so already, please install appium and devtools

You will first need to install Appium

npm install -g appium

Next, install DevTools.

pip install Appium-Python-Client
pip install devtools-ai

Integrate SmartDriver

To get started, simply import and add SmartDriver to your existing test script.

note

You will need to change "API_KEY" to the api key you get in the dashboard.

from devtools_ai.appium import SmartDriver

driver = SmartDriver(driver, "??API_KEY??")

Sample Test

As an example, we will start with a basic appium test case that will launch the Reddit is Fun app, and click the new section. You can see the SmartDriver lines added to the script.

import time
import unittest
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

from devtools_ai.appium import SmartDriver


def _main() -> None:
"""Main driver"""
desired_caps = dict(
platformName='Android',
automationName='uiautomator2',
deviceName='emulator-5554',
app='/path/to/app.apk' # <-- Replace with a valid APK path
)
appium_driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

driver = SmartDriver(appium_driver, "??API_KEY??")

done_button = driver.find_element(by=AppiumBy.XPATH, value='//*[@text="DONE"]')
done_button.click()
time.sleep(1)

new_button = driver.find_element(by=AppiumBy.XPATH, value='//*[@text="NEW"]')
new_button.click()
time.sleep(1)


if __name__ == "__main__":
_main()

Adding Element Names

SmartDriver allows you to add element names for given selectors by passing it in as an optional paramater. This is useful when managing elements in the dashboard UI.

# Find the searchbox and send "hello world"
done_button = driver.find_element(
by=AppiumBy.XPATH, value='//*[@text="DONE"]', element_name="done_button")

Adding Test Case Names

SmartDriver allows you to add a name for your test case. This is used in the dashboard for grouping all of your element.

To add a test case name, pass it in when initializing the SmartDriver.

# Convert appium_driver to smartDriver
driver = SmartDriver(appium_driver, "??API_KEY??", {"test_case_name": "My test case"})