How to Update TestLink Test Case Execution Status Remotely Through Selenium – Tutorial #3

Updating TestLink Test Case Execution Status Remotely Through Selenium WebDriver Using TestLink API

In first two TestLink tutorials (part 1 and part 2) we learned TestLink installation, creating test project, test plan, test cases, requirements management, manual execution of test cases, and generating test reports.

Today, we will learn one advanced and important feature of TestLink i.e. updating test case execution status through Selenium WebDriver code using TestLink API. We will also provide the exact Selenium code that you can use for this API call.

With this feature you don’t have to login into TestLink each time to update the test case execution status. You can do it automatically using TestLink API. This will save your lot of manual execution time.

To demonstrate this feature we are using Selenium WebDriver and updating the test case status along with test note in TestLink.

Let’s have a deep look at – how to update test case execution status remotely through Selenium WebDriver code and TestLink API through XML-RPC call.

TestLink API

What you will learn in this tutorial?

  • Prerequisites
  • Enabling TestLink API
  • Generating API Key
  • Changing Execution mode
  • Writing Selenium code
  • Executing selenium code
  • Conclusion

Prerequisites

  1. All the steps explained in TestLink tutorial #1 should be done.
  2. You are using Selenium for test automation on your project.
  3. Test cases which are automated using Selenium can be updated in TestLink through Selenium code.

Java
– You can download java from here.
– Double click on the exe file and install java on your system.

Eclipse
– Download eclipse for windows from here.
– It will be downloaded as a zip package, extract and place it in your local drive.

Selenium Library Jars
Download selenium-java jar and selenium-standalone jar from here.

Junit-4.11
Download Junit 4.11 jar from here.

TestLink Client API jars
Download Test Client API jars from here.

Enabling TestLink API

For automated test case execution, TestLink API configuration should be enabled in configuration file.

To Enable API follow these steps:

Step -1 (Stop Apache service)
TestLink has already deployed in Apache. Before doing any modifications in configuration file Apache should be stopped.

To do that, open Control Panel -> System and Security -> Administrative Tools.
Double click on “services” icon.

TestLink img1

Click on Apache 2.4 service and click on the “stop the service” link appearing on the left side.
It will stop the Apache service.

Step -2 (Enable API in TestLink Configuration file)
Open TestLink folder inside htdocs folder and open Config.inc.php file in edit mode.
Change following line to “TRUE”.

 /* [API] */
/** XML-RPC API availability - do less than promised 
FALSE => user are not able to generate and set 
his/her API key. XML-RPC server do not check this 
config in order to answer or not a call.
*/

$tlCfg->api->enabled = TRUE; 

Save and close the file.

Step -3 (Start Apache service)
Open Apache service as described in Step 1 and start it.

Generating API Key

TestLink provides an API key for each user which is essential for updating Test case execution status in an automated way.

API key can be generated through simple steps as explained in below steps:

Step -1
Open TestLink URL in your browser and login with your user credentials.

Step -2
Open “My Settings” link on the TestLink desktop page.

TestLink img2

Step -3
Click on the “Generate a new Key” button in the API Interface section.

TestLink img3

A new key will be generated and displayed on the page.

TestLink img4

Changing Execution Mode

To update a Test case execution status through API, its execution type should be “Automated”.

Changing test case execution type to Automated:

Note: If you are following this remote status update practice you can update the execution type to Automated while creating the test cases itself.

Open a Test case and click on “settings” icon appearing on the right side panel. It will display list of operations. Click on “Edit” button.

TestLink img5


Change Execution Type to “Automated”.

TestLink img6

Click on “Save” button.

Note down the Test case name, Test project name, Test plan name, and the build name. We will need these details in our Selenium code.

In our example,
Test Project Name: Gmail
Test Plan Name: SampleTestPlan
Test Case Name: GmailLogin1
Build Name: SampleBuild

Writing Selenium code

Open Eclipse, and create a Java project as shown in below figure. (Click to enlarge image)

TestLink img7

Right click on the Project , go to Build path -> Configure build path, switch to “Libraries” tab and click on “Add External Jars” button.

