Ask a Question

How to get test step response in readyAPI using Java?

SOLVED
arunbharath
Contributor

How to get test step response in readyAPI using Java?

Hi All.

     I'm trying to execute ReadyApi test cases from Java. I'm able to execute the test case but I could figure how to retrive the response from test step using java. I need couple of fields from the response to validate externally. Can anyone help me on this? I couldn't find any tutorial or support from the internet. 

 

		try {
			// Create a test runner object
			final SoapUIProTestCaseRunner runner = new SoapUIProTestCaseRunner();

			// Specify the path to the project file
			runner.setProjectFile("C://Work//sampleproject.xml");

			// Specify the test suite to run
			runner.setTestSuite("TestSuite 1");

			// Specify the test case to run
			// It must be in the test suite specified above
			runner.setTestCase("TestCase 1");

			// Run the test
			// Command the runner to create JUnit-style report
			runner.setJUnitReport(true);

			// Command the runner to create printable report
			runner.setPrintReport(true);

			// Command the runner to open the created report
			runner.setOpenReport(true);

			// Specify the folder to save the report in
			runner.setOutputFolder("C:\\Users\\mwl\\tmp");

			// Start the test run
			runner.run();
		}
		// Handle the exception, if any
		catch (final Exception e) {
			e.printStackTrace();
		}
	}

Above is the code. I have used to execute the test cases. any help would be appreciated.

18 REPLIES 18
nmrao
Community Hero

When it is possible to execute the tests using testrunner.bat (.sh) utility of READYAPI_HOME/bin, what are you trying to achieve by writing java? Just trying to understand what testrunner can't do and that is achieved by your program.


Regards,
Rao.

@nmrao  Thanks for you response.

I've got a UI testing scenarios for that I need values from the API response. I used TestNG  framework with java to achieve the UI automation (I know readyAPI supports selenium,, but My case needs a lot of classes, so TestNG is better compared to readyAPI, I believe). So to achieve that, I have to run readyAPI through java and get the response values. I already worked on this by using soapUI, I'm able to achieve that. But when comes to readyAPI, I'm not getting proper documentation for java integration. Any inputs is appreciated.

Here is the Javadoc for ReadyAPI.
https://support.smartbear.com/readyapi/apidocs/soapui/index.html

By the way, could not see in the code presented above where the response of a step. Missing something?


Regards,
Rao.

Yes. Above code is the one I got from the smartbear document. All above methods are void one, so it will not return anything. I'm not sure how to implement retreive the response in the code.

OK. But you mentioned that you were able to got that working with SoapUI. How does that code look like and how were you reading then?


Regards,
Rao.

