Creating script in Selenium

Below are few steps through which we can write own Selenium script:
1. After successfully launch of eclipse(See previous post “Installation”), now we will create a Java project. For example “TestProject” in below image.

2. When we expand above project in Eclipse, we see the src folder and default JRE System Library. Inside src folder, create a new package. For example named “sanityTests”.

3. Inside package, create a Java file. For example
4. After creating Java class, create a method. For example openApplication().
5. Now add @Test annotation above the method name and import TestNG in class. TestNG provides a test execution which executes this @Test annotation.
6. For executing selenium script we need to specify web browser driver object on which we have to execute the test script. And also we need to import FirefoxDriver class and WebDriver interface in the program. In this script, we will create firefox browser object and execute our script on firefox.
7. To open a url, we need to use either get() or navigateTo() methods with parameter as url of the application.
8. Save the program and run this program as TestNG.
9. Program execution opens a new firefox browser and open the url.
10. At the end, we need to close the browser window using driver.exit() or driver.close() methods.