I was trying to setup automation on macbook for android application using selenium webdriver and appium.
Here is my code :-
package com.tas.androidtest;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import junit.framework.Assert;
public class MyFirstAppiumDroidTest {
public static void main(String[] args) throws MalformedURLException {
File appDir= new File(System.getProperty("user.dir")+"/app");
File app= new File(appDir, "selendroid-test-app-0.17.0.apk");
//declaring Andriod platform properties
DesiredCapabilities capa = new DesiredCapabilities();
capa.setCapability("deviceName","Android");
capa.setCapability("platformVersion", "6.0.1");
capa.setCapability("platformName",MobilePlatform.ANDROID);
capa.setCapability("app", app.getAbsolutePath());
capa.setCapability("appPackage", "io.selendriod.testapp");
capa.setCapability("appActivity","io.selendriod.testapp.HomeScreenActivity");
//instantiating Andriod driver
AndroidDriver driver= new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"),capa);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElementById("io.selendroid.testapp:id/startUserRegistration").clear();
driver.findElementById("io.selendroid.testapp:id/inputUsername").sendKeys("test");
driver.findElement(By.id("io.selendroid.testapp:id/inputEmail")).sendKeys("test@mail.com");
driver.findElement(By.id("io.selendroid.testapp:id/inputPassword")).sendKeys("12345");
driver.hideKeyboard();
driver.findElement(By.id("io.selendroid.testapp:id/input_adds")).click();
driver.findElement(By.id("io.selendroid.testapp:id/btnRegisterUser")).click();
Assert.assertEquals("napendra", driver.findElement(By.id("io.selendroid.testapp:id/label_username_data")).getText());
driver.quit();
System.out.print("Completed !!!");
}
}
I Have started the appium server and run the test using with maven but I am getting error everytime I run the test.
Here is the error :-
Exception in thread “main” org.openqa.selenium.WebDriverException:
Unable to parse remote response: Parameters were incorrect. We wanted
{“required”:[“desiredCapabilities”],“optional”:[“requiredCapabilities”,“sessionId”,“id”]}
and you sent [“desiredCapabilities”,“capabilities”] Build info:
version: ‘3.7.1’, revision: ‘8a0099a’, time:
‘2017-11-06T21:01:39.354Z’ System info: host:
‘Users-MacBook-Air.local’, ip: ‘192.xxx.xxx.xxx’, os.name: ‘Mac OS X’,
os.arch: ‘x86_64’, os.version: ‘10.11.6’, java.version: '1.8.0_91’
Driver info: driver.version: AndroidDriver at
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:111)
at
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at
io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:69)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
at
io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at
io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142)
at
io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:36)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:114)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:132)
at
io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:92)
at
com.tas.androidtest.MyFirstAppiumDroidTest.main(MyFirstAppiumDroidTest.java:52)