Monday, June 3, 2013

Selenium Using Java

For Java, we need to use either JUnit or TestNG as the test engine. Some
development environments like Eclipse have direct support for these via plug-ins.
This makes it even easier.
You will probably want to rename the test class from “NewTest” to something of
your own choosing.
Also, you will need to change the browser-open parameters in the statement

selenium = new DefaultSelenium("localhost", 4444, "*iehta", "http://www.google.com/");
The Selenium-IDE generated code will look like this. This example has comments
added manually for additional clarity.

package com.example.tests;
// We specify the package of our tests

import com.thoughtworks.selenium.*;
// This is the driver’s import. You’ll use this for instantiating a
// browser and making it do what you need.

import java.util.regex.Pattern;
// Selenium-IDE add the Pattern module because it’s sometimes used for
// regex validations. You can remove the module if it’s not used in your
// script.

public class NewTest extends SeleneseTestCase {
// We create our Selenium test case
public void setUp() throws Exception {
setUp( "http://www.google.com/" , "*firefox" );
// We instantiate and start the browser
}
public void testNew() throws Exception {
selenium.open( "/" );
selenium.type( "q" , "selenium rc" );
selenium.click( "btnG" );
selenium.waitForPageToLoad( "30000" );
assertTrue(selenium. isTextPresent( "Results * for selenium rc" ));
// These are the real test steps
}
}

No comments:

Post a Comment