Thursday, July 28, 2011

How To Setup - Selenium 1.0, JDK, TestNG, ANT

How To Setup - Selenium 1.0, JDK, TestNG, ANT

Selenium setup checklist
1. JDK
2. ANT
3. Eclipse IDE
4. Eclipse TestNG
5. Selenium
6. How to start Selenium server
7. How to create selenium project in Eclipse IDE
8. How to execute code in eclipse IDE using TestNG

Select following link to for Selenium full-fledged implementation.

Note: You need to have admin privileges to install few software's.

1. JDK

Download from http://www.oracle.com/technetwork/java/javase/downloads/index.html



JDK is machine and OS dependent, Check whether your machine is 32 OR 64 Bit.
How to Check?
Programs -> Accessories -> System Tools -> System Information

Download your corresponding JRE file and install on your PC.


Check whether it is installed correctly?
Type java  -version at the command prompt, you should see the version related info.

2. ANT


It is a self installable exe file, located the java JDK directory during installation. 
Logoff and login for complete installation.
Check whether it is installed correctly?
Type ant  - version at the command prompt, you should see the version related info.

3. Eclipse IDE


It is not required to install this software, just run the exe file to open the editor.

4. Eclipse TestNG

Inside the eclipse, select   Help - > Eclipse Market Place
Search for TestNG and install directly into IDE.



5. Selenium



Unzip the file and copy Selenium Server and Selenium Java client driver FOLDERS separately for later use.



6. How to start Selenium server

In the "Selenium server" folder as mentioned above, you can find “selenium-server.jar”.
Place this file in new folder "SeleniumServer", from the command prompt opens this folder path and run following command.
Java  –jar selenium-server.jar
You will see following screen, don’t close the window (Keep it the window open)


If you see any errors, something gone wrong with the server. 

7. How to create selenium project in Eclipse IDE


Open the Eclipse IDE by selecting eclipse.exe file.
Select File->New -> Java Project


Enter project name and hit “Next”




Select “Finish”
Now you will see the project name "MyFirstProject"  in the “Package Explorer” window.
Right click on the project name and create “Package”


Click on finish after typing the package name "Selenium".


In the package explorer, right click on the package name “Selenium” and select “Configure Build Path”.



Add following JAR files showed in the below screen by selecting “Add external jar” button.
You will not be able to run your test without these files, try locating it and add those files shown in the below screen.



Now, right click on the package "Selenium" and select class


Enter class name “Test” and select Finish.



You will notice a new class is created in the package explorer.
In the same way create classes as per your requirement and place necessary code.

8. How to execute code in eclipse IDE using TestNG

Copy the code from the below link and execute the test.
http://bharath-marrivada.blogspot.com/2011/07/selenium-testng-parameterization-excel.html


If you still see any errors on the screen, place the cursor over the error code, Eclipse IDE provide auto suggestion on how to resolve the issue.


---

4 comments:

  1. Hi Bharath, This article is very nice. Could you please write similar one, Installing Selenium 2 with TestNG and simple example (Like search in google and checking returned matches contains search string).

    ReplyDelete
  2. Sure Rajesh in another 1 week. I will also include sample code for page object model implementation.

    ReplyDelete
  3. hi Bharath,
    this is yedukondalu I wrote selenium webdriver code then right code but their is no browser lunching plz tell me suggestion.

    this is My code
    package project12;

    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebDriverBackedSelenium;
    import org.openqa.selenium.chrome.ChromeDriver;

    public class project123 {
    private WebDriverBackedSelenium Selenium;

    @Before
    public void setUp() throws Exception {
    WebDriver driver = new ChromeDriver();
    String baseUrl = "http://65.111.172.80/";
    Selenium = new WebDriverBackedSelenium(driver, baseUrl);
    }

    @Test
    public static void main(String[]args) {
    } project123 project = new project123(); {
    Selenium.open("http://65.111.172.80/security");
    Selenium.type("id=User_Name", "shopmaster1");
    Selenium.type("id=Password", "test1");
    Selenium.click("id=Link");
    Selenium.waitForPageToLoad("30000");
    Selenium.click("//*[@id='awesome-menu']/li[5]/a");
    Selenium.waitForPageToLoad("70000");
    assert (Selenium.isElementPresent("css=input[id*='hdnTimeLogDate']"));


    }
    }

    ReplyDelete
    Replies
    1. For chrome you need chromedriver.exe
      System.setProperty("webdriver.chrome.driver","C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe");
      ChromeOptions options = new ChromeOptions();
      options.addArguments("--start-maximized");
      driver = new ChromeDriver(options);

      for more details read the below link
      http://bharath-marrivada.blogspot.in/2012/06/selenium2webdriver-startiefirefoxchrome.html

      Delete