public void soapRunner() throws Exception {

		testProjectFileNameStr = "C:\\Users\\akrishnan\\git\\et-3.5-automation\\et-3.5-automation";

		proxy = ProxySelector.getDefault();

		// TestUtil.getEnvProperties();

		testSuiteResultJsonArrList = new ArrayList<String>();
		testProjectResultJsonArrList = new ArrayList<String>();
		project = new WsdlProject(testProjectFileNameStr);
		testProjectNameStr = project.getName();

		final WsdlTestSuite testSuite = project.getTestSuiteByName("InitiateTransfer");
		testSuiteDisabled = testSuite.getConfig().getDisabled();

		final int numOfTestCases = testSuite.getTestCaseCount();
		KSU.testSuitesOut(testSuiteNameStr);
		KSU.info("Number Of Test Cases: " + numOfTestCases);
		testCaseResultJsonArrList = new ArrayList<String>();
		if (!testSuiteDisabled) {
			for (int i = 0; i < numOfTestCases; i++) {

				testCase = testSuite.getTestCaseAt(i);

				// testCase.setDisabled(true);
				testCaseNameStr = testCase.getName();

				testCaseDisabled = testCase.getConfig().getDisabled();
				final int countCases = i + 1;
				final int numOfTestSteps = testCase.getTestStepCount();

				KSU.testCasesOut(countCases, testCaseNameStr);
				KSU.info("Number of Test Steps: " + numOfTestSteps);
				testStepResultJsonArrList = new ArrayList<String>();

				if (!testCaseDisabled) {
					for (int j = 0; j < numOfTestSteps; j++) {
						reasonStr = "";
						final WsdlTestStep testStep = testCase.getTestStepAt(j);

						testStepNameStr = testStep.getName();

						final int countSteps = j + 1;
						KSU.testStepsOut(countSteps, testStepNameStr);

						testStepDisabled = testStep.getConfig().getDisabled();

						if (!testStepDisabled) {
							testRunner = new WsdlTestCaseRunner(testCase, null);
							soapResult = testRunner.runTestStepByName(testStepNameStr);

							final Status result = testRunner.getStatus();
							final String resultStr = result.toString();

Above is the code I used for SoapUI and its working fine, now I'm trying to implement soapUI pro. I tried same code by calling soapui-pro test cases , I got below exception

java.util.ServiceConfigurationError: java.sql.Driver: Provider org.olap4j.driver.xmla.XmlaOlap4jDriver could not be instantiated
	at java.util.ServiceLoader.fail(ServiceLoader.java:232)
	at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
	at java.lang.Iterable.forEach(Iterable.java:74)
	at com.eviware.soapui.DefaultSoapUICore.loadJdbcDrivers(DefaultSoapUICore.java:690)
	at com.eviware.soapui.DefaultSoapUICore.loadExternalLibraries(DefaultSoapUICore.java:725)
	at com.eviware.soapui.DefaultSoapUICore.init(DefaultSoapUICore.java:185)
	at com.eviware.soapui.DefaultSoapUICore.<init>(DefaultSoapUICore.java:159)
	at com.eviware.soapui.DefaultSoapUICore.createDefault(DefaultSoapUICore.java:169)
	at com.smartbear.ready.core.ApplicationEnvironment.initDefaultCore(ApplicationEnvironment.java:213)
	at com.smartbear.ready.core.ApplicationEnvironment.getSoapUICore(ApplicationEnvironment.java:182)
	at com.smartbear.ready.core.Registries.getListenerRegistry(Registries.java:16)
	at com.eviware.soapui.impl.wsdl.WsdlProject.addProjectListeners(WsdlProject.java:998)
	at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:317)
	at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:303)
	at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:298)
	at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:286)
	at com.interac.api.emt.test.SoapRunner2.soapRunner(SoapRunner2.java:137)
	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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
	at org.testng.TestRunner.privateRun(TestRunner.java:767)
	at org.testng.TestRunner.run(TestRunner.java:617)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
	at org.testng.SuiteRunner.run(SuiteRunner.java:254)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
	at org.testng.TestNG.run(TestNG.java:1057)
	at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.IllegalAccessException: Class java.util.ServiceLoader$LazyIterator can not access a member of class org.olap4j.driver.xmla.XmlaOlap4jDriver with modifiers "protected"
	at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
	at java.lang.Class.newInstance(Class.java:436)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
	... 41 more

You may be missing a dependency for "XmlaOlap4jDriver" class. Find jar file name and add it to classpath.


Regards,
Rao.

If I fixed that exception. I'm getting failed to load a project exception. I'm trying to load composite project here. I'm not sure is it possible to load composite project with below code

public void soapRunner() throws Exception {

		testProjectFileNameStr = "C:\\Users\\akrishnan\\git\\et-3.5-automation\\et-3.5-automation\\";

		proxy = ProxySelector.getDefault();

		// TestUtil.getEnvProperties();

		testSuiteResultJsonArrList = new ArrayList<String>();
		testProjectResultJsonArrList = new ArrayList<String>();
		project = new WsdlProject(testProjectFileNameStr);
		testProjectNameStr = project.getName();

		final WsdlTestSuite testSuite = project.getTestSuiteByName("InitiateTransfer");
		// testSuiteDisabled = testSuite.getConfig().getDisabled();

		final int numOfTestCases = testSuite.getTestCaseCount();
		KSU.testSuitesOut(testSuiteNameStr);
		KSU.info("Number Of Test Cases: " + numOfTestCases);
		testCaseResultJsonArrList = new ArrayList<String>();
		if (!testSuiteDisabled) {
			for (int i = 0; i < numOfTestCases; i++) {

				testCase = testSuite.getTestCaseAt(i);

				// testCase.setDisabled(true);
				testCaseNameStr = testCase.getName();

				testCaseDisabled = testCase.getConfig().getDisabled();
				final int countCases = i + 1;
				final int numOfTestSteps = testCase.getTestStepCount();

				KSU.testCasesOut(countCases, testCaseNameStr);
				KSU.info("Number of Test Steps: " + numOfTestSteps);
				testStepResultJsonArrList = new ArrayList<String>();

				if (!testCaseDisabled) {
					for (int j = 0; j < numOfTestSteps; j++) {
						reasonStr = "";
						final WsdlTestStep testStep = testCase.getTestStepAt(j);

						testStepNameStr = testStep.getName();

						final int countSteps = j + 1;
						KSU.testStepsOut(countSteps, testStepNameStr);

						testStepDisabled = testStep.getConfig().getDisabled();

						if (!testStepDisabled) {
							testRunner = new WsdlTestCaseRunner(testCase, null);
							soapResult = testRunner.runTestStepByName(testStepNameStr);

							final Status result = testRunner.getStatus();
							final String resultStr = result.toString();
An error occurred [Failed to load project from file [file:/C:/Users/akrishnan/git/et-3.5-automation/et-3.5-automation/]], see error log for details
13:01:17,913 ERROR [errorlog] com.eviware.soapui.support.SoapUIException: Failed to load project from file [file:/C:/Users/akrishnan/git/et-3.5-automation/et-3.5-automation/]
com.eviware.soapui.support.SoapUIException: Failed to load project from file [file:/C:/Users/akrishnan/git/et-3.5-automation/et-3.5-automation/]
	at com.eviware.soapui.impl.wsdl.WsdlProject.loadProject(WsdlProject.java:498) ~[ready-api-soapui-2.8.0.jar:2.8.0]
	at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:324) [ready-api-soapui-2.8.0.jar:2.8.0]
	at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:303) [ready-api-soapui-2.8.0.jar:2.8.0]
	at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:298) [ready-api-soapui-2.8.0.jar:2.8.0]
	at com.eviware.soapui.impl.wsdl.WsdlProject.<init>(WsdlProject.java:286) [ready-api-soapui-2.8.0.jar:2.8.0]
	at com.interac.api.emt.test.SoapRunner2.soapRunner(SoapRunner2.java:137) [classes/:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) [testng-6.8.8.jar:?]
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) [testng-6.8.8.jar:?]
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) [testng-6.8.8.jar:?]
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) [testng-6.8.8.jar:?]
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) [testng-6.8.8.jar:?]
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) [testng-6.8.8.jar:?]
	at org.testng.TestRunner.privateRun(TestRunner.java:767) [testng-6.8.8.jar:?]
	at org.testng.TestRunner.run(TestRunner.java:617) [testng-6.8.8.jar:?]
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:348) [testng-6.8.8.jar:?]
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343) [testng-6.8.8.jar:?]
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305) [testng-6.8.8.jar:?]
	at org.testng.SuiteRunner.run(SuiteRunner.java:254) [testng-6.8.8.jar:?]
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) [testng-6.8.8.jar:?]
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) [testng-6.8.8.jar:?]
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) [testng-6.8.8.jar:?]
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) [testng-6.8.8.jar:?]
	at org.testng.TestNG.run(TestNG.java:1057) [testng-6.8.8.jar:?]
	at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115) [testng-remote.jar:?]
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) [testng-remote.jar:?]
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) [testng-remote.jar:?]
Caused by: org.apache.xmlbeans.XmlException: error: Unexpected element: CDATA
	at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3486) ~[xbean-2.4.0-sb-fixed.jar:?]
	at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1276) ~[xbean-2.4.0-sb-fixed.jar:?]
	at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1263) ~[xbean-2.4.0-sb-fixed.jar:?]
	at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345) ~[xbean-2.4.0-sb-fixed.jar:?]
	at com.eviware.soapui.config.SoapuiProjectDocumentConfig$Factory.parse(Unknown Source) ~[ready-api-soapui-2.8.0.jar:2.8.0]
	at com.eviware.soapui.impl.wsdl.WsdlProject.loadProjectFromStreamBase(WsdlProject.java:517) ~[ready-api-soapui-2.8.0.jar:2.8.0]
	at com.eviware.soapui.impl.wsdl.WsdlProject.loadProjectFromInputStream(WsdlProject.java:689) ~[ready-api-soapui-2.8.0.jar:2.8.0]
	at com.eviware.soapui.impl.wsdl.WsdlProject.loadProject(WsdlProject.java:482) ~[ready-api-soapui-2.8.0.jar:2.8.0]
	... 29 more

Yes, WsdlProject can't be used to read a composite project.

Use WsdlProjectPro instead. See below link for API docs
https://support.smartbear.com/readyapi/apidocs/pro/index.html?com/eviware/soapui/impl/wsdl/WsdlProje...


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: