Unable to execute Test Suite using TestNG and webdriver in appium

1,495 views
Skip to first unread message

Jitendra kumar

unread,
Apr 3, 2014, 3:13:29 AM4/3/14
to appium-...@googlegroups.com
Hi All,

I have crated two Test scripts using selenium web driver and Test NG but i am not able to run both test cases from test suite.

TestSuite Code -

<suite name="RegSmokeAutomation" verbose="1">

<test name="SmokeAutomation" preserve-order="true">

<class name="com.optumhealth.ehp.reg.Test1" />

<class name="com.optumhealth.ehp.reg.Test2" />

</classes>

</test>

</suite>

 
First test execute successfully on second test i am getting exception.

I am getting below exception -

org.openqa.selenium.WebDriverException: 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: 15 milliseconds

Build info: version: '2.21.0', revision: '16552', time: '2012-04-11 19:09:00'

System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.2', java.version: '1.6.0_65'

Driver info: driver.version: RemoteWebDriver

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

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

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

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

at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:95)

at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:103)

at com.optumhealth.ehp.reg.Test2.setUp(Test2.java:43)

... Removed 30 stack frames


If i am override the existing session (Appium> Preferneces> Override existing session)then i am getting below exception -


error: Failed to start an Appium session, err was: Error: Instruments crashed on startup


info: Cleaning up appium session

info: Error: Instruments crashed on startup

    at Instruments.onInstrumentsExit (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/lib/instruments.js:351:31)

    at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/lib/instruments.js:294:12)

    at ChildProcess.EventEmitter.emit (events.js:98:17)

    at Process.ChildProcess._handle.onexit (child_process.js:797:12)

info: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Instruments crashed on startup)","origValue":"Instruments crashed on startup"},"sessionId":null}


POST /wd/hub/session 500 37911ms - 210b

Sumeet

unread,
Apr 3, 2014, 8:40:44 AM4/3/14
to appium-...@googlegroups.com
Hi Jitendra,

You can't execute both script at a time.
Try to execute one script, then restart server, and then execute second script.

U can also improve your code script, by calling driver.quit(); from tearDown() method of your script. I think this call will shutdown server at the end of first script. 

Thanks,
Sumeet.

Jitendra kumar

unread,
Apr 3, 2014, 10:33:44 AM4/3/14
to appium-...@googlegroups.com
So We can not create test suite in appium using testNG and webdriver. What I understand from your comment is - I can
execute only one script at a time then i have to restart the server then i can execute the another script.Please let me know
if my understanding is correct.

Sumeet

unread,
Apr 3, 2014, 2:38:51 PM4/3/14
to appium-...@googlegroups.com
you can easily write script by using Appium and TestNG.  I told you about execution of script.
On execution of script, api try to create a new session, but already one session created on first script execution. Thats why you are getting error on second script execution.

You can ask, if still any thing is not clear to you..

Jitendra kumar

unread,
Apr 4, 2014, 12:51:31 AM4/4/14
to appium-...@googlegroups.com
Hi Sumeet,
 
Thanks for reply. Can you please guide me how I can write test suite in appium using TestNG and selenium webdriver.
 
Actually I am new to these frameworks. Really appreciate !!
 
 
Thanks,
Jitendra

Sumeet

unread,
Apr 4, 2014, 1:03:59 AM4/4/14
to appium-...@googlegroups.com
TestNG simply a plugin in eclipse, which will be use to execute script.
you can write appium script in any language, like java, ruby, etc.
Once you write your script, then you can run that script in any way like as TestNG test, etc.
Still have any doubt, then do one thing, paste here your two script, which you already written.

Thanks,
Sumeet.

Jitendra kumar

unread,
Apr 4, 2014, 1:21:43 AM4/4/14
to appium-...@googlegroups.com
Script1 -

package com.optumhealth.ehp.reg;


import java.net.URL;

import java.util.concurrent.TimeUnit;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.remote.CapabilityType;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;


import com.optumhealth.ehp.util.UIConstants;


public class Test1 implements UIConstants {

private static final String JavascriptExecutor = null;

public WebDriver wd = null;


@BeforeMethod

public void setUp() throws Exception {


// set up appium

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");

capabilities.setCapability(CapabilityType.VERSION, "6.1");

capabilities.setCapability(CapabilityType.PLATFORM, "Mac");

capabilities.setCapability("device", "iPhone Retina (4-inch 64-bit)");

capabilities.setCapability("app", "/Users/jitendrakumar/Desktop/Helath4MeApp_Prd/ConsumerTransparency.app");

wd = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);


}


@AfterMethod

public void tearDown() throws Exception {

}

