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:
- Download zip folder of the latest version of Eclipse IDE from http://www.eclipse.org/downloads/
- Download the latest jre( Java Run Time) and install on the system.
- Set the path of Environment Variable under the System Properties. (till path \java\bin and \java\lib)
- To verify successful installation of JDK/JRE, follow below steps:
- Download language specific WebDriver from https://docs.seleniumhq.org/download/. Java is most preferred language in today’s world.
- We also need some third party drivers while programming such as ChromeDriver, Mozila GeckoDriver, IEDriver etc.
- Download the required browser driver and save on the hard disc to use later.
- Now double click on the Eclipse.exe to launch the application.
- 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.
- 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
- Select the workspace as you needed.
Note:
To get detailed knowledge about JDK/JRE, visit Understand Java before start learning JAVA.
Features of Java
- 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.
- Pure Object Oriented Programming language as it supports Abstraction, Encapsulation, Inheritance, Polymorphism
- Simple language because it does not have complex features like Operator overloading, Multiple inheritances, pointers and Explicit memory allocation.
- 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.
- Secure: JVM provides a virtual environment to run java programs in a secured sandbox.
- Distributed: Objects on one JVM (java virtual machine) can execute procedures on a remote JVM.
- Multithreading: Can perform multiple tasks simultaneously.
Selenium Tutorials:
- Selenium-1 || Understanding Selenium and Selenium WebDriver.
- Selenium-2 || Let’s learn Selenium IDE.
- Selenium-3 || First program using Selenium Web Driver.
- Selenium-4 || Handling multiple web browsers.
- Selenium-5 || Locating web elements using various type of Locators.
- Selenium-6 || XPath is the best way to locate web elements.
- Selenium-7 || Let’s learn to create complex XPath.
- Selenium-8 || Implementing Wait(s) in Selenium.
- Selenium-9 || Understanding WebDriver API.
- Selenium-10 || Taking Screenshots using Selenium
- Selenium-11 || Use of Actions and Action Classes.
- Selenium-12 || Select Class to handle drop-down.
- Windows Handling | Multiple windows handling using JavascriptExecutor.
- iFrame || Multiple ways to handle iFrame html tag using selenium.
- iFrame || iFrame Handling within a web page.
- getWindowHandle() and getWindowHandles() methods.
- Properties File | Accessing properties file for user input or test data.
- Framework || Simple example of Key Driven Framework using excel sheet in Selenium(JAVA).
- TestNG – 16 || Access data from Excel sheet using DataProvider.
- Selenium Grid | Configuration and implementation with Example.
- TestNG – 1 || Introduction and benefits of TestNG Framework.
- TestNG – 2 || Installation process and a sample program of TestNG.
- TestNG – 3 || Create and execute multiple Test Cases.
- TestNG – 4 || Let’s understand @Test Annotation and attributes.
- TestNG – 5 || Understand Assertion in TestNG.
- TestNG – 6 || Use of @BeforeMethod and @AfterMethod.
- TestNG – 7 || Use of @BeforeClass and @AfterClass.
- TestNG – 8 || Creation and execution of Test Suites.
- TestNG – 9 || Let’s move deep into the Test Suites.
- TestNG – 10 || Use @BeforeTest and @AfterTest Annotations.
- TestNG – 11 || Groups attribute with @Test Annotation.
- TestNG – 12 || Use of @BeforeGroups & @AfterGroups.
- TestNG – 13 || Use of @BeforeSuite & @AfterSuite.
- TestNG – 14 || DataProvider annotation & attribute.
- TestNG – 15 || DataProvider with parameters.
- TestNG – 16 || Access data from Excel sheet using DataProvider.
- TestNG – 17 || Passing multiple Parameters in testng xml.
- TestNG – 18 || Multiple Browser and Parallel Execution in TestNG.
- TestNG -19 || Concept of Parallel Execution.
- TestNG – 20 || Run TestNG Program using main() method.
- Headless Testing via ChormeOptions Class.
First Eclipse Program:
- Download latest jar files.
- Open URL: http://www.seleniumhq.org/download/
- Navigate to section “Selenium Client & WebDriver Language Bindings”
- Click on ‘download’ link for Java language(or as per requirement)
- Unzip the folder.
- Open Eclipse IDE and select/set workspace on the local drive.
- File Menu > New > Select Java Project.
- Enter Project Name
- Optional: User can select JRE version from the drop-down.
- Click Next
- Click on “Libraries” tab > Add External JARs
- Now locate the jar files downloaded in Step#1. and Click Finish.
- Under the Project Explorer > src folder > Right Click
- Click New > Class
- Give the name(Test) and press Enter.
- 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..."); } }


Thank You for this.
Hope you are doing well. If you Like my posts please Subscribe us and Share your thoughts. So that we could serve you better:
Yotube: https://www.youtube.com/channel/UCyd9tmuHrlfCqA0c5YX9-gQ/featured?sub_confirmation=1
Blogs: http://www.allinoneblogs.com
Ask a Question: http://www.allinoneblogs.com/ask-a-question/
Thanks!!!
allinoneblogs