Running multiple testcase present in a single testsuite to be run on single device one after another without starting another appium insatnces

Hello guys,

Running multiple testcase present in a single testsuite to be run on single device one after another without starting another appium insatnces.

I tried running multiple testcases by keeping them in a single test suite but it run the first testcase successfully fails with another testcase giving stackstrace stating a new session cannot be started.

Is there any possible way to run multiple testcases on single device (Real android devices or IOS simulator) without starting multiple appium instances

Here are the log:

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: 9 milliseconds

Build info: version: β€˜2.45.0’, revision: β€˜32a636c’, time: β€˜2015-03-05 22:01:35’

System info: host: β€˜Anand-Mac-mini.local’, ip: β€˜192.168.1.12’, os.name: β€˜Mac OS X’, os.arch: β€˜x86_64’, os.version: β€˜10.10.3’, java.version: β€˜1.8.0_25’

Driver info: io.appium.java_client.ios.IOSDriver

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:408)

at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)

at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)

at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)

at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)

at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)

at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)

at io.appium.java_client.AppiumDriver.(AppiumDriver.java:109)

at io.appium.java_client.ios.IOSDriver.(IOSDriver.java:23)

at misc.Util.initAppium(Util.java:60)

at testcases.FindParkingTest.test(FindParkingTest.java:46)

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:483)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

at org.junit.runners.Suite.runChild(Suite.java:127)

at org.junit.runners.Suite.runChild(Suite.java:26)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

at org.junit.runners.Suite.runChild(Suite.java:127)

at org.junit.runners.Suite.runChild(Suite.java:26)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

at org.junit.runner.JUnitCore.run(JUnitCore.java:160)

at org.junit.runner.JUnitCore.run(JUnitCore.java:138)

at org.junit.runner.JUnitCore.run(JUnitCore.java:117)

at org.junit.runner.JUnitCore.runMain(JUnitCore.java:96)

at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:47)

at org.junit.runner.JUnitCore.main(JUnitCore.java:40)

at testcases.runnerIOSTestCases.main(runnerIOSTestCases.java:13)

I tried searching any question here but unable to find anything
Help will be alot appreciated.

Thanks Anand

It was not able to create a session because, the session used for first test case was not closed. But you are trying to create new driver session.

I am not sure if it can span multiple test classes in a test suite. But you can atleast make it run all test cases[methods] within a Test class file.

Create session in setup method of test class and kill it in tear down. Have a single instance of driver per class.

Running multiple tests in a single suite can also be achieved by closing the APP(application under test) and relaunching it, below code snippet if placed in @AfterTest can be helpful

driver.closeApp();
driver.launchApp();

This helps to use the same session for all the tests in the suite saving us the time to instantiate the appium server session for every test.

@RamS
Thanks for quick reply.
I am trying to run a testsuite that contains 12 testcases through Continuous integeration and I have implemented my every testcases with setup and teardown method. But I was thinking to initiate the appium server in my first testcases and all the testcase could get run with the same appium instance.

@somasekhar
Thanks for the reply
driver.closeApp();
this code is not working with appium server.

@ravisingh171989
What error do you get when calling this method.I am able to get it running smoothly on Android platform using Appium server 1.3.4.1 and Java client 2.1.0 but have not tried on IOS. Check if you are making call to this method after switching to NATIVE context?

Can you also please paste the log for the error you observe.

Thanks
Somasekhar

Hi ,

I tried using above driver.launchApp() and driver.closeApp() but unable to launch the app again after the completion of the one test. I want to run multiple tests in one suite .

each test has start method which initiates appium driver and one tearDown method which uses both methods mentioned above but after completion of one test its stopping and nothing is happening at the console.

I used driver.quit() method in tearDown method followed by after test annotation ,it was working fine and control goes to second test but got nosuch element exception and due to that ,app crashed.

Please help on this.

Thanks,
Ranjan

Hi Ranjan @Ranjan_Gupta

Even I am facing the same issue as mentioned above please let me know if you get the solution for the same.

1 Like

Running to the same issue! was it ever resolved?

This works for me:
public static AndroidDriver driver;
Dimension size;

static String Appium_Node_Path = "C:\\Program Files (x86)\\Appium\\node.exe";
static String Appium_JS_Path = "C:\\Program Files (x86)\\Appium\\node_modules\\appium\\bin\\appium.js";
static AppiumDriverLocalService service;
static String service_url;

public static void appiumStart() throws Exception {
	service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingPort(0)
				.usingDriverExecutable(new File(Appium_Node_Path)).withAppiumJS(new File(Appium_JS_Path)));
	service.start();
	Thread.sleep(25000);
	service_url = service.getUrl().toString();

	System.out.println("Appium Server Started with URL: " + service_url.toString());
}

public static void appiumStop() throws Exception {
	service.stop();
	System.out.println("Appium Server Stopped..");
}

@BeforeTest
public void setUp() throws Exception {
	// Stop appium server If It Is already running.
	/* appiumStop(); */
	// Start appium server.
	appiumStart();

	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability("deviceName", "192.168.223.101:5555");
	// capabilities.setCapability("browserName", "Android");
	// capabilities.setCapability("platformVersion", "6.0");
	// capabilities.setCapability("platformName", "Android");
	capabilities.setCapability("appPackage", "com.hmh.api");
	capabilities.setCapability("appActivity", "com.hmh.api.ApiDemos");

	driver = new AndroidDriver<AndroidElement>(new URL(service_url), capabilities);
	driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}

@AfterMethod
public void afterMethod()
{
	driver.closeApp();
	driver.launchApp();
}

@AfterTest
public void End() throws Exception {
	driver.quit();		
	// Stop appium server when test Is ended.
	appiumStop();
}