This article will show how to integrate Selenium with Testlink .
This integration is nothing more than sending the execution result of
the test script for Testlink .
We will create a Java project
with the support of testng for creating the test script with
Selenium . Below is a list of items needed for this tutorial.
PreRequisites:
- Install Testlink version 1.9
- dbfacade-Testlink-api-client
- IDE for Java development(Eclipce)
- Java JDK 1.6.0
- Libraries Selenium RC Java
Configure TestLink:
Step1:Enable the project with Automation Testing
Step2:Edit the configuration file in Testlink
1)Add below two lines in file
custom_config.inc.php.example
$tlCfg->
api-> enabled
$tlCfg-> exec_cfg->
enable_test_automation
2)Rename
custom_config.inc.php.example as custom_config.inc.php
Step3:Generate a new key access
After you enable the API access to XML-RPC and report
the activation of automation in the configuration file is necessary
to generate the key. This key is created by user and that it will
allow the Testlink identify who is trying to access the XML-RPC
services.
TestLinkHomePage--->MySettings--->AccounSettings--->ApiInterface
Section--->Click on Generate a new key.
Preparing
Development Environment
Step1:Add
the following JAR files
in eclipse.
- dbfacade-Testlink:
- Testlink-client-api-2.0.jar
- all libs
- Selenium RC:
- selenium-server.jar
- selenium-java-client-driver.jar
Step2:Sample Source
Code.
import java.util.Date;
import com.thoughtworks.selenium.*;
import org.testng.Reporter;
import org.testng.annotations.*;
import
testlink.api.java.client.TestLinkAPIResults;
public class Selenium_Methods implements
IConstantes {
Selenium selenium;
@Parameters({"selenium.host","selenium.port","selenium.browser","selenium.url"})
@BeforeMethod(alwaysRun=true)
public void startBrowser(String
host,String port,String browser,String url){
this.selenium= new
DefaultSelenium(host, Integer.parseInt(port), browser, url);
this.selenium.start("captureNetworkTraffic=true,
addCustomRequestHeader=true,captureNetworkTraffic=true");
this.selenium.open(url);
} //startBrowser();
@Test public void limitedSearch() throws
Exception {
String resultado = null;
String nota = null;
try
{
selenium.open("/");
selenium.click("link=Login");
selenium.waitForPageToLoad("30000");
selenium.type("login", "bala");
selenium.type("password",
"krishna");
selenium.click("Submit");
selenium.waitForPageToLoad("30000");
if(selenium.isTextPresent("Welcome
balakrishna"))
Reporter.log("Successfully log in");
else
Reporter.log("Error
on page");
selenium.click("link=Limited Search
Member");
selenium.waitForPageToLoad("30000");
selenium.type("email", "10");
selenium.click("//input[@type='submit']");
selenium.waitForPageToLoad("30000");
selenium.click("link=Logout");
selenium.waitForPageToLoad("30000");
resultado =
TestLinkAPIResults.TEST_PASSED;
}
catch (Exception e) {
resultado =
TestLinkAPIResults.TEST_FAILED;
nota = e.getMessage();
e.printStackTrace();
}
finally {
ResultadoExecucao.reportTestCaseResult1(PROJETO,
PLANO, CASO_TESTE1, BUILD, nota, resultado);
}
}
@AfterMethod(alwaysRun=true)
public void stopSelenium() {
Date dt;
dt = new Date();
System.out.println("Execution Terminated at "+ dt);
this.selenium.stop();
} //stopSelenium();
}
Step3:Class ResultadoExecucao
Within the
project create ResultadoExecucao class, which is responsible for
sending the result of the script to Testlink.
import
testlink.api.java.client.TestLinkAPIClient;
import
testlink.api.java.client.TestLinkAPIException;
public class ResultadoExecucao implements
IConstantes {
public static void
reportTestCaseResult1(String projetoTeste, String planoTeste, String
casoTeste, String nomeBuild, String nota, String resultado) throws
TestLinkAPIException {
TestLinkAPIClient testlinkAPIClient =
new TestLinkAPIClient(DEVKEY, URL);
testlinkAPIClient.reportTestCaseResult(projetoTeste, planoTeste,
casoTeste, nomeBuild, nota, resultado);
}
Step4:Interface iConstantes
Create an interface
with the data necessary to send the data to the Testlink, which are
the parameters that were described above.
public
interface
IConstantes {
final
String DEVKEY
= "7c0893a8c63d2599074a308de09ad75b";
final
String URL
= "http://localhost:82/testlink/lib/api/xmlrpc.php";
final
String PROJETO
= "SeleniumIntegrationWithTestlink";
final
String PLANO
= "LCLT001-IntegratingSelenium";
final
String BUILD
= "integarationbuild1";
final
String CASO_TESTE1
= "LimitedSearch";
}
Here DEVKEY =generated API KEY
PROJETO = Project name in
Testlink.
PLANO =TestPlan Name
BUILD=Build Name
CASO_TESTE1=TestCaseName
Step5:After Execution,the Result will be automatically reflected to TestLink as below.
Hi,
ReplyDeleteGreat! It's a well understood, detailed description. If I run testcase from Eclipse it's write the result to TestLink.
But how can i run this automated testcase from TestLink?
Beni
Hi i am using testlink-1.9.5, when i am running the above script i am getting following exception, please let me know how to resolve it
ReplyDeletetestlink.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 Pack3.ResultadoExecucao.reportTestCaseResult1(ResultadoExecucao.java:9)
at Pack3.TestlinkExcecution.f(TestlinkExcecution.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
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:128)
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:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
at org.testng.TestNG.run(TestNG.java:1036)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse servers response: The processing instruction target matching "[xX][mM][lL]" is not allowed.
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)
... 31 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 6; The processing instruction target matching "[xX][mM][lL]" is not allowed.
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)
... 39 more
Exception is pointing to this line: testlinkAPIClient.reportTestCaseResult(projetoTeste, planoTeste, casoTeste, nomeBuild, nota, resultado); in ResultadoExecucao class
Delete$tlCfg->api->enabled = TRUE
ReplyDelete$tlCfg->exec_cfg->enable_test_automation = TRUE
Still getting below error even after changing the config file as it is suggested above...
ReplyDeletetestlink.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 Pack3.ResultadoExecucao.reportTestCaseResult1(ResultadoExecucao.java:9)
at Pack3.TestlinkExcecution.f(TestlinkExcecution.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
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:128)
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:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
at org.testng.TestNG.run(TestNG.java:1036)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse servers response: The processing instruction target matching "[xX][mM][lL]" is not allowed.
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)
... 31 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 6; The processing instruction target matching "[xX][mM][lL]" is not allowed.
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)
I have same problem with KD and Vikas
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteWhy NullPointException???
ReplyDeletepackage testy;
import static org.junit.Assert.fail;
import java.util.concurrent.TimeUnit;
import org.apache.http.impl.conn.tsccm.WaitingThread;
import org.apache.xpath.compiler.PsuedoNames;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.server.SeleniumServer;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.thoughtworks.selenium.webdriven.commands.WaitForPageToLoad;
import testlink.api.java.client.TestLinkAPIException;
import testlink.api.java.client.TestLinkAPIResults;
import config.IConstantes;
import config.ResultadoExecucao;
@Test
public class testLogowanie implements IConstantes {
private static WebDriver wd;
private static WebDriverWait wait;
private static String baseUrl;
private static StringBuffer verificationErrors = new StringBuffer();
SeleniumServer s;
@BeforeMethod
public void setUp() throws Exception {
wd = new FirefoxDriver();
}
@Test
public void testUzytkownicySystemu() throws TestLinkAPIException {
String resultado;
String nota;
resultado = new String();
nota = new String();
try
{
//Otwarcie przeglÄ…darki
baseUrl = "http://localhost/mywebsite/public/";
wd.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
wd.manage().window().maximize();
wd.get(baseUrl);
//Logowanie
wd.findElement(By.id("login")).clear();
wd.findElement(By.id("login")).sendKeys("admin1");
wd.findElement(By.xpath("//button")).click();
//ADM. SYS. > Interesanci
wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Interesanci"))).click();
}catch (Exception e) {
resultado = TestLinkAPIResults.TEST_FAILED;
nota = e.getMessage();
e.printStackTrace();
}finally {
ResultadoExecucao.reportTestCaseResult1(PROJETO, PLANO, CASO_TESTE1, BUILD, nota, resultado);
}
}
@AfterMethod
public static void tearDown() throws Exception {
wd.close();
wd.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
This comment has been removed by the author.
ReplyDeleteI'am using https for URl and get the same error as above.
ReplyDeleteCan anyone help me for this case?
I'am investigating and the error occur at execXmlRpcMethodWithCache method in TestLinkAPIClient class.
Many thanks,
Xuyen Tran
Issue resolved by edit php.ini file and set always_populate_raw_post_data = -1
ReplyDeleteI am getting the below error-
ReplyDeletetestlink.api.java.client.TestLinkAPIException: The test case identifier null was not found and the test case Given navigate to Application and login with credentials could not be accessed to report a test result to test plan UIAutomatoion.
at testlink.api.java.client.TestLinkAPIClient.reportTestCaseResult(TestLinkAPIClient.java:199)
how can i connect to automate the pycharm code with the testlink
ReplyDelete