Skip to main content

Basic Test Case

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

Install Dependencies

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

pip install selenium
pip install devtools-ai
pip install webdriver_manager # Optional: Used to auto-install ChromeDriver

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 of Dev Tools in action, we will use a basic selenium test case that goes to Google and searches for hello world. You can see the SmartDriver lines added to the script.

from time import sleep

from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

from devtools_ai.selenium import SmartDriver

def _main() -> None:
"""Main driver"""
chrome_driver = Chrome(service=Service(ChromeDriverManager().install()))

# Convert chrome_driver to smartDriver
driver = SmartDriver(chrome_driver, "??API_KEY??")

# Navigate to Google.com
driver.get("https://google.com")
sleep(1)

# Find the searchbox and send "hello world"
searchbox_element = driver.find_element(By.NAME, 'q')
searchbox_element.send_keys("hello world\n")

sleep(2)

driver.quit()


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"
searchbox_element = driver.find_element_by_name("q", element_name="searchbox")

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 chrome_driver to smartDriver
driver = SmartDriver(chrome_driver, "??API_KEY??", {"test_case_name": "My test case"})