@Test

public void testSecond() throws InterruptedException {

wd.findElement(By.xpath("//window[3]/alert[1]/tableview[1]/cell[1]")).click();

wd.findElement(By.xpath("//window[1]/scrollview[1]/button[2]")).click();

wd.findElement(By.name("Back")).click();

}


}




Script 2

package com.optumhealth.ehp.reg;


import java.net.URL;

import java.util.concurrent.TimeUnit;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.remote.CapabilityType;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;


import com.optumhealth.ehp.util.UIConstants;


public class Test2 implements UIConstants {

private static final String JavascriptExecutor = null;

public WebDriver wd = null;


@BeforeMethod

public void setUp() throws Exception {


DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");

capabilities.setCapability(CapabilityType.VERSION, "6.1");

capabilities.setCapability(CapabilityType.PLATFORM, "Mac");

capabilities.setCapability("device", "iPhone Retina (4-inch 64-bit)");

capabilities.setCapability("app", "/Users/jitendrakumar/Desktop/Helath4MeApp_Prd/ConsumerTransparency.app");

wd = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);



}


@AfterMethod

public void tearDown() throws Exception {

}


//Guest

@Test

public void testHome() throws InterruptedException {

wd.findElement(By.xpath("//window[1]/scrollview[1]/button[5]")).click();

//wd.findElement(By.name("Skip Login")).click();

wd.findElement(By.xpath("//window[1]/button[2]")).click();

}


}


Suite.XMl

<?xml version="1.0" encoding="UTF-8"?>

<suite name="RegSmokeAutomation" verbose="1">


<test name="SmokeAutomation" preserve-order="true">

<classes>

<class name="com.optumhealth.ehp.reg.Test1" />

<class name="com.optumhealth.ehp.reg.Test2" />

</classes>

</test>

</suite>




Sumeet

unread,
Apr 4, 2014, 2:10:58 AM4/4/14
to appium-...@googlegroups.com
Hi Jitendra,
You are doing write thing, code seems to be perfect for script execution.
Just do below mention changes in both script:
(1.) In tearDown() method try to include this line in both script:
                   wd.quit();
(2.) Try to use this line to assign an instance of RemoteWebDriver:
                   wd = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

Now try to run both script one by one, and see whats happening.

Thanks,
Sumeet.
Script1 -

</blockquote
...

Jitendra kumar

unread,
Apr 4, 2014, 3:15:46 AM4/4/14
to appium-...@googlegroups.com
Steps done so far -

1) put the wd.quit in tearDown().
2)Started the Appium server manually n click of Launch button 
3)Executed the first TC - Test1 with TestNG and it was passed.
4) iPhone simulator is gone as we called the wd.quit.
5)Executed the Test2 with testNg and Script failed and got below exception -

FAILED CONFIGURATION: @BeforeMethod setUp

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

Build info: version: '2.21.0', revision: '16552', time: '2012-04-11 19:09:00'


6)This time i have not started the server manual... if i am starting the server with launch button again then Test2 is also passed.

7) I have not changed the port coz appium is running on 0.0.0.0 and on 127.0.0..0 i am getting startup issue


Please let me know where i am doing mistake.



Thanks,

Jitendra


Thanks,
Script1 -

<p
...

Sumeet

unread,
Apr 4, 2014, 5:30:12 AM4/4/14
to appium-...@googlegroups.com
Hi JItendra,

Try to find issue in Appium log also, becoz I am able to run multiple script with same code, which you shared.

Thanks,
Sumeet.

Thanks,
Script1 -

<p style="line-height:normal;font-family:Courier;margin-bottom:0px"
...

Jitendra kumar

unread,
Apr 4, 2014, 7:45:07 AM4/4/14
to appium-...@googlegroups.com
How you have executed ....are you starting server manually each time before executing the script.

Thanks,
Script1 -

<p
...

Jitendra kumar

unread,
Apr 4, 2014, 2:01:03 PM4/4/14
to appium-...@googlegroups.com

debug: Appium request initiated at /wd/hub/session


warn: [DEPRECATED] The device capability has been deprecated and will be removed.  Please use the platformName capability instead.

info: [INSTSERVER] Instruments exited with code 255


info: Attempting to retry launching instruments, this is retry #3

info: Attempting to run app on iPhone Retina (4-inch) - Simulator - iOS 6.1

info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -w iPhone Retina (4-inch) - Simulator - iOS 6.1 /Users/jitendrakumar/Desktop/Helath4MeApp_Prd/ConsumerTransparency.app -e UIASCRIPT /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments

