Getting trouble with Java Selenium and TestLink integration

Discussion and information for XML-RPC interface.

Moderators: Amaradana, TurboPT, TL Developers

Post Reply
andredecotia
TestLink user
Posts: 7
Joined: Wed May 11, 2011 4:44 pm

Getting trouble with Java Selenium and TestLink integration

Post by andredecotia »

Hi all, I am using the following below code:

Code: Select all

package teste;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import java.util.Map;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

public class TestlinkAPIXMLRPCClient {
	// Substitute your Dev Key Here
	public static final String DEV_KEY = "xxxxxxxx";
	// Substitute your Server URL Here
	public static final String SERVER_URL = "http://10.50.18.188/lib/api/xmlrpc.php";

	/**
	 * report test execution to TestLink API
	 * 
	 * @param int tcid
	 * @param int tpid
	 * @param String
	 *            status
	 */
	@SuppressWarnings("rawtypes")
	public static void testLinkReport(int tcid, String status) {
		try {
			XmlRpcClient rpcClient;
			XmlRpcClientConfigImpl config;

			config = new XmlRpcClientConfigImpl();
			config.setServerURL(new URL(SERVER_URL));
			rpcClient = new XmlRpcClient();
			rpcClient.setConfig(config);

			// ////////////////////////
			// Get available projects.
			// ////////////////////////

			ArrayList<Object> params = new ArrayList<Object>();
			Hashtable<String, Object> executionData = new Hashtable<String, Object>();
			executionData.put("devKey", DEV_KEY);
			params.add(executionData);

			Object[] result = (Object[]) rpcClient.execute("tl.getProjects",
					params);

			int idProject = -1;

			// Typically you'd want to validate the result here and probably do
			// something more useful with it
			System.out.println("Result was:\n");
			for (int i = 0; i < result.length; i++) {
				Map item = (Map) result[i];
				System.out.println("Keys: " + item.keySet().toString()
						+ " values: " + item.values().toString());
				if (item.get("name").equals("xxxx")) {
					idProject = Integer.parseInt((String) item.get("id"));
				}
			}

			if (idProject == -1)
				return;

			// ///////////////////////////////////////////
			// Get available test plans in xxx project.
			// DOES ONLY WORK WHEN ALL TEST PLAN NAMES DO
			// NOT CONTAIN ANY SPECIAL CHARS LIKE UMLAUTS
			// ///////////////////////////////////////////

			params = new ArrayList<Object>();
			executionData = new Hashtable<String, Object>();
			executionData.put("devKey", DEV_KEY);
			executionData.put("testprojectid", idProject);
			params.add(executionData);

			result = (Object[]) rpcClient.execute("tl.getProjectTestPlans", params);

			int idTestPlan = -1;

			// Typically you'd want to validate the result here and probably do
			// something more useful with it
			System.out.println("Result was:\n");
			for (int i = 0; i < result.length; i++) {
				Map item = (Map) result[i];
				System.out.println("Keys: " + item.keySet().toString()
						+ " values: " + item.values().toString());

				for (Object key : item.keySet()) {
					Object element = item.get(key);
					if (element instanceof Map == false)
						continue;

					if (((Map) element).get("name").equals("Szenario")) {
						idTestPlan = Integer.parseInt((String) ((Map) element)
								.get("id"));
					}
				}
			}

			if (idTestPlan == -1)
				return;

			// //////////////////
			// Create new build.
			// //////////////////

			params = new ArrayList<Object>();
			executionData = new Hashtable<String, Object>();
			executionData.put("devKey", DEV_KEY);
			executionData.put("testplanid", idTestPlan);
			executionData.put("buildname", "Automatischer Test am "
					+ (new Date()).toString());
			executionData.put("buildnotes", "Notizen...");
			params.add(executionData);

			result = (Object[]) rpcClient.execute("tl.createBuild", params);

			int idBuild = -1;

			// Typically you'd want to validate the result here and probably do
			// something more useful with it
			System.out.println("Result was:\n");
			for (int i = 0; i < result.length; i++) {
				Map item = (Map) result[i];
				System.out.println("Keys: " + item.keySet().toString()
						+ " values: " + item.values().toString());

				if (((Boolean) item.get("status")) == true) {
					idBuild = Integer.parseInt((String) item.get("id"));
				}
			}

			if (idBuild == -1)
				return;

			// Report test case result in new build.
			params = new ArrayList<Object>();
			executionData = new Hashtable<String, Object>();
			executionData.put("devKey", DEV_KEY);
			executionData.put("testcaseid", tcid);
			executionData.put("testplanid", idTestPlan);
			executionData.put("buildid", idBuild);
			executionData.put("status", status);
			executionData.put("notes", "testtest");
			params.add(executionData);

			result = (Object[]) rpcClient.execute("tl.reportTCResult", params);

			// Typically you'd want to validate the result here and probably do
			// something more useful with it
			System.out.println("Result was:\n");
			for (int i = 0; i < result.length; i++) {
				Map item = (Map) result[i];
				System.out.println("Keys: " + item.keySet().toString()
						+ " values: " + item.values().toString());
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (XmlRpcException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		// Substitute this for a valid tcid and tpid within your project
		TestlinkAPIXMLRPCClient.testLinkReport(4, "b");
	}
}
But I got the error:

Code: Select all

org.apache.xmlrpc.XmlRpcException: Failed to create input stream: http://10.50.18.188/lib/api/xmlrpc.php
	at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:65)
	at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:141)
	at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:94)
	at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:44)
	at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:157)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:146)
	at teste.TestlinkAPIXMLRPCClient.testLinkReport(TestlinkAPIXMLRPCClient.java:48)
	at teste.TestlinkAPIXMLRPCClient.main(TestlinkAPIXMLRPCClient.java:170)
Caused by: java.io.FileNotFoundException: http://10.50.18.188/lib/api/xmlrpc.php
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
	at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:63)
	... 9 more
Caused by:
java.io.FileNotFoundException: http://10.50.18.188/lib/api/xmlrpc.php
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
	at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:63)
	at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:141)
	at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:94)
	at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:44)
	at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:157)
	at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:146)
	at teste.TestlinkAPIXMLRPCClient.testLinkReport(TestlinkAPIXMLRPCClient.java:48)
	at teste.TestlinkAPIXMLRPCClient.main(TestlinkAPIXMLRPCClient.java:170)
andredecotia
TestLink user
Posts: 7
Joined: Wed May 11, 2011 4:44 pm

Re: Getting trouble with Java Selenium and TestLink integrat

Post by andredecotia »

Any help?

Thanks.
André AS
Unhandled
Advanced user
Posts: 67
Joined: Sun Jan 23, 2011 11:28 pm

Re: Getting trouble with Java Selenium and TestLink integrat

Post by Unhandled »

What happens if you open a web browser and go to the following URL?
http://10.50.18.188/lib/api/xmlrpc.php

You should see a page with only the following text:
XML-RPC server accepts POST requests only.
andredecotia
TestLink user
Posts: 7
Joined: Wed May 11, 2011 4:44 pm

Re: Getting trouble with Java Selenium and TestLink integrat

Post by andredecotia »

When I use automation test must I attribute the Testlink's use case to anyone yet?
aostad
Member of TestLink Community
Posts: 183
Joined: Wed Apr 01, 2009 8:32 pm

Re: Getting trouble with Java Selenium and TestLink integrat

Post by aostad »

Did you find any solution?
Post Reply