Appium with SeleniumGrid (testNG) : org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: deviceName)

Here is the textNG.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd”>
<suite name=”Suite” parallel=”tests” thread-count=”5″ verbose=”1″>
<test name=”Test1″>
<parameter name=”device_id” value=”36C35E3F00B8B341″><!–id of Samsung galaxy note –>
<classes>
<class name=”avaamo_android.Master_avaamo” />
<class name=”avaamo_android.Conversation” />
</classes>
</parameter>
</test> <!– Test –>
<test name=”Test2″>
<parameter name=”device_id” value=”2636b827a05e6bb3″><!–id of nexus rooted – 2636b827a05e6bb3 –>
<classes>
<class name=”avaamo_android.Master_avaamo” />
<class name=”avaamo_android.Conversation” />
</classes>
</parameter>
</test> <!– Test –>
</suite> <!– Suite –>

Following is the java file:
####Imports and class level declarations*******

//To fetch network details
public static String networkConnection=””;

@BeforeSuite//The annotated method will be run before all tests in this suite have run.
@Parameters({“device_id”})
public static WebDriver atStart(@Optional (“Abc”) String device_id) throws InterruptedException, IOException
{
//setup property with webdriver to create/cutomize a session with webdriver
DesiredCapabilities capabilities = new DesiredCapabilities();
System.out.println(“”+device_id);
if (“36C35E3F00B8B341″.equals(device_id))
{

try
{
writer = new FileWriter(“..\\Avaamoo\\DataFile\\avaamoMessagePerformanceResults.csv”);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} // windows machine

writer.write(“Network Type”);
writer.write(‘,’);
writer.write(“File Type”);
writer.write(‘,’);
writer.write(“File Size”);
writer.write(“,”);
writer.write(“Total Time Taken to send file (in MS)”);
writer.write(“,”);
writer.write(‘\n’);

//Load the excel file to fetch data
try
{
importData();
}
catch (Exception e)
{
e.printStackTrace();
}

File app = new File(applicationPath);
capabilities.setCapability(“automationName”, “Appium”);
capabilities.setCapability(CapabilityType.BROWSER_NAME, “Android”);

//samsung-sm_n750-3204da2a5075c0b5//micromax-micromax_a311-8a2d363//samsung-nexus_s-30345C56DC2000EC
capabilities.setCapability(“deviceName”, “samsung-sm_n750-3204da2a5075c0b5″);
capabilities.setCapability(“platformVersion”, “4.4.2”);//Or//capabilities.setCapability(CapabilityType.VERSION, “4.1.2”);
capabilities.setCapability(CapabilityType.PLATFORM, “WINDOWS”);
capabilities.setCapability(“platformName”, “ANDROID”);//Or//capabilities.setCapability(CapabilityType.PLATFORM, “Android”);
capabilities.setCapability(“app”, app.getAbsolutePath());
capabilities.setCapability(“appPackage”, “com.avaamo.android.staging”); //Replace with your app’s package
capabilities.setCapability(“appActivity”, “com.avaamo.android.ui.LandingActivity”); //Replace with app’s Activity

//setting new command timeout for selenium server
capabilities.setCapability(“newCommandTimeout”, “2000000”);//33.33 mins
//implement logging from -http://loggingselenium.sourceforge.net/usage.html
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
}

It is throwing the error as follows:
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: deviceName) (WARNING: The server did not provide any stacktrace information)

Could you please tell me whats going wrong?
I have already mentioned the capabilities that have been suggested.

Add Comment
2 Answer(s)

capabilities.setCapability(CapabilityType.BROWSER_NAME, “Android”); // This says to launch browser here u need to pass Chrome,Chromium etc

capabilities.setCapability(“deviceName”, “samsung-sm_n750-3204da2a5075c0b5″); // this says device name it should be same as

type command adb devices
this output should go in deviceName

Note : Browser works only for android version 4.4 + with latest chromedriver.exe 2.5 present in
…\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\build\chromedriver\windows

Try once like this

import io.appium.java_client.remote.MobileBrowserType;
import io.appium.java_client.remote.MobileCapabilityType;

DesiredCapabilities cap = new DesiredCapabilities();
//cap.setCapability(MobileCapabilityType.DEVICE_NAME,”ZX1B32HNBD”);
cap.setCapability(MobileCapabilityType.BROWSER_NAME,MobileBrowserType.CHROME);
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION,”4.4.4″);
cap.setCapability(MobileCapabilityType.PLATFORM_NAME,”Android”);

amitjain Supporter Answered on April 16, 2015.
Add Comment

Thanks Amit !

I updated the script as per your suggestion.

The issue I am facing is, The value passed from xml to testscript is caught null.

Can you please suggest me the possible solution?

JRE 1.8.0_40 is used.

thitenitin Train Answered on April 16, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.