Automate Testlink Test Case Result Using Selenium

This article is about, Run Test cases with automation scripts in test link. It is necessary that you had worked on selenium before. After wards only you will understand this still try to explore from below information.

There are some important points and Preconditions for this. You need to install Java first. Then install Eclipse. Give proper Path in environment variable for Java and Eclips.

Moving to Next, Install Junit 4.11 jar , Selenium Jar and Test Link client API jar.

Now, Log in with Test link and select a test project from home page. Go to My settings and Verify the
API Interface. From here you can create your API key for a Project. Create New API Key and Note down key in a text file.


After Generate a Key, you need to update test case execution Type from 'Manual' to 'Automated'.


After this step you need to note down the Test Project Name, Test Plan Name, Test Case Name, Build Name.

Then open eclips. Create a new java project for Test case execution in test link. Create a Package for this project.

Now you Add external jars which we have already download. Do right click on project then click on 'Configure Build Path' and select Libraries. Here you can see a button as 'Add External Jars'. Click on it and Add 4 jars.
  • Junit – 4.11.
  • Selenium – standalone server jar.
  • Selenium – Java jar & all libs jar.
  • Test Link Client API jars. Download.
Click on 'OK' button from screen so this all jar will be added for your project. Now convert your project in TestNG and write down the below code in the Eclipse IDE.


package TestCaseExecution;

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="040d169f3f1a2b38ced46c37d073a1c4"; 
  
 //Enter your Test Link URL here
 public static String URL= "www.testlink.com";
 
 //Enter your Test Project Name here 
 String testProject="Test Project1";
 
 //Enter your Test Plan here
 String testPlan="Test Plan";
 
 //Enter your Test build here
 String build="Test Build";
 

@BeforeSuite

public void setUp() throws Exception
 { 
  //Enter the path for your browser exe file here
  System.setProperty("webdriver.chrome.driver","D:\\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.get("http://gmail.com"); 
  //Enter your user name.
  driver.findElement(By.xpath("//input[@id='txtUser']")).sendKeys("Your UserName");
  //Enter your pswd.
  driver.findElement(By.xpath("//input[@id='txtPass']")).sendKeys("Your pswd");
  //Find Xpath of your click button and enter here
  driver.findElement(By.xpath("//input[@id='btnLogin']")).click();
  driver.switchTo().defaultContent();

  result= TestLinkAPIResults.TEST_PASSED;
  //Enter your test case ID here
  updateTestLinkResult("Test case ID", null, result); 
  
 }

 catch(Exception e)
 {
  result = TestLinkAPIResults.TEST_FAILED;
          exception = e.getMessage();
          updateTestLinkResult("Test case ID", 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();
}
}

This is the scrip for run test case automatically in test link. You need to Run the script from eclips and verify the result.

Now we will understand what we have done above. Gmail Login test case is passed due to this script. First this Login test case has 'Not Run' status in testlink. After running script it will have status as 'Passed' if successful Login is done by your valid user name and pswd.

Be care full while Enter your Test Project Name, Test Plan Name, Test Build Name, Test URL and Test case ID. If you made any mistake for this field then script will not run successfully.

<< PREVIOUS || NEXT >>

4 comments:

  1. I am getting below 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.getProjects(TestLinkAPIClient.java:726)
    at testlink.api.java.client.TestLinkAPIHelper.getProjectInfo(TestLinkAPIHelper.java:64)
    at testlink.api.java.client.TestLinkAPIHelper.getProjectID(TestLinkAPIHelper.java:48)
    at testlink.api.java.client.TestLinkAPIClient.reportTestCaseResult(TestLinkAPIClient.java:184)
    at Testlink.updateTestLinkResult(Testlink.java:76)
    at Testlink.Test(Testlink.java:69)
    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:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)
    Caused by: org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse servers response: Content is not allowed in prolog.
    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:39)
    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)
    ... 31 more

    ReplyDelete
  2. Issue resolved after edit php.ini file and set always_populate_raw_post_data = -1

    ReplyDelete
  3. Hi,

    I am getting below error:
    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.

    ReplyDelete
  4. I added the testlink-api jar file in eclipse but when Iam running the script it still giving the error:java.lang.NoClassDefFoundError: org/apache/xmlrpc/client/XmlRpcClientConfig

    ReplyDelete