info: And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/thirdparty/iwd/InstrumentsShim.dylib","LIB_PATH":"/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/thirdparty/iwd"}

info: And launch timeout: 90000ms


debug: Appium request initiated at /wd/hub/status


info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.17.6","revision":"7b32947e166a4338047f31ac14457c2b0eb432aa"}},"sessionId":"4c0bb729-671e-4637-877a-2e8c5ba08c4c"}


debug: Request received with params: {}


GET /wd/hub/status 200 1ms - 199b


debug: Appium request initiated at /wd/hub/status


info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.17.6","revision":"7b32947e166a4338047f31ac14457c2b0eb432aa"}},"sessionId":"4c0bb729-671e-4637-877a-2e8c5ba08c4c"}


debug: Request received with params: {}


GET /wd/hub/status 200 1ms - 199b


info: [INST STDERR] Instruments Usage Error : Unknown hardware device specified: iPhone Retina (4-inch) - Simulator - iOS 6.1



info: [INST] Known Devices:

       


info: [INST] Jitendra Kumar’s MacBook Pro (com.apple.instruments.devices.local)

       iPhone - Simulator - iOS 7.1

iPhone Retina (3.5-inch) - Simulator - iOS 7.1

iPhone Retina (4-inch) - Simulator - iOS 7.1

iPhone Retina (4-inch 64-bit) - Simulator - iOS 7.1

iPad - Simulator - iOS 7.1

iPad Retina - Simulator - iOS 7.1

iPad Retina (64-bit) - Simulator - iOS 7.1



error: Instruments crashed on startup


info: [INSTSERVER] Instruments exited with code 255


info: Killall instruments

info: Stopping iOS log capture

info: Killing the simulator process


debug: Sending command to instruments: au.bundleId()


info: Instruments launched. Starting poll loop for new commands.

info: Pushing command to appium work queue: "au.bundleId()"

info: Killing any other simulator daemons


info: Cleaning app state.


info: No folders found to remove


error: Failed to start an Appium session, err was: Error: Instruments crashed on startup


info: Cleaning up appium session

info: Error: Instruments crashed on startup

    at Instruments.onInstrumentsExit (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/lib/instruments.js:351:31)

    at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/lib/instruments.js:294:12)

    at ChildProcess.EventEmitter.emit (events.js:98:17)

    at Process.ChildProcess._handle.onexit (child_process.js:797:12)

info: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Instruments crashed on startup)","origValue":"Instruments crashed on startup"},"sessionId":null}

POST /wd/hub/session 500 38034ms - 210b


debug: Appium request initiated at /wd/hub/status


info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.17.6","revision":"7b32947e166a4338047f31ac14457c2b0eb432aa"}}}


debug: Request received with params: {}


GET /wd/hub/status 200 1ms - 144b


debug: Appium request initiated at /wd/hub/status


info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.17.6","revision":"7b32947e166a4338047f31ac14457c2b0eb432aa"}}}


debug: Request received with params: {}


GET /wd/hub/status 200 1ms - 144b

...

Jeevan Reddy

unread,
Apr 4, 2014, 2:43:02 PM4/4/14
to appium-...@googlegroups.com


Hi,

This is my testNG.xml file and i have totally 3 test cases in these two class files and i was able to run all test cases.

<?xml version="1.0" encoding="UTF-8"?>

<suite name="Testing" verbose="1">

<test name="Tetsing two Test case">

<classes>

<class name="com.test.testcripts.TestCase1" />

<class name="com.test.testcripts.TestCase2"/>

</classes>

</test>

</suite>


By looking at your XML file i can see u missed <classes> tag.

in @AfterMethod :

try to use driver.quit();


OutPut:

===============================================

Testing

Total tests run: 3, Failures: 0, Skips: 0

===============================================

Thanks,

Jeevan

Jitendra kumar

unread,
Apr 4, 2014, 3:03:51 PM4/4/14
to appium-...@googlegroups.com
Hi jeevan,

i am getting issue on server startup. If i execute Test1 and then i am trying to run test2 with starting the server manually(from launch button of appium) i am getting error that 

error: Failed to start an Appium session, err was: Error: Instruments crashed on startup


info: Cleaning up appium session

info: Error: Instruments crashed on startup

    at Instruments.onInstrumentsExit (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/lib/instruments.js:351:31)

    at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/lib/instruments.js:294:12)

    at ChildProcess.EventEmitter.emit (events.js:98:17)

    at Process.ChildProcess._handle.onexit (child_process.js:797:12)

info: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Instruments crashed on startup)","origValue":"Instruments crashed on startup"},"sessionId":null}

POST /wd/hub/session 500 38034ms - 210b