Add following jars in the build path

  1. Junit 4.11 jar
  2. Selenium-standalone server jar
  3. Selenium – java jar & all libs (Library folder) jar
  4. TestLink Client API jar & all lib (Library folder) jar

TestLink img8

Click “OK” button. All jars will be added to the project build path.

Create a package inside src directory of the java project as shown below:

TestLink img9

Create a class inside the package with name “AutomatedUpdateExample”.

Copy the following code into that class:

 package com.test;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import testlink.api.java.client.TestLinkAPIClient;
import testlink.api.java.client.TestLinkAPIException;
import testlink.api.java.client.TestLinkAPIResults;

public class AutomatedUpdateExample {

public static String DEVKEY="2f404203b306bd8dd811a7f824c194d0";
public static String URL="http://localhost/testlink/lib/api/xmlrpc/v1/xmlrpc.php";

public static void reportResult(String TestProject,String TestPlan,String Testcase,String Build,String Notes,String Result) throws TestLinkAPIException{
TestLinkAPIClient api=new TestLinkAPIClient(DEVKEY, URL);
api.reportTestCaseResult(TestProject, TestPlan, Testcase, Build, Notes, Result);
}

@Test
public void Test1()throws Exception
{
AutomatedUpdateExample a=new AutomatedUpdateExample();
WebDriver driver=new FirefoxDriver();
WebDriverWait wait=new WebDriverWait(driver, 600);
String testProject="Gmail";
String testPlan="SampleTestPlan";
String testCase="GmailLogin1";
String build="SampleBuild";
String notes=null;
String result=null;
try{
driver.manage().window().maximize();
driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1");
driver.findElement(By.id("Email")).sendKeys("testlink.msoftgp");
driver.findElement(By.id("Passwd")).sendKeys("*******");
driver.findElement(By.id("signIn")).click();
driver.switchTo().defaultContent();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("+Testlink")));
result= TestLinkAPIResults.TEST_PASSED;
notes="Executed successfully";
}
catch(Exception e){
result=TestLinkAPIResults.TEST_FAILED;
notes="Execution failed";
}
finally{

a.reportResult(testProject, testPlan, testCase, build, notes, result);
driver.quit();
}
}
} 

[Note: update Test project, Test plan, Test case and Build name in above code as per your project details]

Save the file.

Executing Selenium Code

Depending upon the execution of the test in Selenium, TestLink test case status will be updated as either “Passed” or “Failed”.

If the code executed successfully without any exceptions then test case status will be updated as “Passed”. In case of any exceptions test case status will be updated as “Failed”.

To execute code, just right click on the file and select Run As -> Junit Test. It will start executing the test.

(Click to enlarge image)

TestLink img10

Now open TestLink in your browser and see the execution status for the test case. It should be updated.

Before Execution

TestLink img11

After Execution

(Click to enlarge image)

TestLink img12

Conclusion

Hope we have clearly explained how to update TestLink test case execution status automatically using TestLink API.

The testers can easily update test case execution status directly in TestLink without having to login. This will surely help you save your precious time and money. :)

This again proves that TestLink is a good open source Test Management Tool, which can be used by manual testers as well as automation experts.

With this, we are concluding our TestLink tutorial series. Feel free to post your queries in comments.




Recommended reading

40 comments ↓

#1 gurpreet

very helpful,,,, please start tutorials on Selenium
web- driver….

#2 Tanaya

I’m getting below testlink exception after running the junit test-

testlink.api.java.client.TestLinkAPIException:
The xml-rpc call to TestLink API method tl.getProjects failed.
Result[0] = {message=Can not authenticate client: invalid developer key, code=2000}

at testlink.api.java.client.TestLinkAPIClient.
execXmlRpcMethodWithCache(TestLinkAPIClient.java:1209)

at testlink.api.java.client.TestLinkAPIClient.
getProjects(TestLinkAPIClient.java:726)

at testlink.api.java.client.TestLinkAPIHelper.
getProjectInfo(TestLinkAPIHelper.java:64)

at testlink.api.java.client.TestLinkAPIHelper.
getProjectID(TestLinkAPIHelper.java:48)

….

#3 Kirti Jadhav

thanks for this. we are using Test link but not updating it automatically. we will now try to automate it.

#4 Anitha Eswari

@Tanaya – Ensure , whether you’ve enabled API in Testlink Config file and check whether your Developer key is correct.

If, Still you’re facing the same problem then, generate a new developer key and use it in your code.

#5 Need Selenium

nice one.

Vijay when you are going to cover Selenium on STH? we are waiting to see it since long.

#6 Roopesh`

Nice Articles.Plz start Selenium Articles

#7 KOushik

Hi ,

Thanks For the post , it is very useful for me to execute the testcases from test-Link using Jenkins. Can you please help me out for , how to extract the the Testcases within the build.

i.e. Execute the all the testcases with in the build.

Thanks

#8 srinivasan

Thanks for the post, i face an performance issue . when i run the script with multiple test case it take 1 min to update the status in testlink. i have 1000 testcases in repository (test Spec).

#9 Vishi

Hi Vijay/Srinivasan,

I was able to automatically update the status of one test case in TestLink after the automation test was run in Selenium. But how to update the results for several test cases in a build. Please help me.

#10 Vishi

Please share the code. Also even though I have added the dependency in pom.xml .

br.eti.kinoshita
testlink-java-api
1.9.8-1

Build is throwing error, package testlink.api.java.client does not exist. How to resolve this? Are you guys also facing the same error?

#11 vani

I was able to automatically update the status of one test case in TestLink after the automation test was run in Selenium. But how to update the results for several test cases in a build. Please help me.

#12 Bala

Thanks for the post. It really helps a lot .

I am facing a problem while using the same code with real time server ex:https://servername.com/testlink/lib/api/xmlrpc/v1/xmlrpc.php

It is throwing :The call to the xml-rpc client failed.

Please someone help out with this.

#13 Panchajanya

hi,
When i run i got this message – ” The email or password you entered is incorrect. ”
Please help me

#14 Vishal Deshpande

Hi Team,

Appreciate your effort to explain the procedure. However I am looking for Test step level result logging. Your help will be appreciable. Thanks in Advance.

Regards,
Vishal D

#15 Toni

Can someone share with me a XML template to update the result of a test case? I would like to create the post to the http://localhost/testlink/lib/api/xmlrpc.php file manually. Thank you for the help

#16 Sagar Khalasi

Hello,
I have tried this same for ubuntu12.04.
I have found this error.

“testlink.api.java.client.TestLinkAPIException: Unable to create a XML-RPC client.”

Check this :
boolean isConn = api.isConnected;
System.out.println(isConn);//return false

Fore more info : http://stackoverflow.com/questions/28272881/what-is-solution-for-this-error-unable-to-create-a-xml-rpc-client

#17 sachin

Will you please explain the meaning of below mention line:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText(“+Testlink”)));

#18 mona

I’m getting below testlink exception after running the junit test-

testlink.api.java.client.TestLinkAPIException:
The xml-rpc call to TestLink API method tl.getProjects failed.
Result[0] = {message=Can not authenticate client: invalid developer key, code=2000}

Please please help

#19 annie

I’m getting below testlink exception after running the junit test-

testlink.api.java.client.TestLinkAPIException:

#20 Pardhu

Thanks a lot very helpful tutorial.it is working fine but i am not able update status on TEST LINK. I am getting bellow ERROR:

“”Exception in thread “main” testlink.api.java.client.TestLinkAPIException: The test case identifier null was not found and the test case CPIDM-8937: 20150604-03:58:17 SSO_Email_Forgot_Password could not be accessed to report a test result to test plan Sample – Smoke Suite.””

#21 Pardhu

I need to integrate selenium with testlink for automated testing.
i am using below code

TestLinkAPIClient api = new TestLinkAPIClient(DEVKEY, URL);
api.reportTestCaseResult(TestProject, TestPlan, Testcase, Build, Notes,Result);

But getting exception

“testlink.api.java.client.TestLinkAPIException:
The xml-rpc call to TestLink API method tl.reportTCResult failed.
Result[0] = {message=(reportTCResult) – Parameter platformname OR platformid is required, but has not been provided, code=200}”

