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