0% found this document useful (0 votes)
58 views

Selenium Configuration

The document provides steps to configure Selenium WebDriver with Java. It describes downloading Eclipse, JDK, the Selenium server standalone JAR file, and ChromeDriver. It also explains how to set up a project in Eclipse, including creating packages and classes, configuring JAR files, and writing a test script to open a URL.

Uploaded by

Nikhitha Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Selenium Configuration

The document provides steps to configure Selenium WebDriver with Java. It describes downloading Eclipse, JDK, the Selenium server standalone JAR file, and ChromeDriver. It also explains how to set up a project in Eclipse, including creating packages and classes, configuring JAR files, and writing a test script to open a URL.

Uploaded by

Nikhitha Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 14

How to configure or setup Selenium WebDriver with java:

To configure selenium WebDriver, need below


Eclipse, JDK (8), Selenium_server_standalone_3.*.*.jar
We can download from the below
https://www.eclipse.org/downloads

https://selenium.dev/downloads/

Note: To open eclipse java should be installed in your system.


How To download and install JDK-8:
Open browser Navigate to below URL
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Java is platform independent (It works for each and every O.s)
Scroll down till this comes

Note: Based on your System type and respective O.S we need to download
Select Accept License Agreement Radio Button (shown above)
click on link jdk-8u231-windows-x64.exe link (If your System type is 64 bit) jdk-
8u231-windows-i586.exe (If your System type is 32 bit)

It will expect Oracle username and password (Create account or use these Credentials)

Username: [email protected]
Password: Oracle21dec
Note: O is capital letter

Wait until complete download


Create one folder like “SeleniumSoftwares” in drive and Paste that download (JDK-
8.exe) file into that folder
double click on that jdk-8u231-windows-x64.exe You will get window popup shown
below

click next wait till you get following window popup shown below
again click next wait till you get following window popup shown below
again click next (you will get following window popup shown below) wait until
complete installation process like shown below

After finishing the installation you will get the msg “Successfully installed “
And then click close Button (shown below)
After completing we need to check Java is successfully installed or not by browsing Java
folder find these folders jdk and jre in “C:\Program Files\Java” or in “C:\Program
Files(x86) \Java”

How to set Environment Variables for Java:


We need set the Environment variables
Copy location of JDK (C:\Program Files\Java\jdk1.8.0_221)
Click on start button Right click on My Computerclick on Properties
click on Advanced System Settings
click on Environment variables
navigate to System variables
click New
Enter Details like:
Variable name: JAVA_HOME
Variable value: C:\Program Files\Java\JDK 1.8

click ok
Select PATH variable click on Edit Press end key and place semicolon
at the end and enter %JAVA_HOME%\bin (If the OS is windows7)
If the OS is windows10 Select path variable click on Edit click on
New Provide the value %JAVA_HOME%\bin like shown below
Click okclick ok
click okclose

To check Java is successfully installed or not


Click start buttonenter cmd (in search)Go to command Prompt Enter command
>java -version (You will get version of the jdk)
Selenium-server-standalone jar file: -

Navigate to below url


https://selenium.dev/downloads/
click on Latest stable version 3.141.59 (right below corner)

copy and paste into ‘SeleniumSoftware’ folder

How to install Eclipse:

Eclipse: - It is Editor where we can write the code, compile and execute the code then
you will get the result also.

Launch google site Enter Eclipse Neon downloadNavigate to below url


https://www.eclipse.org/downloads/packages/release/oxygen/3a
click on download link with respect to OS (Based on the System type (32 bit or 64 bit)
we need to download Eclipse)
wait until complete download
Copy Eclipse folder and paste that in “SeleniumSoftware” folder (It is not necessary to
install it)
Unzip it Open Eclipse (Extracted folder)

Right click on Eclipse.exe ( )and Send to Desktop (create shortcut)

double click on blue icon eclipse.exe ( ) continue to openLaunch

· By default, it displays some path in the workspace if required we can update the path
· if you want to use another workspace
click on browse click on any drive  click on New folder and name it as
“SeleniumWorkspace” and then select click on Launchclose welcome tab
(Your scripts are stored in this Workspace)
· Workspace is the folder where it contains the test scripts. Click ok on workspace
launcher window.

