Single Post

Header

Friday, October 23, 2015

how to configure selenium rc in eclipse



Configure Selenium RC/WebDriver with Eclipse


I.Softwares Required and Installation for Eclipse , Selenium

1. Download Java JDK and Install

http://www.java.com/en/download/index.jsp (java download  link)

2.Download Eclipse

http://www.eclipse.org/downloads/ (Eclipse IDE for Java EE Developers) -->zip file

3.Download Selenium Libraries

http://seleniumhq.org/download/
a.Selenium Server (formerly the Selenium RC Server)  (Download version 2.25.0)  --> .jar file
b.Language Client Version  Release Date  (Java 2.25.0)   --> zip file
Note : For Selenium WebDriver - We need to extract this zip file And Put all the jar files in one folder


II.Configuration steps for Selenium Setup
1.Create a folder for workspace (any folder name)
2. Extract the above eclipse zip inside the <workspace> folder
3.Create a folder inside <workspace> folder called lib (any folder name).
   copy the above selenium 2 library files inside <lib> folder
4. Create a new Java Project in eclipse
File->New->Java Project (Enter any project name)  ->Finish
5. Add Selenium Libraries : In Eclipse
Expand the project (which we created) ->Right Click on (Java System Library) ->Build Path ->
Configure Build Path -> Add External Jars (Click) ->(Browse and Choose the selenium libraries .jar and all .zip file .jar files) ->ok
6.Configure External Jars : In Eclipse
Run ->External Tools -> External Tools Configurations ->Program (Double Click)
a.Enter any config name
b.In Location ->Browse File System ->(Give path of java.exe in your system)
Ex:   C:\Program Files\Java\jdk1.6.0_30\bin\java.exe
c.In Working Directory ->Browse File System ->(Give path of selenium Lib <.jar and .zip files located>)
Ex: E:\Selenium\VenkyLib 
d.In Arguments  ->(give like below <can give any 4 digit port number>)
-jar selenium-server-standalone-2.25.0.jar -port 8888
e.Apply -> Run (It will run selenium server)

Now the Selenium Configuration is ready





















Selenium Simple Examples - Java (Selenium RC)

Selenium Simple Examples - Java (Selenium RC)

1.Open Google website , type any word and click on search button

import com.thoughtworks.selenium.DefaultSelenium;

public class GoogleSearch
 {

    public static void main(String[] args)
    {       
        DefaultSelenium ds=new DefaultSelenium("localhost",8888,"*firefox","http://www.google.co.in/");
          ds.start();
          ds.windowMaximize();
          ds.open("/");
          ds.type("q", "india");
          ds.click("btnK");   
        }
}

2.Open Gmail website , give username and password.Click on Sign in button
import com.thoughtworks.selenium.DefaultSelenium;

public class GmailLogin_Selenium
{
       public static void main(String[] args) throws Exception
    {
        DefaultSelenium ds=new DefaultSelenium("localhost",8888,"*firefox","http://www.gmail.com");
          ds.start();
          ds.windowMaximize();
          ds.open("/");
          ds.type("Email", "<username>");
          ds.type("Passwd", "<pwd>");
          ds.click("signIn");      
    }
}


3.Open YahooMail,Sing In and Check whether the sign in is happened or not

        import com.thoughtworks.selenium.DefaultSelenium;
        public class YahooMail_isText_Selenium
        {           
            public static void main(String[] args) throws Exception
            {
                DefaultSelenium ds=new DefaultSelenium("localhost",8888,"*firefox","http://www.yahoomail.com");
                  ds.start();
                  ds.windowMaximize();
                  ds.open("/");
                  ds.type("login",
"<username>");
                  ds.type("passwd",
"<pwd>");
                  ds.click(".save");
                  Thread.sleep(10000);
                  if(ds.isTextPresent("Sign Out")) {
                      System.out.println("Signin is Success") ;
                  } else {
                      System.out.println("Signin is not Success") ;
                  }
                                 
            }

        }


Thursday, October 1, 2015

Simple Example for TestNG FrameWork with Selenium RC

I am giving sample example for TestNG Framework for Selenium : (Selenium RC)
I have used Inheritance concept also.

1.Create one Launch.java as below
import com.thoughtworks.selenium.DefaultSelenium;
public class Launch {
   
    static DefaultSelenium ds;

    public static void fn_launch(String br,String url)
    {
      ds=new DefaultSelenium("localhost",8888,br,url);
      ds.start();
      ds.windowMaximize();
      ds.open("/");
       
    }
}

2.GoogleSearch_Launch.java program which is given classname and method name in testng.xml
import org.testng.Reporter;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class GoogleSearch_Launch extends Launch
  {
    @Test
    @Parameters({"browser"})

    public static void resultspresent(String b) throws Exception
        {
        fn_launch(b,"http://google.co.in");
        ds.type("q", "selenium");
        ds.click("btnK");
        Thread.sleep(5000);
        if(ds.isElementPresent("resultStats"))
        {
            Reporter.log("<font color='green'><B>Results are displayed</B></font>");
        }
                
    }
}

3.Create TestNG.xml like below

<suite name="mysuite">
 <test name="mytest_firefox">
  <parameter name="browser" value="*firefox" />
    <classes>
       <class name="GoogleSearch_Launch"/>
        <methods>
          <include name="resultspresent" />
        </methods>           
    </classes>       
  </test> 
 
   <test name="mytest_ie">
  <parameter name="browser" value="*iehta" />
    <classes>
       <class name="GoogleSearch_Launch"/>
        <methods>
          <include name="resultspresent" />
        </methods>           
    </classes>       
  </test> 
 </suite>