#22 AJAY

Hye every 1,
how to re-executes any test case failed in selenium tools ?

#23 Mahendran

This works great, Is there any way to log the test case step level result?.

#24 Umesh

Hi Ajay,

You can re-execute failed cases in selenium.. check

http://easytestautomation.blogspot.in/2015/06/selenium-rerun-failed-test-scripts.html

#25 Olimpia

Hi,

I followed your example but unfortunately I got stuck in this error:

testlink.api.java.client.TestLinkAPIException: The call to the xml-rpc client failed.
at testlink.api.java.client.TestLinkAPIClient.executeXmlRpcMethod(TestLinkAPIClient.java:1266)
at testlink.api.java.client.TestLinkAPIClient.execXmlRpcMethodWithCache(TestLinkAPIClient.java:1195)
at testlink.api.java.client.TestLinkAPIClient.about(TestLinkAPIClient.java:145)
at testing.utils.TestLinkUtils.reportResult(TestLinkUtils.java:38)
at testing.login_page.GeneralAdminLogIn.I_should_see_the_title(GeneralAdminLogIn.java:99)
at ?.Then I should see the title “Administration des produits Airs Serveur”/IdeaProjects/GeneralAdminTest/src/test/resources/features/login_page/GeneralAdminLogIn.feature:14)
Caused by: org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse servers response: Expected methodResponse element, got br
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:177)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:145)
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 testlink.api.java.client.TestLinkAPIClient.executeXmlRpcMethod(TestLinkAPIClient.java:1232)
at testlink.api.java.client.TestLinkAPIClient.execXmlRpcMethodWithCache(TestLinkAPIClient.java:1195)
at testlink.api.java.client.TestLinkAPIClient.about(TestLinkAPIClient.java:145)
at testing.utils.TestLinkUtils.reportResult(TestLinkUtils.java:38)
at testing.login_page.GeneralAdminLogIn.I_should_see_the_title(GeneralAdminLogIn.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at cucumber.runtime.Utils$1.call(Utils.java:34)
at cucumber.runtime.Timeout.timeout(Timeout.java:13)
at cucumber.runtime.Utils.invoke(Utils.java:30)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:35)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
at cucumber.runtime.Runtime.runStep(Runtime.java:298)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:48)
at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:163)
at cucumber.runtime.Runtime.run(Runtime.java:120)
at cucumber.api.cli.Main.run(Main.java:36)
at cucumber.api.cli.Main.main(Main.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 7; Expected methodResponse element, got br
at org.apache.xmlrpc.parser.XmlRpcResponseParser.startElement(XmlRpcResponseParser.java:98)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:175)
… 34 more

My Testlink is installed on a server. Could you please help me out with this problem?
Thanks,
Olimpia

#26 User

Superb article. Can we log bugs too in JIRA automatically if test case fails?

#27 hemanth

By using this Testlink plugin, i si we can updatae the test step status ?

kindly update me ASAP.

Thanks…

#28 Sumaiya

I would like to know how to automatically update the number of test cases executed by each person in the project. How many test cases have not run, how many blocked. how many test cases are assigned to each individual.

#29 XrisseM

Hi, and thank you for great tutorials and articles!

I’m new to software testing and automation, so I’m sorry in advance if this comes through as noob questions.

I would like to accomplish updating test case execution status directly in TestLink with the help of Selenium.
Is there any way to this working with c# and Visual Studio? If so, where can I learn to set it up?

Best regards.

#30 Suprita

I am getting the below error:

The xml-rpc call to TestLink API method tl.reportTCResult failed.
Result[0] = {code=200, message=(reportTCResult) – Parameter platformname OR platformid is required, but has not been provided}

where do I pass the platformname? Any idea ? Thanks

#31 patrick

great article,
worked a treat! We now have integration for out selenium test cases, which is a big improvement.
Does anyone konw if there is anything comparable with with QTP / UFT?
thanks

#32 richard

Good article.
Is it possible to Update TestLink Test Case Execution Status Remotely while executing Web Services automation?

