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 a 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 will you 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 on 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 the configuration file.

To Enable API to 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 the 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 a 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 on 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.


Further Reading

46 thoughts on “How to Update TestLink Test Case Execution Status Remotely Through Selenium – Tutorial #3”

  1. 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)

    ….

  2. @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.

  3. 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

  4. 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).

  5. 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.

  6. 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?

  7. 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.

  8. 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

  9. Will you please explain the meaning of below mention line:

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

  10. 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

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

    testlink.api.java.client.TestLinkAPIException:

  12. 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.””

  13. 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}”

  14. 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

  15. 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.

  16. 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.

  17. 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

  18. 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

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

    Thanks.

  20. 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

  21. 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

  22. 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

  23. 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!

  24. 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.

  25. Hello all, Thank’s fos sharing thos pst is very useful, now i’m not able to update status in Testlink after run them with Nunit Conole (my tests are developped in visula studion (Selenium c#)
    I’m bloked and i need your help please :)

  26. Thanks for the post, it helped me to update status through selenium. Only issue I see is it takes a lot of time to update the status in Testlink. I have nearly 300 cases and it takes almost 3 to 4 hours to update the status.
    Is there a quick soltuion to this, please let me know.

  27. Hi,

    Thank you for the useful information.
    We are using same in our project to update 300+ test cases through XML-RPC call and it is taking 4+ hours to update same.
    As we have totally around 2000 test cases to be updated. Can you please suggest the ways to increase its performance.

    Advance thank you!

  28. Hi,
    I am getting an error.Please share your views

    testlink.api.java.client.TestLinkAPIException: The test case identifier null was not found and the test case 485 could not be accessed to report a test result to test plan UIAutomatoion.

Leave a Comment