Selenium server standalone example

Step 1: Download the selenium,

selenium-server-standalone-2.28.0.jar (31.5MB).

Step 2: Download the junit-4.3.1. jar, http://mirrors.ibiblio.org/pub/mirrors/maven2/junit/junit/4.3.1/junit-4.3.1.jar

Step 3: Open the command prompt and run as follows,

“java -jar selenium-server-standalone-2.28.0.jar”

Step 4: Open the eclipse and create the project, Step 5: Create the java project named “Selenium” and create the class named “JavadomainTest.java”  and paste the below code,

import org.junit.Test;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class JavadomainTest{

@Test
public void jdtesting() throws InterruptedException{

Selenium selenium = new DefaultSelenium("localhost",4444,"firefox","http://google.com");
selenium.start(); //starting selenium instance
selenium.open("/");
selenium.windowMaximize();
selenium.windowFocus();
selenium.type("//*[@id='gbqfq']","ngdeveloper.com");
selenium.click("//*[@id='gbqfb']");
Thread.sleep(20000);
selenium.click("//*[@id='rso']/li[1]/div/h3/a/em");
Thread.sleep(80000);
selenium.close(); //to close the browser
selenium.stop(); //to stop selenium instance

}
}

 Step 6: Rightclick on the project -> Build path -> Configure build path -> Libraries -> Add external jars -> (browse the location of downloaded selenium and junit jar file) -> ok. Step 7: Right click on the project -> Run As -> Junit Test.

output:

Mozilla firefox will open with www.google.com and ngdeveloper.com is typed automatically at the search box and click the search button. Then from the search result it will open ngdeveloper.com page.

Leave a Reply