Can Selenium run directly (without adb) on Android devices?

Viewed 3515

I'm writing a web test automation app for Android, and wondering if there is a way to run chromedriver (Selenium) directly on the Android device (or bundle it with my app). I realize the normal way is to run chromedriver on a PC and connect to Android devices with adb. But I would prefer my users not have to install the Android SDK, and be able to run tests on native devices even when no PC is available.

Does anyone know a way to do this? If not - would it be possible to implement the WebDriver protocol in an Android app? Are there any open-source projects that have already attempted to do so?

2 Answers

You can use Appium, an open source tool that implements the WebDriver protocol, to automate Android (and iOS) web testing.

I'm not sure if that answers your question specifically about running "chromedriver (Selenium) directly on the Android device", but that is how I've automated mobile testing in the past.

To run web tests on mobile device you need to use Appium as a server.

1) Install Appium and start the appium server

2) Connect your mobile device with developer options activated and USB debugging enabled.

3) Create instance of RemoteWebDriver with appropriate capabilities:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "MyDevice");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
RemoteWebDriver driver = new RemoteWebDriver("http://localhost:4723/wd/hub", capabilities);

Use this instance of driver same way as you did with ChromeDriver.

Related