3
votes
public class StartFirstJobTest {

AppiumDriver driver;
@BeforeTest
public void setUp() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName", "F4AZFG07P508");
    //capabilities.setCapability("platformName","Android");
    //capabilities.setCapability("platformVersion", "5.0");
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

When I try to run the test, I get this error.

org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{platformName=Android, deviceName=F4AZFG07P508}], required capabilities = Capabilities [{}] Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000' System info: host: 'MacBook-Pro-Roman.local', ip: 'fe80:0:0:0:77:aef0:77:32%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.3', java.version: '1.8.0_121' Driver info: driver.version: AndroidDriver

I think that I set everything up correctly in the appium (When the inspector starts, the device is installed applications and can be tested)

As a project collector I use Maven

UPD. I'm trying to automate the application. I specified additional capabilities in the code

    @BeforeTest
public void setUp() throws Exception {
    File app = new File("/Users/romanderabin/Downloads/TimeTracker.apk");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName","F4AZFG07P508");
    capabilities.setCapability("platformVersion", "5.0");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("app", app.getAbsolutePath());
    capabilities.setCapability("appPackage", "com.ronasit.timetrackerandroid");
    capabilities.setCapability("appActivity","com.ronasit.timetrackerandroid.MainActivity");
    driver = new AndroidDriver(new URL("http://127.0.0.1:4727/wd/hub/"), capabilities);

and the error is the same

org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{app=/Users/romanderabin/Downloads/TimeTracker.apk, appPackage=com.ronasit.timetrackerandroid, appActivity=com.ronasit.timetrackerandroid.MainActivity, platformVersion=5.0, platformName=Android, deviceName=F4AZFG07P508}], required capabilities = Capabilities [{}] Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000' System info: host: 'MacBook-Pro-Roman.local', ip: 'fe80:0:0:0:77:aef0:77:32%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.3', java.version: '1.8.0_121' Driver info: driver.version: AndroidDriver

at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:69) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604) 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:244) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:144) 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 StartFirstJobTest.setUp(StartFirstJobTest.java:30) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138) at org.testng.TestRunner.beforeRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:616) at org.testng.SuiteRunner.runTest(SuiteRunner.java:359) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312) at org.testng.SuiteRunner.run(SuiteRunner.java:261) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1191) at org.testng.TestNG.runSuitesLocally(TestNG.java:1116) at org.testng.TestNG.run(TestNG.java:1024) at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72) at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:127) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Test ignored.

Appium logs when I'm trying start test

[HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"app":"/Users/romanderabin/Downloads/TimeTracker.apk","appPackage":"com.ronasit.timetrackerandroid","appActivity":"com.ronasit.timetrackerandroid.MainActivity","platformVersion":"5.0","platformName":"Android","deviceName":"F4AZFG07P508"},"requiredCapabilities":{},"capabilities":{"desiredCapabilities":{"app":"/Users/romanderabin/Downloads/TimeTracker.apk","appPackage":"com.ronasit.timetrackerandroid","appActivity":"com.ronasit.timetrackerandroid.MainActivity","platformVersion":"5.0","platformName":"Android","deviceName":"F4AZFG07P508"},"requiredCapabilities":{}},"alwaysMatch":{"app":"/Users/romanderabin/Downloads/TimeTracker.apk","appPackage":"com.ronasit.timetrackerandroid","appActivity":"com.ronasit.timetrackerandroid.MainActivity","platformVersion":"5.0","platformName":"Android","deviceName":"F4AZFG07P508"},"firstMatch":[]}

[debug] [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities","sessionId","id"]} and you sent ["desiredCapabilities","requiredCapabilities","capabilities","alwaysMatch","firstMatch"]

[HTTP] <-- POST /wd/hub/session 400 4 ms - 228

7

7 Answers

4
votes

I found the solution to the problem. Update the Appium Java-client version 4.1.2 to 5.0.0 BETA6 and use the Selenium-Java version 3.3.1

1
votes

When handling version compatibility, Maven repository provides Compile Dependencies option. Simply scroll down on Maven Repository website and you will see this section.

0
votes

I hope you are using an Physical Device and not an emulator. In both cases we need to mention either the browser or app file details in the desired capabilities. I assume that you haven't mentioned those things in code as well as in Appium GUI. Below is the sample code for testing for testing an hybrid apk using appium.

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","ANDROID");
capabilities.setCapability("platformVersion", "6");
capabilities.setCapability("platformName",Constant.appPlatform);
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", Constant.appPackage);
capabilities.setCapability("appActivity",Constant.appActivity);
driver = new AndroidDriver(new URL("http://127.0.0.1:4727/wd/hub"), capabilities);  

This code will invoke the application opened in the target device with the mentioned app activity in the desired capabilities.

0
votes

Try changing the device. I changed the device and it worked for me.

0
votes

I had the same issue, beccause I used appPackage from manifest. Should get appPackage from gradle (applicationId).

0
votes

In your IDE, go and run the below command in the terminal

appium --allow-insecure chromedriver_autodownload

This will install the chromedrivers and you are all set to run the code on chrome browsers

0
votes

This could be an issue, since as I understood you are running Appium on the same machine where your client scripts reside, try using "http://127.0.1.1:4723/wd/hub". this solution works for me.

AndroidDriver<AndroidElement> driver = null;
driver = new AndroidDriver<>(new URL("http://127.0.1.1:4723/wd/hub"), capabilities);