I am using Java + Selenium with Appium to test a Cordova app but I think I can at least get you going down the right path here. In my experience, it helps to view the components involved (Test script + Appium + App in test + Device) as independent items that get glued together at runtime. What I mean is that all four of those things are separate executables and they only get connected to each other once you call [ var driver = new webdriver … ] in your test script (which means you have to turn your test script into an executable).
I am going to attach some of my Java code as an example in a moment but first I’m going to talk through some more details in plain English. When I am running a test against my App, the steps before anything starts are:
- Have the .apk to be tested somewhere on the file system of your host machine (I believe there is a way to hook into an app already on the device but this adds complications)
- Have a device or emulator hooked up and running (knowing the device ID might help)
- Start an Appium server (take note of the IP address it says it is running on)
Now you are ready to execute your test script which upon startup will establish a WebDriver/AppiumDriver. While you are already doing this in your example, you should provide a few more Capabilities so that everything gets connected. Below is the Java equivalent of webdriver.withCapabilities() which basically says:
“I am making a new WebDriver. The app I want to test is located at file path xxx/xxx.apk… The device I want to test it on is ID xxxx and the Appium server to make that happen is at IP xxxx” The moment your test script says “new WebDriver” with those capabilities, all of the independent components are now connected… The apk will get loaded onto the device and start; the Appium server will begin listening for Selenium commands (through your new Webdriver) to pass through to the Android device.
Here is that Java code:
File appDir = new File("/FooAppsFolder/");
File app = new File(appDir, “app-debug.apk”);
DesiredCapabilities capabilities = new DesiredCapabilities();
driver = new AndroidDriver(new URL(“http://0.0.0.0:” + appiumPort + “/wd/hub”), capabilities);
Of course all of this assumes that you already have the PATHs and Android tools such as ADB configured properly.
I hope that made sense / helps get you moving in the right direction.
Good Luck and Happy Testing!