December 5, 2010

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();
            }

}





6 comments: