- INTRODUCTION
1.1 Overview
Selenium is a portable software testing framework for web applications. Selenium provides a record tool for authoring tests without learning a test scripting language (Selenium IDE). It also provides a test domain specific language(Selenese) to write tests in number of programming languages, including JAVA, C#, Perl, PHP, Python and Ruby. The tests can be run in modern browsers.
2. SELENIUM COMPONENTS
2.1 Selenium IDE
It is the complete IDE for Selenium testing. It is implemented as Firefox extension and allows recording, editing and debugging tests. Scripts may be automatically recorded and edited manually providing auto completion support and the ability to move commands around quickly. Scripts are recorded in Selenese, a special test scripting language for Selenium. Selenese provides commands for performing actions in a browser (click a link, select an option), and for retrieving data from the resulting pages. Selenium IDE is a plug-in for Firefox that record tests. We can then export the recorded tests as conditions, iterations, and so on.
Open Selenium IDE by clicking Tools > Selenium IDE in Firefox.
Selenium IDE of firefox is
2.2 Selenium Client API
As an alternative to writing tests in Selenese, tests can also be written in various programming languages. These tests then communicate with Selenium by calling methods in the Selenium Client API. Selenium currently provides client APIs for Java, C#, Ruby and Python. With Selenium 2, a new Client API was introduced (with WebDriver as its central component). However, the old API is still supported.
2.3 Selenium Remote Control (RC)
Selenium Remote Control (RC) is a server, written in Java, which accepts commands for the browser via HTTP. RC makes it possible to write automated tests for a web application in any programming language, which allows for better integration of Selenium in existing unit test frameworks. Selenium project currently provides client drivers for PHP, Python, Ruby, Perl and JAVA. A new instance of selenium RC server is needed to launch HTML test case. However for Java/PHP test case only one Selenium RC instance needs to be running continuously. With the release of Selenium 2, Selenium RC has been officially deprecated in favor of Selenium WebDriver.
The Selenium server is simply a JAR file that you can run using the Java Runtime Environment (JRE). You can execute the Selenium server by running the following command in command prompt:
java -jar selenium-server.jar
Before performing actions in Selenium IDE, start the server and begin using the web application.
2.4 Selenium WebDriver
Selenium WebDriver is the successor to Selenium RC. Selenium WebDriver accepts commands (sent in Selenese, or via a Client API) and sends them to a browser. This is implemented through a browser-specific browser driver, which sends commands to a browser, and retrieves results.
Selenium-Web Driver was developed to better support dynamic web pages where elements of a page may change without the page itself being reloaded. WebDriver goal is to supply a well-designed object-oriented API that provides improved support for modern advanced web-app testing problems.
3. SELENIUM INTEGRATION WITH TESTLINK
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 JUnit for creating the test script with Selenium.
3.1 Prerequisites
- TestLink Version 1.9
- Testlink-api-client-2.0 and XMLRPC Client libraries.
- Java IDE(Eclipse)
- Selenium RC Libraries.
Exporting JUnit webdriver backed from selenium IDE.
3.2 Configure TestLink
◦ Create new project in testlink and enable the project with automation testing.
◦ Generate new access key. 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.
3.3 Preparing Development Environment
Add all jar into libs in eclipse.
- Testlink-client-api-2.0.jar
- Selenium RC: selenium-server.jar
- selenium-java-client-driver.jar
- Junit libs.
3.4 Sample Code
- Create a JUnit class named “Selenium_Methods ” and copy the following code:-
1 |
package com.j2eereference; |
1 |
import org.junit.After; |
1 |
import org.junit.Before; |
1 |
import org.openqa.selenium.WebDriver; |
1 |
import org.openqa.selenium.WebDriverBackedSelenium; |
1 |
import org.openqa.selenium.firefox.FirefoxDriver; |
1 |
import testlink.api.java.client.TestLinkAPIResults; |
1 |
import com.thoughtworks.selenium.SeleneseTestCase; |
1 |
public class Selenium_Methods extends SeleneseTestCase implements IConstants { |
1 |
@Before |
1 |
public void setUp() throws Exception { |
1 |
WebDriver driver = new FirefoxDriver(); |
1 |
String baseUrl = "http://192.168.0.254:8080/"; |
1 |
selenium = new WebDriverBackedSelenium(driver, baseUrl); |
1 |
} |
1 |
public void testTestcase() throws Exception { |
1 |
String result = null; |
1 |
String msg = null; |
1 |
try { |
1 |
selenium.open("/project/"); |
1 |
selenium.type("id=loginAction_userID", "user"); |
1 |
selenium.type("id=loginAction_password", "admin"); |
1 |
selenium.click("id=loginAction_0"); |
1 |
selenium.waitForPageToLoad("30000"); |
1 |
selenium.click("link=Pentium(R)D"); |
1 |
selenium.waitForPageToLoad("30000"); |
1 |
selenium.click("//a[contains(text(),'Needs\n Service')]"); |
1 |
selenium.waitForPageToLoad("30000"); |
1 |
selenium.click("link=Systems"); |
1 |
selenium.waitForPageToLoad("30000"); |
1 |
selenium.click("link=Logout"); |
1 |
selenium.waitForPageToLoad("30000"); |
1 |
selenium.click("link=Click here"); |
1 |
selenium.waitForPageToLoad("30000"); |
1 |
result = TestLinkAPIResults.TEST_PASSED; |
1 |
} catch (Exception e) { |
1 |
result = TestLinkAPIResults.TEST_FAILED; |
1 |
msg = e.getMessage(); |
1 |
e.printStackTrace(); |
1 |
} finally { |
1 |
TestClass.reportTestCaseResult(PROJECTNAME, TESTPLANNAME, |
1 |
TESTCASENAME, BUILDNAME, msg, result); |
1 |
} |
1 |
} |
1 |
@After |
1 |
public void tearDown() throws Exception { |
1 |
selenium.stop(); |
1 |
} |
1 |
} |
- Create a class TestClass ,which is responsible for sending the result of the script to Testlink.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package com.j2eereference; import testlink.api.java.client.TestLinkAPIClient; import testlink.api.java.client.TestLinkAPIException; public class TestClass implements IConstants { public static void reportTestCaseResult(String projectName,String testplanName, String testcaseName, String buildName,String msg,String result) throws TestLinkAPIException { TestLinkAPIClient testlinkAPIClient = new TestLinkAPIClient(<em>DEVKEY</em>, <em>URL</em>); testlinkAPIClient.reportTestCaseResult(projectName, testplanName, testcaseName, buildName, msg, result); } } |
- Create an interface Iconstants, with the data necessary to send the data to the Testlink, which are the parameters that were described above.
1 |
package com.j2eereference; |
1 |
public interface IConstants { |
1 |
final String <em>DEVKEY</em> = "your access key"; |
1 |
final String <em>URL</em> = "your testlink url"; |
1 |
eg: http://localhost/testlink/lib/api/xmlrpc.php |
1 |
final String <em>PROJECTNAME</em> = "TestProjectName"; |
1 |
final String <em>TESTPLANNAME</em> = "TestPlanName"; |
1 |
final String <em>BUILDNAME</em> = "BuildName"; |
1 |
final String <em>TESTCASENAME</em> = "TestcaseName"; |
1 |
} |
On this interface we gave all details of project in TestLink such as devkey, URL, ProjectName, TestPlanName, BuildName and TestcaseName.
After creating all the needed, run as JUnit test. After execution, the Result will be automatically reflected to TestLink as below.
SRIH says
May 25, 2012 at 7:05 pmHi,
this is an excellent article, I followed all the steps but the test case in TestLink still have the state “Not run”, can you give us an example to have the correct configuration specially the interface LConstants.java, Thank you 😉
I wait your answer
PS: Execuse me for my bad english
Best regards 😀
dinesh says
June 16, 2012 at 5:58 pmHi can anybody send me scwcd dumps to dineshrajkr@gmail.com…….. thx in advance
Madhumitha says
July 31, 2012 at 3:14 pmThanks for the post. It works. Is there any way to initiate the test execution from TestLink itself.?
Bharath says
August 26, 2012 at 7:13 pmHi,
I have got TestLink 1.9.3 installed on my laptop. But I think I have done something wrong somewhere.
At step# 3.2, I created a project, with Test Automation API enabled. But in the account settings page, I can not find the API access key section at all. Any help would be very much appreciated. Thanks.
Regards,
Bharath
Bharath says
August 26, 2012 at 7:46 pmGot it done, by changing config.php file for API availability. Thanks.