Selenium Configuration
Selenium Configuration
https://selenium.dev/downloads/
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
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”
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 okclick ok
click okclose
Eclipse: - It is Editor where we can write the code, compile and execute the code then
you will get the result also.
· 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 Launchclose 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.
click on 32 bit Windows IE or 64 bit Windows IE copy and paste that into
“SeleniumSoftware” folder Extract to get IEDriverServer.exe
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 packageEnter
Package name as ‘com.webdiver’
How to create class:
· Right click on package new click on classname 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.
}
}
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.
· 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.
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
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;
}
}