Use within Android
Before launching / test setup
Add gptdriver-client into the libraries inside libs.versions.toml file:
[libraries]
// ...
gptdriver-client = { group = "io.mobileboost.gptdriver", name = "gptdriver-client", version = "1.0.11" }
// ...
Add gptdriver-client into the dependencies array inside build.gradle.kts (:app) file:
dependencies {
// ...
implementation(libs.gptdriver.client)
// ...
}
If needed, add packaging exclude rules in the android section of the build.gradle.kts (:app) file
To resolve build failures caused by duplicate metadata files from dependencies, exclude them from the packaging process.
android {
// ...
packaging {
resources {
excludes.addAll(listOf("META-INF/INDEX.LIST", "META-INF/io.netty.versions.properties"))
}
}
// ...
}
If not already present, add internet permissions to the AndroidManifest.xml file
GPT Driver testing setup requires Appium to interact with the emulator. Since Appium operates via HTTP, ensure explicit network access is available.
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- ... -->
<application
android:usesCleartextTraffic="true">
<!-- ... -->
</application>
<uses-permission android:name="android.permission.INTERNET" />
<!-- ... -->
</manifest>
Before launching the tests, start appium locally
appium --base-path /wd/hub
Inside the test file
Import necessary dependencies
import io.mobileboost.gptdriver.GptDriver
import io.mobileboost.gptdriver.types.Platform
Create the GPT Driver instance and start the session
val sdkInstance = GptDriver(
"<api_key>",
Platform.Android,
"http://10.0.2.2:4723/wd/hub"
)
Use execute method to perform AI-driven steps:
sdkInstance.execute("Tap on the home button and verify it leads to the main screen")
Simple test example:
class TestWithGptDriver {
@get:Rule
val activityRule = ActivityScenarioRule(MainActivity::class.java)
private lateinit var sdkInstance: GptDriver
@Before
fun setUp() {
sdkInstance = GptDriver(
"<api_key>",
Platform.Android,
"http://10.0.2.2:4723/wd/hub"
)
}
@Test
fun basicLoginTest() {
sdkInstance.execute("Log into the app with credentials: username=test, password=test")
sdkInstance.assertCondition("You are on the home screen")
sdkInstance.setSessionStatus("success")
}
}
Last updated