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']","javadomain.in");
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 javadomain.in is typed automatically at the search box and click the search button. Then from the search result it will open javadomain.in page.

Leave a Reply

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

*

* Copy This Password *

* Type Or Paste Password Here *

95,238 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>