I’m trying to create a test for Appium 2.0 using the appium library version 9.3.0. Unfortunately there are virtually no consistent samples that show how to write an Android test in Kotlin using Gradle, so I have to figure all of this out and fix stuff in existing samples that were written for older versions of Appium.
This is my test code (in part):
import android.provider.Settings.Global.DEVICE_NAME
import io.appium.java_client.android.AndroidDriver
import io.appium.java_client.remote.AutomationName
import io.appium.java_client.remote.MobilePlatform
import junit.framework.TestCase.assertTrue
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME
import org.openqa.selenium.remote.DesiredCapabilities
import java.net.URL
class MyTests {
private lateinit var driver: AndroidDriver<*>
private const val DEFAULT_APPIUM_ADDRESS = "http://0.0.0.0:4723"
fun makeDriver(): AndroidDriver {
val capabilities = DesiredCapabilities()
capabilities.setCapability(PLATFORM_NAME, MobilePlatform.ANDROID)
capabilities.setCapability(AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2)
capabilities.setCapability(DEVICE_NAME, "Android Emulator")
capabilities.setCapability("appium:appPackage", "com.android.settings")
capabilities.setCapability("appium:appActivity", ".Settings")
return AndroidDriver(URL(DEFAULT_APPIUM_ADDRESS), capabilities)
}
}
The line of code for setting AUTOMATION_NAME indicates that AUTOMATION_NAME doesn’t exist.
Correct me if I’m wrong, but with Appium 2.0 drivers were separated from the Appium server. This would imply that if you use the Android driver, it would automatically know that AutomationName.ANDROID_UIAUTOMATOR2
would be used and therefore became unnecessary for the library to include this anymore. Or am I wrong and I simply am not using the correct library? MobileCapabilityType
no longer exists in the 9.x.x driver, so I assume that AutomationName.ANDROID_UIAUTOMATOR2
is no longer needed.