Showing posts with label Sample script. Show all posts
Showing posts with label Sample script. Show all posts

December 13, 2010

Sample script using JUnit

December 13, 2010 0
Sample script using JUnit
Here is the sample script which will open a page...

This script was written using JUnit...


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

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

public class Google1 extends SeleneseTestCase{

private Selenium selenium;
private SeleniumServer seleniumServer;

@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iehta", "http://");
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}



@Test
public void testText1() throws Exception {
selenium.open("http://www.yahoo.com");
selenium.windowMaximize();
}
@After
public void tearDown() throws Exception {
selenium.stop();
seleniumServer.stop();
}
}

December 5, 2010

Selenium Script Explanation

December 05, 2010 6
Selenium Script Explanation
Selenium Script Explanation



Here we can see the code for simple login and logout functionality with comments and the explanation of code.

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

//Class name[class name should equal to program name]
public class Login {

 //creating a method
            public static void Login_results() throws Exception
            {
                        /*Defining the selenium method if you want to declare Default selenium outside the method you need to declare as public
public static DefaultSelenium selenium=new DefaultSelenium("localhost",4444,"*iehta","http://");
localhost—serverHost
4444 ---  serverport
Iehta ----- browserstart command(we can use *firefox also)
http:// ---browser URL(Here we can give full URL of site) */    
                     DefaultSelenium selenium=new DefaultSelenium("localhost", 4444, "*iehta", "http://");
//this command will start the selenium                
selenium.start();
//to open the URL
                        selenium.open("http://test2.xyzt.com");
//Maximizes the window
                        selenium.windowMaximize();
//to read user name
                        selenium.type("name=login[username]", "dnr5dnr@gmail.com");
//to read password       
            selenium.type("name=login[password]", "mourya");
//click login button                    
selenium.click("send2");
//waits until the page loads
                        selenium.waitForPageToLoad("50000");
//click the link sign out
                        selenium.click("link=Sign Out");
// print message
                        System.out.println("Login and Log out success");

            }
            public static void main(String[] args) throws Exception{
                        Login_results();
            }

}