Test Skipped everytime in Selenium Grid in Appium

Hi, I am using selenium grip in appium and connected two device with my project by everytime whenever run testNG.xml only one test run and other test skips…and the case that skip is of that device whose appium server run in the last. Please suggest me what to do and where I have to change.
Details are here:
TestNG xml-

Code
public class testing {
static AppiumDriver driver;

@Parameters({ "device","version" })
@BeforeClass
public void setup(String device,String version) throws IOException {

	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("appPackage", "com.android.settings");
	capabilities.setCapability("appActivity", ".Settings");
	capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,
			"Android");
	capabilities
			.setCapability(MobileCapabilityType.PLATFORM_VERSION,version);
	capabilities.setCapability("udid", device);
	capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,
			"Micromax");
	driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
			capabilities);
}

@AfterClass
public void teardown() throws IOException {
	driver.quit();

}

@Test()
public void Call() throws Exception {
	Thread.sleep(2000);
	System.out.println("end call");
}

public static AppiumDriver getdriver() {
	return driver;
}

}

output of testNG:

… TestNG 6.9.11 by Cédric Beust ([email protected])

[TestNG] Running:
E:\Project\Eclipse\AppiumForWeb\testng.xml

[ThreadUtil] Starting executor timeOut:2147483647ms workers:2 threadPoolSize:5
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\AppiumForWeb\App2 Under Test .html
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\AppiumForWeb exists: true
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\AppiumForWeb\App2 Under Test .xml
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\AppiumForWeb exists: true
FAILED CONFIGURATION: @BeforeClass setup(“c65368bf”, “5.0.2”)
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Requested a new session but one was in progress) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 447 milliseconds
Build info: version: ‘2.48.2’, revision: ‘41bccdd’, time: ‘2015-10-09 19:59:12’
System info: host: ‘SANDY-PC’, ip: ‘192.168.0.109’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.8.0_91’
Driver info: io.appium.java_client.android.AndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:156)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:109)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:39)
at testing.setup(testing.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:143)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:778)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.access$000(SuiteRunner.java:39)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:400)
at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

SKIPPED CONFIGURATION: @AfterClass teardown
SKIPPED: Call

===============================================
App2 Under Test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1

end call
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\AppiumForWeb\App1 Under Test .html
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\AppiumForWeb exists: true
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\AppiumForWeb\App1 Under Test .xml
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\AppiumForWeb exists: true
PASSED: Call

===============================================
App1 Under Test
Tests run: 1, Failures: 0, Skips: 0

===============================================
AppiumForWeb
Total tests run: 2, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1

[TestNG] Time taken by org.testng.reporters.XMLReporter@1698539: 40 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@ba2a48: 45 ms
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\junitreports\TEST-testing.xml
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\junitreports exists: true
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@616ca2: 14 ms
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb\toc.html
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb exists: true
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb\App2 Under Test .properties
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb exists: true
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb\App1 Under Test .properties
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb exists: true
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb\index.html
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb exists: true
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb\main.html
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb exists: true
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb\groups.html
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb exists: true
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb\classes.html
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb exists: true
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb\reporter-output.html
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb exists: true
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb\methods-not-run.html
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb exists: true
[Utils] Problem creating output directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb\testng.xml.html
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\old\AppiumForWeb exists: true
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\old\index.html
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\old exists: true
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@f71333: 128 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@3498ed: 137 ms
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\testng-failed.xml
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output exists: true
[Utils] Attempting to create E:\Project\Eclipse\AppiumForWeb\test-output\AppiumForWeb\testng-failed.xml
[Utils] Directory E:\Project\Eclipse\AppiumForWeb\test-output\AppiumForWeb exists: true
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 263 ms

node1.js:

{
“capabilities”:
[
{
“browserName”: “Android”,
“version”:“5.1”,
“udid”:“0123456789ABCDEF”,
“maxInstances”: 1,
“platform”:“ANDROID”,
“deviceName”:“Device”
}],
“configuration”:

{
“cleanUpCycle”:2000,
“timeout”:10000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://0.0.0.0:4723/wd/hub”,
“maxSession”: 5,
“port”: 4723,
“host”: “0.0.0.0”,
“register”: true,
“registerCycle”: 5000,
“hubPort”: 4444,
“hubHost”: “localhost”
}
}

node2.js:
{
“capabilities”:
[
{
“browserName”: “Android”,
“version”:“5.0.2”,
“udid”:“c65368bf”,
“maxInstances”: 1,
“platform”:“ANDROID”,
“deviceName”:“Device”
}],
“configuration”:

{
“cleanUpCycle”:2000,
“timeout”:10000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://0.0.0.0:4724/wd/hub”,
“maxSession”: 5,
“port”: 4724,
“host”: “0.0.0.0”,
“register”: true,
“registerCycle”: 5000,
“hubPort”: 4444,
“hubHost”: “localhost”
}
}

commands for appium server:
node.exe node_modules\appium\bin\appium.js --nodeconfig E:\Project\Eclipse\AppiumForWeb\node1.json -p 4723 –U 0123456789ABCDEF

node.exe node_modules\appium\bin\appium.js --nodeconfig E:\Project\Eclipse\AppiumForWeb\node2.json -p 4724 –U c65368bf

Could this be a timing issue or race condition? Seems like you call driver.quit in the after method, but that the next test starts running before the driver has fully quit. Try adding an implicit wait, like a sleep, and see if that doesn’t fix the issue. I would start with a large wait, like 45 seconds just as an experiment, and then lower it down until you get an optimal value. If you decide to make this your long term solution make sure you comment it so you don’t forget and remove it at some point.

Alternatively, you can get the PID of the Appium process and use an explicit wait that tests if the process has completely finished, but for troubleshooting I’d start as stated above.

@wreed Its not working after using Implicit wait.
Everytime my first device skipped, and test run in second device.
Dont know what happend to the test script.
Please help if possible.
When I use “methods” instead of tests., its working fine.

but for “tests” case run on only one device and show error of “a new session cannot be created…” for another device.

I don’t understand this comment? Admittedly my Java/TestNG is a bit rusty, but are you saying that if you change it to @Method instead of @Test it works fine? I think I’m missing something here.

If I am using this in testNG

suite name=“AppiumGmail” verbose=“1” parallel=“methods” thread-count=“2”
instead of this

suite name=“AppiumGmail” verbose=“1” parallel=“tests” thread-count=“2”

The xml file running perfectly.

Ok, I had to look this up:

parallel=“methods”: TestNG will run all your test methods in separate threads. Dependent methods will also run in separate threads but they will respect the order that you specified.

parallel=“tests”: TestNG will run all the methods in the same tag in the same thread, but each tag will be in a separate thread. This allows you to group all your classes that are not thread safe in the same and guarantee they will all run in the same thread while taking advantage of TestNG using as many threads as possible to run your tests.

http://testng.org/doc/documentation-main.html

Can I ask what the problem is with running with parallel=“methods”?