# Selenium RC and TestNG

In this example you will learn how to use Selenium RC with TestNG. The key feature of the sample is that Selenium Server will be launched automatically by the application. Each test has description in the test methods.

Before you start automation, you need to know what are the tests and what you are going to validate. Let's break the test suite into 4 test cases.

1. Go to http://www.seleniummaster.com/seleniummastertestapp/index.php
2. Enter "test" in the Username field
3. Enter "XXXX" in the Password filed
4. Click on the Login button
5. Verify that the text "Selenium Test" is present.

Test 2 (openUserSettingPage)
1. Click on the Settings link on the top of the page
2. Enter "test" in the Username field
3. Enter "XXXX" in the Password filed
4. Click on the Login button
5. Verify that Account Prefernces page displayed.

# Selenium RC Handling HTTPS and Security Popups

Some web applications use SSL certificates, so that they switch from HTTP to HTTPS to send encrypted information such as passwords or credit card information. This is common with many of today's web application. Selenium RC supports this by default.

In some cases, users need to add https site as a trusted site in their browsers and create a custom profile for using in Selenium RC. This way, users can avoid Security Popups.

# Selenium RC Run Single Test Case As Test Suite With Command

Sometimes, users want to run a single test case directly within the server using -htmlSuite parameter.  This can be achieved by saving a single test case as a Test Suite.  For example, we have a login test case called "SeleniumMasterLoginTest.html".

Step 1: we save the above test case as a test suite. We name the test suite as "SeleniumMasterLoginTestSuite.html".

# Selenium RC Multi-Window Vs Single-Window Mode

In Selenium RC, users can run tests under Multi-Window mode or Single-Window mode. Multi-Window mode is the default behavior by default. Some application may not run correctly in a sub frame, and needed to be loaded into the top frame of the window. The Multi-Window mode option allows users to run the tests in a separate window rather than in the default frame.

# Using Proxy in Selenium RC

When your application under test is behind an HTTP proxy that requires authentication during the test, you should configure http.proxyHost, http.proxyPort, http.proxyUser and http.proxyPassword using the following command.

For example, if you have a proxy like this below:

# Run Selenium RC with Google Chrome

In some cases, to verify web application compatibility with Google Chrome, QA Engineers need to run Selenium RC tests with Google Chrome.

Here are the two options to run tests on Google Chrome.

1. Add the directory containing "chrome.exe" to your system PATH environment. For example, if chrome.exe is under the location "C:\Program Files (x86)\Google\Chrome\Application", you need to add this to your system environment path and reboot your computer. Once you setup the path to chrome.exe and reboot your pc, you can launch your test suite with this command below.

te.html" "c:\SeleniumTestCase\chromeresult.html"

# Selenium RC Server Logging

Selenium RC Server Logging has two options: Server-Side Logs and Browser-Side Logs.

Server-Side Logs:

When launching Selenium server with the -log option, the server can record valuable debugging information reported by the Selenium Server to a text file.

For example: this command below will create a file named "selenium.log" under c:\SeleniumTestCase folder.

C:\selenium-java-2.39.0>java -jar selenium-server-standalone-2.39.0.jar -log c:\SeleniumTestCase\selenium.log

Content of the selenium.log file:

21:38:36.175 INFO [1] org.openqa.grid.selenium.GridLauncher - Launching a standalone server
21:38:36.379 INFO [1] org.openqa.selenium.server.SeleniumServer - Writing debug logs to c:\SeleniumTestCase\selenium.log
21:38:36.380 INFO [1] org.openqa.selenium.server.SeleniumServer - Java: Oracle Corporation 23.21-b01
21:38:36.380 INFO [1] org.openqa.selenium.server.SeleniumServer - OS: Windows 7 6.1 amd64
21:38:36.396 INFO [1] org.openqa.selenium.server.SeleniumServer - v2.39.0, with Core v2.39.0. Built from revision ff23eac
21:38:36.484 INFO [1] org.openqa.selenium.remote.server.DefaultDriverSessions - Default driver org.openqa.selenium.iphone.IPhoneDriver registration is skipped: registration capabilities Capabilities [{platform=MAC, browserName=iPhone, version=}] does not match with current platform: VISTA
21:38:36.491 INFO [1] org.openqa.selenium.remote.server.DefaultDriverSessions - Default driver org.openqa.selenium.iphone.IPhoneDriver registration is skipped: registration capabilities Capabilities [{platform=MAC, browserName=iPad, version=}] does not match with current platform: VISTA
21:38:36.544 INFO [1] org.openqa.selenium.server.SeleniumServer - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
21:38:36.545 INFO [1] org.openqa.jetty.http.HttpServer - Version Jetty/5.1.x
21:38:36.546 INFO [1] org.openqa.jetty.util.Container - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
21:38:36.547 INFO [1] org.openqa.jetty.util.Container - Started HttpContext[/selenium-server,/selenium-server]
21:38:36.547 INFO [1] org.openqa.jetty.util.Container - Started HttpContext[/,/]
21:38:36.601 INFO [1] org.openqa.jetty.util.Container - Started org.openqa.jetty.jetty.servlet.ServletHandler@215bfaa5
21:38:36.601 INFO [1] org.openqa.jetty.util.Container - Started HttpContext[/wd,/wd]
21:38:36.606 INFO [1] org.openqa.jetty.http.SocketListener - Started SocketListener on 0.0.0.0:4444
21:38:36.606 INFO [1] org.openqa.jetty.util.Container - Started org.openqa.jetty.jetty.Server@6fae53e9

Another example: this example below creates a debug.log file with debug information and nnn.log file

C:\selenium-java-2.39.0>java -jar selenium-server-standalone-2.39.0.jar -debug -log c:\SeleniumTestCase\debug.log -DSelenium.LOGGER=nnn.log
Setting system property Selenium.LOGGER to nnn.log

Browser-Side Logs:

JavaScript on the browser side also logs important messages. To access browser-side logs, pass the -browserSideLog argument to the Selenium Server.

For example: this command below creates a log on the browser side under c:\SeleniumTestCase folder. If -log option is not defined, the server console will display all the debug information.

C:\selenium-java-2.39.0>java -jar selenium-server-standalone-2.39.0.jar -browserSideLog -log c:\SeleniumTestCase\browserside.log

Debug.log file content:

# How to Run Selence Directly Within the Server Using -htmlSuite

After you record test cases or test suite with Selenium IDE, you can run Selenese html files directly within the Selenium Server by passing the html file to the server's command line.

java -jar selenium-server-standalone-<version-number>.jar -htmlSuite "*firefox"
"c:\absolute\path\to\my\results.html"

For example, we have recorded a login test case and user setting change test case and saved it as a test suite  "SeleniumMasterLoginModuleSuite.html" file (see the screenshot below).

# How to Run Selenium Server

To run selenium 1.0 automated test cases, you need to start (run) Selenium Server.  Go to the directory where the Selenium RC's server is located(downloaded), and then run the following from a command-line console.

java -jar selenium-server-standalone-<version-number>.jar

For example, if you have downloaded the server jar files in the directory below, enter the directory in the command line console and type the command below.

C:\selenium-java-2.39.0\java -jar selenium-server-standalone-2.39.0.jar

### When the server is running, the screenshot looks like this:

Of you can go to this site below and download the Selenium Server jar file.