Automation Selenium RC using TestNG

Selenium Remote Control

Selenium Remote Control (RC) is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.
Selenium RC comes in two parts.

  1. A server which automatically launches and kills browsers, and acts as an HTTP proxy for web requests from them.
  2. Client libraries for your favorite computer language.

Selenium TestNG

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionality that make it more powerful and easier to use, such as:

  • JDK 5 Annotations (JDK 1.4 is also supported with JavaDoc annotations).
  • Flexible test configuration.
  • Support for data-driven testing (with @DataProvider).
  • Support for parameters.
  • Allows distribution of tests on slave machines.
  • Powerful execution model (no more TestSuite).
  • Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc…).
  • Embeds BeanShell for further flexibility.
  • Default JDK functions for runtime and logging (no dependencies).
  • Dependent methods for application server testing.

TestNG is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc…

Why use TestNG with Selenium RC ?

Selenium IDE by itself is great for creating test cases and executing single tests. TestRunner is ok at running a test suite. But if you want full automation against different server and client platforms, you need a way to invoke the tests from a command line process, flexibility in how you create your test suites, and reports that tell you what happened. TestNG provides these features. You can use Selenium RC with other languages as well, but since Sakai is written in Java it makes sense to stick with the language most of us are familiar with already.

How to Install TestNG plugin in Eclipse

TestNG is a testing framework inspired from JUnit and NUnit, but introduces some new functionalities that make it more powerful and easier to use.

  • Go to tolls–install new software
  • Install window will be opened.Click ADD button.
  • In Add repository window –Enter names as TestNG and URL http://beust.com/eclipse
  • Click OK.
  • Select TEstNG and click Next. And again, click Next next…after installing testing, just restart Eclipse to reflect the changes.

TestNG sample script

package one;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class FirstTNG {
public SeleniumServer ss;//Create a variable
public Selenium selenium;//Create a variable

public void beforeClass() throws Exception
ss=new SeleniumServer();//Create an object
ss.start();//start selenium server
selenium=new DefaultSelenium("localhost", 4444, "*firefox", "http://"); //Pass arguments to selenium
selenium.start();//srat selenium server

public void testFirstTNG() throws Exception
//open google page
//maximize window

public void afterClass()
//stop selenium
//stop selenium server

Reports generation using TestNG

TestNG is required to generate the reports. Without testNG this code won’t work.

Generating reports is easy in TEstNG compared to other frame works. TestNG will generate reports automatically. After running the script just refresh the project. Right click on Project and click Refresh…then u can see a new folder test‐output..expand that folder, you can see INDEX.html and emailable‐report.html. These two files are the reports.

Creating Test suites using TestNG

A test suite is a collection of test cases intended to test a behavior or a set of behaviors of software programs.

For TESTNG we need to create a test suite using XML file. For sample XML file, we can use the (index.html) report created automatically.

1. Click on Index.html
2. Click on LINK under testing.xml column.
3. Copy the XML code.
4. Now create an XML file (Right click on Project‐‐‐New ‐‐‐‐ File)
5. Give file name as testing.xml and copy the code in that file
6. Save the file.
7. Under Classes tag.add classes…and save it..
8. Right click on the XML file from Package Explorer and runas‐testngsuite..
9. The scripts will run one after the other and report is created automatically.


0 Responses on Automation Selenium RC using TestNG"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.