Selenium-3 || First program using Selenium Web Driver.

Selenium web driver can be used using the Eclipse environment. Java is the most used programming language for the same. Let’s learn step by step to create the first program in Selenium.

Installation of Eclipse, JDK/JRE and Selenium Web Driver:

  1. Download zip folder of the latest version of Eclipse IDE from http://www.eclipse.org/downloads/
  2. Download the latest jre( Java Run Time) and install on the system.
  3. Set the path of Environment Variable under the System Properties. (till path \java\bin and \java\lib)
  4. To verify successful installation of JDK/JRE, follow below steps:
    1. Open command prompt
    2. Type Java command and press Enter
    3. The user should get below Output on command prompt
    4. Command Prompt
      Command Prompt
  5. Download language specific WebDriver from https://docs.seleniumhq.org/download/. Java is most preferred language in today’s world.

    Language Specific WebDriver
    Language Specific WebDriver
  6. We also need some third party drivers while programming such as ChromeDriver, Mozila GeckoDriver, IEDriver etc.

    Third Party Drivers
    Third Party Drivers
  7. Download the required browser driver and save on the hard disc to use later.
  8. Now double click on the Eclipse.exe to launch the application.
  9. If user get fatal error [Error 13 or Error 1], like “Unable to create Virtual Machine” due to an unknown path of the “javaw.exe” file.
    1. Open the “eclipse.ini” file in edit mode and type following syntax just above the “-vmargs” command: -vm C:\java\jre1.8.0_111\bin\javaw.exe
  10. Select the workspace as you needed.



Note:

To get detailed knowledge about JDK/JRE, visit Understand Java before start learning JAVA.

Features of Java
  1. Platform Independent Programming language. This can be achieved by creating a runnable jar file of java programs.This jar file can be run on multiple machines which supports JVM/JDK/JRE.

Note that programming language is platform independent but JVM/JDK/JRE are platform dependent. There are multiple versions of JVM/JDK/JRE depending upon the OS(MAC/Windows/Linux) 64-bit, 32-bit.

  1. Pure Object Oriented Programming language as it supports Abstraction, Encapsulation, Inheritance, Polymorphism
  2. Simple language because it does not have complex features like Operator overloading, Multiple inheritances, pointers and Explicit memory allocation.
  3. Robust Language as it handles both Memory Management Mistakes and Runtime Errors.

Memory Management Mistakes overcome by Garbage Collection(Automatic allocation and deallocation of memory when objects not in use.)

Runtime Errors: By exception handling procedures.

  1. Secure: JVM provides a virtual environment to run java programs in a secured sandbox.
  2. Distributed: Objects on one JVM (java virtual machine) can execute procedures on a remote JVM.
  3. Multithreading: Can perform multiple tasks simultaneously.

Selenium Tutorials:

Window Handling: 

Test Frameworks: 

Related Links: 


First Eclipse Program:
  1. Download latest jar files.
  2. Open URL: http://www.seleniumhq.org/download/
  3. Navigate to section “Selenium Client & WebDriver Language Bindings”
  4. Click on ‘download’ link for Java language(or as per requirement)
  5. Unzip the folder.
  6. Open Eclipse IDE and select/set workspace on the local drive.
  7. File Menu > New > Select Java Project.
  8. Enter Project Name
  9. Optional: User can select JRE version from the drop-down.
  10. Click Next
  11. Click on “Libraries” tab > Add External JARs
  12. Now locate the jar files downloaded in Step#1. and Click Finish.
  13. Under the Project Explorer > src folder > Right Click
  14. Click New > Class
  15. Give the name(Test) and press Enter.
  16. By default, these file saved with “.java” extension. (Test.java)
 Code Example:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test {
	public static void main(String[] args) 
	{
		System.out.println("Defining the type of target browser and location of the browser specific driver...");
		
		// In the below statment target browser is Chrome and chromeDriver placed under C:\
		System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
		
		// Launching the target browser.
		WebDriver driver=new ChromeDriver();
		System.out.println("Chrome Browser launched successfully...");
		
		// Send the target URL to the current browser's address bar.
		driver.get("http://www.allinoneblogs.com/");
		System.out.println("Target URL launched successfully...");
	}
}
Test Script
Test Script
Console Output
Console Output

1916total visits,2visits today

2 thoughts on “Selenium-3 || First program using Selenium Web Driver.”

Leave a Reply

Your email address will not be published. Required fields are marked *