Getting a SessionNotCreatedException when running Java Program

Hello all. I am currently doing this test on Android with a Mac

I am doing a very basic test where I can run Appium and display an App on the virtual device. However every time I run the Java Program I get this exception thrown:

org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired     capabilities = Capabilities [{app=src/bookMyShow-ucb.apk, platformVersion=7.0, platformName=Android,   deviceName=Android Simulator}], required capabilities = Capabilities [{}]
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'Bluecarts-MBP.lan', ip: '192.168.86.121', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.2', java.version: '1.8.0_111'
Driver info: driver.version: AndroidDriver
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
    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:601)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    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:241)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:83)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:93)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:72)
    at desiredcap.test(desiredcap.java:25)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Here is my code:

import static org.junit.Assert.*;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.Test;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import org.openqa.selenium.remote.DesiredCapabilities;

public class desiredcap {

@Test
public void test() throws MalformedURLException {
	File appDir = new File("src");
	File app = new File(appDir, "bookMyShow-ucb.apk");
	
	DesiredCapabilities cap = new DesiredCapabilities();
	cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
	cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.0");
	cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Simulator");
	cap.setCapability(MobileCapabilityType.APP, app);
			
	AndroidDriver ad = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub/"), cap);		
    }
}

Thank you all for your help!

What version of appium?

I had trouble with 1.6.3 and using Simulator, and the issue was caused by using a emulator system image that included with Google API. When I used a different image it worked.

Thanks for the reply!

This is on 1.5.3 (App version) I don’t think there is an app version for 1.6.3? That said I will try and use a different image.

This part of the error is interesting.

deviceName=Android Simulator}], required capabilities = Capabilities [{}]

When you open the Android setting on the Appium GUI what is the deviceName you have there?

Device Name in Basic Settings is blank. Could that be the culprit?

Maybe.

I set my deviceName to DeviceName then add the below to my capabilities.

capabilities.setCapability(“deviceName”, “DeviceName”);

When I use a real device I use the below.

capabilities.setCapability(“deviceName”,strAVDName);

So I changed MobileCapabilityType.DEVICE_NAME to just deviceName and still running into the same issue. Does required capabilities have to be filled in as well?

cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, “7.0”);

I believe this should be something like 5.0. or 4.4.

It worked! Thank you so much! But for the platform version why is it 4.4? Doesn’t it have to be the android version on the phone?

It’s not the phone version, it’s the hardware version.

When you create the emulator you select a Hardware version then a image.

Make sense?

Ah yes now that does. Thank you for the help!

hi dduphorn,

it doesnt work on my mac. can you help me via team viewer?