Downloading Drivers: ChromeDriver, GeckoDriver, Opera Driver, IEDriverServer,


Safari Driver
How to configure selenium with ChromeDriver:
Open Chrome browser click on three dots select help

click on about Google chrome and find Version number.

Navigate to url https://selenium.dev/downloads/


 Scroll down till this comes (Selenium Client & WebDriver Languages Bindings)

Navigate to Selenium Client & WebDriver Languages Bindings

click on other languages exist link


click on Releases Link (beside Google ChromeDriver)
choose according to Chrome Browser version You will get another tabclick on
chromedriver_win32.zip  copy and paste that into “Seleniumsoftware “ folder 
Extract to get “chromedriver.exe”

Gecko Driver download for Mozilla Firefox:


Open Firefox browser  click on menu click on help click on about fire fox  check if
update needed and update version.
Navigate to https://selenium.dev/thirdparty/

click on Releases Link (beside Mozilla geckodriver)


 Scroll down until this comes

click on geckodriver-v0.26.0(based on your system)

 copy and paste that into “seleniumsoftware” folder


 Extract to get “geckodriver.exe”

Downloading IEDriverServer for running script in IE


Open IE browser click on tools tab click on Internet Options Click on
Securitycheck whether protected mode is click on for all Zones (either checked
mode or unchecked mode)
Navigate to https://selenium.dev/downloads/
click on The Internet Explorer Driver Server (based on our OS system type (x86 or 64 bit)

click on 32 bit Windows IE or 64 bit Windows IE copy and paste that into
“SeleniumSoftware” folder Extract to get IEDriverServer.exe

Opera Driver Download:


Navigate to https://selenium.dev/thirdparty/  Scroll down the page

 Navigate to Current Releases

click on Releases Link (beside Opeara chromium driver)


click on Operadriver_win.zip (based on your Operating system type)  copy and
paste that into “seleniumsoftware “folder  Extract to get “operadriver.exe”
System.setProperty("webdriver.opera.driver", "C:\\Users\\sushma\\operadriver.exe");
WebDriver driver = new OperaDriver();
driver.get("http://selenium4testing.com/");

Selenium configuration in Safari Driver:


Open Safari browser go to “https://selenium.dev/” site. click on version of recent
SafariDriver wait until complete download Double click on the Download to install
 close safari browser  We no need to set property value

WebDriver driver = new SafariDriver();


driver.get("http://selenium4testing.com/");

Create a workspace:
WorkSpace: It is Project location where I write my code.
How to Create a project
· Navigate to a file menu, click on new and select project.
· Select the java project then click on next.
· Give the project name as ‘SeleniumProject’.
· Check that java SE 1.8. From the field use an execution environment JRE then click
on finish.
· Click on Open Perspective click on finish.
How to create a package:
· Expand “SeleniumProject“ Right click on src folder new packageEnter
Package name as ‘com.webdiver’
How to create class:
· Right click on package new click on classname it as ‘HMSLaunch’
Select public static void main(String args[]) check box click on finish
· Right click on Project and click on New and click on Folder Name it as ‘lib’ and click
on finish
· Copy all jars like Selenium standalone, poi, log4J, commans-io paste from Unzipped
folder paste in ‘lib’ folder in project
· Right click on ‘Project’ and click on new and click on folder, name it as ‘resources’
and click finish.
· Right click on ‘resources’ and click on new folder and name it as ‘drivers’ and click
on finish.

How to configure Jars:


Expand the selenium automation project
· Right click on Project select build path then select configure build path.
 click on libraries tab Click on add external Jars Navigate to location ‘lib’
(where you saved all jar )and select selenium server standalone jar file click on
open click on apply and close

Test Script 1: Write a program to open the URL


Package: com.webdriver

Class name: HMSLaunch.java

Public class HMSLaunch {

Public static void main(String args[])


{
//Disable notifications
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver","C:\\sushma\\chrome\\chromedriver.exe");
//launch the chrome browser
WebDriver driver = new ChromeDriver(options);
//maximize the chrome browser window
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//navigate to url “selenium4testing.com” site
driver.get("http://selenium4testing.com/");

}
}
Public static void main (String args[]): -
It is the main method which is responsible for Execution
· Public: Public is the access specifier due to which we can access it from outside
the class. it is intended for the purpose of the JVM to execute the main method
from any location.
· Static: Static is a modifier. The main method must be declared as static so that the
JVM can access the main method directly by using the class name. there is no need to
create any instance of it

As we know main method also reside inside a class and to access the particular
function of a class from outside the class (In this case from JVM), an instance of that
particular class is needed, so to avoid these we simply put static to make access main
method outside of class.

If we remove static then it becomes instance method, to access an instance method


we should create object and then invoke the method using the object reference

· void: Void is the return type of main method. The Caller of the main method is
JVM and the JVM does not expect any value from the main method and therefore the
main method should not return any value. This is the reason for specifying Void.

· main: Main is the method name and it is fixed as per the Java coding
conventions.
· (String args[]): String is a pre-defined class name in java. And args [] is a
variable name of String type object. It is used for storing the command line arguments.
The name of the array can be any valid Java identifier.

So, we can also change the name of args[]. String class and its object can be passed in
a running program as an argument to pass information to the main method from
command line.
System.setProperty("webdriver.gecko.driver", "C:\Drivers\geckodriver.exe")

· The first argument sets the browser name which would be used while execution.
And the second argument specifies the driver path for respective browser

· This driver would be in .exe format and varies from browser to browser.

· In selenium, you use this method because the browser doesn’t have a built-in
server to run the automation code so you will need a Chrome/IE/Gecko (according to
requirement) driver server for communicating your Selenium code to the browser.

WebDriver driver = new ChromeDriver ();


· We generally do it this way because usually we want to be able to run our tests on
multiple browsers. If we declare the driver as a specific driver type, we are then anchored
to only that driver.

Having reference variable of type WebDriver allows us to assign the driver object
different browser specific drivers. Allowing multi-browser testing by assigning the driver
Object to any of the desired browser.

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

The Implicit wait will tell the web driver to wait for a certain amount of time before it
throws a “No Such Element Exception”. The default setting of Implicit wait is zero. Once
you set the time, the web driver will wait for that particular amount of time before
throwing an exception.

Note: Implicitly wait is applied globally which means it is always available for all the web
elements throughout the driver instance. once you set that time it is set for the entire
driver instance and applied everywhere. It implies if the driver is interacting with 100
elements then, implicitly wait is applicable for all the 100 elements.

Scenario2: -write a program to test the login functionality of hms by using the
credentials user1 and user1

Refer the Programs from selenium4testing.com/downloads


Package: com.webdriver
class name: HMS_Login
· Give the package name as com.webdriver, take a new class by right clicking on
the project, click on new and select class and give the class name as HMS_logn,
then select the checkbox public static void main then click on finish
· To perform action on any field we need the locator. we can take the locators for
every browser we are having the below addon for different browsers
· To take the locator, right click on the field click on inspect element(Q), then use
either ID or Name or any locator.
Browser Addon
· Firefox inspect element
· IE developer tools
· Google chrome ChroPath, inspect element
· Safari inspect element
· Opera inspect element

ChroPath - Google Chrome


How to Install ChroPath in Google chrome: You can also copy the XPath Expressions and CSS
Selectors locators that are auto-generated by Chropath
Open Chrome browser  Enter “ChroPath install” or click on link
https://chrome.google.com/webstore/detail/chropath/ljngjbnaijcbncmcnjfhigebomdlkcjo?hl=en

click on Add To Chrome--> Click on 'Add Extension' option on the displayed dialog

package webdriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class HMSLogin {

public static void main(String[] args) {


System. setProperty("webdriver.chrome.driver",”C:\\Users\\sushma\\
chromedriver.exe");
//launch the chrome browser
WebDriver driver = new ChromeDriver();
//maximize the chrome browser window
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//navigate to url
driver.get("http://selenium4testing.com/hms/");
//locating an Element By using name locater and sending the value to the
TextBox field
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin");
//locating an Element By using name locater and performing click
operation
driver.findElement(By.name("submit")).click();

}
}

You might also like