Thanks.

#33 Joseph

I also getting the below error:

The xml-rpc call to TestLink API method tl.reportTCResult failed.
Result[0] = {code=200, message=(reportTCResult) – Parameter platformname OR platformid is required, but has not been provided}

Can you help or give a pointer to resolving the issue. Thanks

#34 Mahesh N.P

HI ,

Do you have code or explanation for updating the Step wise result in Test Link. Thanks in advance.

Thnk

#35 Vijay

Really nice tutorial but I want to attach the log file to failed test cases so Is it possible using API if yes please provide its steps and API

#36 Madhushri

Hi,
I want to install XAMPP for testlink. I am using windows 8 64 bit. Because of this i am unable to install. Please help me..

Thanks

#37 nevil

getting message

The call to the xml-rpc client failed.

php 7
testlink-1.9.15

#38 Praveen

Download testlink.eclipse.plugin_0.97.11.zip and add all files after extract, it should work.

#39 Reymond Villaluz

Hi great tutorial but I’m having an issue which is the same with the other guys here. ” The call to the xml-rpc client failed” I’ve already updated config.inc in testlink root directory. I’ve also enable test automation API Key on my testlink test project. I’m using testlink-api-client 2.0. Thanks!

#40 Rinkle

I am trying to integrate testlink with selenium webdriver, using the following code

import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import testlink.api.java.client.TestLinkAPIClient;
import testlink.api.java.client.TestLinkAPIException;
import testlink.api.java.client.TestLinkAPIResults;

public class TestLink
{
public static WebDriver driver;
//Enter your project API key here.
public static String DEVKEY=”cb5f984421c93f1efb42b53a43f83c3a8d04d2b1fa2f17cb798054a944297d91″;
//Enter your Test Link URL here
public static String URL= “http://192.168.129.33/testlink/index.php”;

//Enter your Test Project Name here
String testProject=”Test Project2″;

//Enter your Test Plan here
String testPlan=”TesT Plan2″;

//Enter your Test build here
String build=”Test Plan 1″;

@BeforeSuite

public void setUp() throws Exception
{
//Enter the path for your browser exe file here
System.setProperty(“webdriver.chrome.driver”,”D:\\Selenium\\chromedriver.exe”);
driver = new ChromeDriver();
}

@Test

public void Test()throws Exception

{
String result = “”;
String exception = “”;

try
{
driver.manage().window().maximize();
//Enter your applicaton URL.
driver.navigate().to(“https://www.gmail.com”);

//enter ur username
driver.findElement(By.xpath(“.//* [@id=’Email’]”)).sendKeys(“rinkle95@gmail.com”);

//click on next
driver.findElement(By.xpath(“.//*[@id=’next’]”)).click();

//Enter your password
// driver.findElement(By.xpath(“.//*[@id=’Passwd’]”)).click();
// driver.findElement(By.xpath(“.//*[@id=’Passwd’]”)).sendKeys(“1233”);
driver.findElement(By.id(“Passwd”)).sendKeys(“12345”);
//Find Xpath of your click button and enter here
driver.findElement(By.xpath(“.//*[@id=’signIn’]”)).click();
driver.switchTo().defaultContent();

result= TestLinkAPIResults.TEST_PASSED;
//Enter your test case ID here
updateTestLinkResult(“TC–1”, null, result);

}

catch(Exception e)
{
result = TestLinkAPIResults.TEST_FAILED;
exception = e.getMessage();
updateTestLinkResult(“TTC–1”, exception, result);
}
}

public void updateTestLinkResult(String testCase, String exception, String result) throws TestLinkAPIException
{
TestLinkAPIClient testlinkAPIClient = new TestLinkAPIClient(DEVKEY,URL);
testlinkAPIClient.reportTestCaseResult(testProject, testPlan, testCase, build, exception, result);

}

@AfterSuite

public void close()
{
driver.quit();
}
}

after that, this code is running properly but not updating anything in testlink. Could anyone please help me resolving this issue.I just want to mark testcase execution in testlink through selenium webdriver.

Leave a Comment