Jeevan Reddy

unread,
Apr 4, 2014, 3:08:46 PM4/4/14
to appium-...@googlegroups.com
I think once the appium server is up and running , the only thing we have to do is just run the test SUITE thats all.

No need to run the server again right, its still running in the background.

Thanks,
Jeevan

Jitendra kumar

unread,
Apr 4, 2014, 3:09:26 PM4/4/14
to appium-...@googlegroups.com
once first script is passed then server try 3 attempt to run the second script 
and then getting issue - unable error: Failed to start an Appium session, err was: Error: Instruments crashed on startup


info: [INSTSERVER] Instruments exited with code 255


info: Attempting to retry launching instruments, this is retry #2

info: Attempting to run app on iPhone Retina (4-inch) - Simulator - iOS 6.1

info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -w iPhone Retina (4-inch) - Simulator - iOS 6.1 /Users/jitendrakumar/Desktop/Helath4MeApp_Prd/ConsumerTransparency.app -e UIASCRIPT /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments

info: And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/thirdparty/iwd/InstrumentsShim.dylib","LIB_PATH":"/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/thirdparty/iwd"}

info: And launch timeout: 90000ms


Jeevan Reddy

unread,
Apr 4, 2014, 3:15:46 PM4/4/14
to appium-...@googlegroups.com

Just add your test cases to one class file and run it as testng test and see how it works.
Also show us the @BeforeMethod &@AfterMethods.

Thanks,
Jeevan

Jitendra kumar

unread,
Apr 4, 2014, 3:17:02 PM4/4/14
to appium-...@googlegroups.com

wd.quit();

}

@Test

public void testSecond() throws InterruptedException {

wd.findElement(By.xpath("//window[3]/alert[1]/tableview[1]/cell[1]")).click();

wd.findElement(By.xpath("//window[1]/scrollview[1]/button[2]")).click();

wd.findElement(By.name("Back")).click();

}


}



Jitendra kumar

unread,
Apr 4, 2014, 3:21:25 PM4/4/14
to appium-...@googlegroups.com
I am not clear on point - add two class in one . Can you give me one example.

Jeevan Reddy

unread,
Apr 4, 2014, 3:42:23 PM4/4/14
to appium-...@googlegroups.com
public class Testing{

@BeforeMethod
/////

@Test
public void testCase1(){
//
}
public void testCase2(){
//
}
@AfterMethod
///

Jitendra kumar

unread,
Apr 7, 2014, 10:34:28 AM4/7/14
to appium-...@googlegroups.com
HiJeevan,

I have tried below script but still getting issue. Problem which i found is control is not going on AfterTest method..i put couple of SOP and find that once AfterMethod is called then webdriver moves to first method again while it should call AfterTest.(tearDown method)..Below is output of same  -


//Optput of SOP


inside testSecond

Finish testSecond

inside testFirst

Finish testFirst

Finish After Method




public class Test_Mac_Skip_Login_iPhone_Multiple implements UIConstants {

public WebDriver wd = null;


@BeforeTest

public void setUp() throws Exception {


// set up appium

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");

capabilities.setCapability(CapabilityType.VERSION, "6.1");

capabilities.setCapability(CapabilityType.PLATFORM, "Mac");

capabilities.setCapability("device", "iPhone Retina (4-inch 64-bit)");

capabilities.setCapability("app", "/Users/jitendrakumar/Desktop/Helath4MeApp_Prd/ConsumerTransparency.app");

wd = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

}

@BeforeMethod

@Test

public void testSecond() throws InterruptedException {

System.out.println("inside testSecond");

wd.findElement(By.xpath("//window[3]/alert[1]/tableview[1]/cell[1]")).click();

wd.findElement(By.xpath("//window[1]/scrollview[1]/button[5]")).click();

wd.findElement(By.xpath("//window[1]/button[2]")).click();

System.out.println("Finish testSecond");

Thread.sleep(10000);

}

@Test

public void testFirst() throws InterruptedException {

System.out.println("inside testFirst");

wd.findElement(By.xpath("//window[1]/scrollview[1]/button[2]")).click();

wd.findElement(By.name("Back")).click();

System.out.println("Finish testFirst");

Thread.sleep(10000);

}

@AfterMethod

public void finish(){

System.out.println("Finish After Method");

}

@AfterTest

public void tearDown() throws Exception {

System.out.println("inside tear down");

wd.close();

//wd.quit();

Jitendra kumar

unread,
Apr 11, 2014, 5:35:40 AM4/11/14
to appium-...@googlegroups.com
Can some body help me to resolve this issue.
Reply all
Reply to author
Forward
0 new messages