Selenuim Training Notes
Selenuim Training Notes
1. Selenium used to automate only web-based applications not for windows-based client server
applications
2. It’s open source suite of tools, mainly used for functional and regression test automation
3. It will support various operating environments: windows, linux, MacOS etc., but UFT will support
only windows OS.
4. It supports various browser environments (Chrome. IE, Firefox, Safari). To launch different
browsers, we need to use browser drivers.
5. Selenium IDE will support only firefox browser.
6. Selenium supports various programing environments: Java, python, C#, Perl, Ruby, PHP but UFT
supports only VB script.
7. Most of the companies will use java for selenium.
History of selenium:
1. First came into market in 2004 and 2006 selenium web driver launched and In 2008 selenium
team merged all selenium tools to form a powerful tool called selenium 2.0
Selenium IDE:
Features of IDE:
1. Create test case and test suites (recording feature or we can manually enter the commands
if you know them)
2. Edit test cases
3. Executing the test cases, test suites
4. Debug the test cases
5. Enhance the test cases
6. Export test cases
7. Default format of selenium ide is .html
Selenium Grid:
1. Not for test case design only for test case execution
2. Grid is used to execute the test cases across multiple browsers, operating environments and
machines in parallel
3. Selenium grid supports selenium RC tests as well as selenium web driver tests
1. By using gecko driver we will launch the firefox. Gecko driver is a class in selenium we must
create object of gecko driver.
2. To launch the gecko driver we have another class called firefox driver and it’s available in
selenium we have to import it.
3. This firefox driver is implementing one interface called web driver.
4. If we are executing with out the driver ‘.exe’ file we will get following error: Exception in
thread "main" java.lang.IllegalStateException: The path to the driver
executable must be set by the webdriver.gecko.driver system property;
5. Same as firefox, chrome also follows the same above steps.
Basic methods:
Launching the safari driver: in mac open any browser and search for extension ‘Safari extension for
selenoum’go to downloads download the latest version
And add that extension in preferences.
--- now one more setting needs to be done in safari preferences section: enable ‘allow remote
automation’ preferencesadvanceselect check box show develop menu in menu barnow click on
develop menuyou will find option called ‘allow remote automation’ and select it
Whatever written after angular bracket ‘<’ is called html tag of that element. In selenium everything is
called elements.
Locators in Selenium:
2.id
3.name
4.linkText: only for links, all the links are represented by ‘a’ tag
5.PartialLinkText: we never use partial link text, it will be used when name of the link is long.
If class is there—‘.’(class)
7.Class—but not recommended, class name can be duplicate for other element.
Priorities of locators:
1. ID
2. Xpath/CssSelector
3. Name
4. linkText
5. className
There is class select class in selenium, just create the object of select class. We I must import it from
selenium support.
We don’t perform actions like send keys or click for drop downs. For handling dropdowns, we have few
methods in selenium:
1. selectByVisibleText() – it will select the option based on the visible text. Recommended to use
this method.
2. If we are trying to deselect the single option selected in drop down then we will get below error
Exception in thread "main" java.lang.UnsupportedOperationException: You may
only deselect options of a multi-select
3. getFirstSelectedOption() //to get the first selected option in dropdown it will work for both the
type of dropdowns.
4. getOptions();-- if we want to see all the options available we have to use for loop with size()
condition, if we are using this will get below error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 36,
Size: 36
In order to remove this error we need to use size()-1.
Alert() method will give alert class object reference of alert class.
Selenium can’t handle the windows popups. like uploading the file popup
For handling file upload it will opens the windows pop-up which cannot be handle by selenium but using
the selenium sendKeys() method we can upload file. For the ‘browse’ button make sure that it’s having
the type as ‘file’
Sometimes in page we have elements located inside the frame. If we are following the normal approach
the we will get errors like no element exception or element not found excetion. To handle the elements
present in frame we will use SwitchTo() metod.
Create reference for string type set class to store the multiple window id’s and use iterator to switch
between windows. Set will not store the values based on indexing.
Set object: set will not store the values based on the index. To get the value from set object we have to
use iterator () method. This iterator method will give you the iterator of string.
We can handle the mouse actions by using the ‘Actions’ class. For actions class we have to pass the
driver reference.
For drag and drop also we need to use Actions class. First we need to click and hold the element and
drop it to the target element by using release method
Implicitwait():
Take screenshot:
1. first take the screenshot using the ‘getScreenshotAs()’ method and type cast the driver
reference to take screenshot interface then it will give us the file object.
2. Now by using the copy file method copy the screenshot into the location where we want to
store it.
Code:
//Take screenshot and store as file format
File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Whatever the generic things are there we will declare them here, like URL, username, password etc.,
To read the property file we must create the object of property file. This class is available in java and we
have another class ‘FileInputStream’
Fileinputstream will connect to properties file. It will create an input stream between our java code and
config.properties file.
Then load the file using prop.load() metod by passing file input stream reference variable.
1. isDisplayed(): is for all the elements. It is used to check whether the element is available on the
page or not.
2. isEnabled(): if we enter or fill all the required data then only some fields like ‘submit’ , ‘Cancel’
buttons will be enabled. To check these kind of elements we will use this method.
3. isSelected(): this method is used only applicable for checkbox, dropdown, radio button.
WebTable:
TestNG:
--unit test frame work, junit and testing both are unit testing frameworks.
-- developer will use this frame work to develop the unit level test case, but automation developer can
also use this framework with selenium to develop the good test cases
--in other words it is also called as TDD means test driven development
Purpose: design the test cases in a systematic way, it will generate the very good html reports
--dependency feature
Open source and freely available in the market. Available in the form of jar files
--and it is also called as java unit testing framework it’s only used for selenium with java. For c# nuinit is
available.
-- no need to select the main method option as testNG automatically executes the main method
Annotations in TestNG:
Annotations will be appended by ‘@’ symbol. Always annotation should be associated with one method.
1. @BeforeClass
Features: