Configuring Selenium in NetBeans

  • Open the NetBeans IDE and open a new project.
 

  • Select Java Application and click next

  • Type the name  “LearnToTestSelenium” in the project name

  •  Right click the libraries and add JAR/Folder

  •  Add Select the selenium-java-client-driver.jar

  •  Next Right click on the <Default Pack> and select a java package.

  •  Name the Package Name as “LearnToTestSelenium” and click finish

  • Now select a new java class

  •  Enter the name as Learn2TestSelenium and click Finish

  •  After this step the package should look something like the below screenshot

  • Copy the below code and paste the same in code window.

/*
  */

package LearnToTestSelenium;
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;

/**
 *
 * @author
 */

public class Learn2TestSelenium extends SeleneseTestCase {
            public static Selenium selenium ;
        public static String strURL = "http://krishnalearnsselenium.blogspot.com/";


    public void setUp() throws Exception {
/* You need to change the directory in which the firefox.exe is located Normally it is
 *located under C:\\Program File
 *
 */
        selenium = new DefaultSelenium("localhost",
                4444, "*firefox C:\\other_programs\\mozilla_firefox\\firefox.exe", strURL);
        selenium.setSpeed("3000");
        selenium.start();
        selenium.deleteAllVisibleCookies();
        //browser.open(getPropertiesValue.PORTAL_URL);
        selenium.open(strURL);
    }
    public void tearDown() throws Exception {
        selenium.stop();
        System.out.println("inside after class");
    }

            public void testBlogentry() throws Exception {
                        //selenium.open("/");
                        verifyEquals("Installing Selenium RC:", selenium.getText("//div[@id='Blog1']/div[1]/div/div/div[1]/div/div[2]/div[7]/b/span"));
            }
}

  • The Selenium server must be up and running before Running the test from NetBeans. So  start the server from the the desktop (Refer to this LINK for  information on how to run the Selenium server from desktop)

  • Build the file and Run the file. Finally  After the test passes it should look like the below screen-shot

  • Congratulations you have configured Selenium in NetBeans. Wish you Happy Testing using Selenium RC.

I will be posting more as I discover more on selenium and JUNIT .


Note: 
If you liked this post then click on any of the advertisements shown in this page...So, I will get paid for the efforts.
Don't worry these ads are by Google and they are not malicious ;-)