Hurry! 20% Off Ends SoonRegister Now

Automation Selenium RC using TestNG - Selenium

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.

To gain in-depth knowledge and be on par with practical experience, then explore Selenium Training Course.

Selenium Testing

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…

Related Page: Different Flavours Of Selenium

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.

Checkout Selenium Interview Questions

MindMajix YouTube Channel

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 https://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.

Related Page: How To Create Test Suites In Selenium

Testing 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
@BeforeClass
public void beforeClass() throws Exception
{
ss=new SeleniumServer();//Create an object
ss.start();//start selenium server
selenium=new DefaultSelenium("localhost", 4444, "*firefox", "https://"); //Pass arguments to selenium
selenium.start();//srat selenium server
}

@TEST
public void testFirstTNG() throws Exception
{
//open google page
selenium.open("https://www.google.com");
//maximize window
selenium.windowMaximize();
Thread.sleep(5000);
}
@AfterClass
public void afterClass()

{
//stop selenium
selenium.stop();
//stop selenium server
ss.stop();
}
}

Reports generation using Testing

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

Generating reports is easy in Testing compared to other frame works. Testing 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.

Checkout Selenium Tutorial

Creating Test suites using Testing

Creating Test suites using Testing

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.

Explore Selenium Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

 

 

Job Support Program

Online Work Support for your on-job roles.

jobservice

Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:

  • Pay Per Hour
  • Pay Per Week
  • Monthly
Learn MoreGet Job Support
Course Schedule
NameDates
Selenium Training Dec 24 to Jan 08View Details
Selenium Training Dec 28 to Jan 12View Details
Selenium Training Dec 31 to Jan 15View Details
Selenium Training Jan 04 to Jan 19View Details
Last updated: 27 Sep 2024
About Author

 

Madhuri is a Senior Content Creator at MindMajix. She has written about a range of different topics on various technologies, which include, Splunk, Tensorflow, Selenium, and CEH. She spends most of her time researching on technology, and startups. Connect with her via LinkedIn and Twitter .

read less
  1. Share:
Selenium Articles