Multi browser testing is always important. Accordingly, we should know how to run selenium scripts on all supported browsers,solet know how selenium works with different browsers. Selenium requires external browser drivers specific to browser to run the scripts. For example,
For Firefox:GeckoDriver is required.
For Chrome: ChromeDriver is required.
For IE: InternetExplorerDriver is required.
For Microsoft Edge Browser: MicrosoftEdgeDriver is required.
To perform any action on any web element on UI or webpage, you need its unique locator. For example, if you want to click on button present on UI, you must have to find ID, Name, Xpath, CSS etc. of that particular button.
Here are the available locators frequently used:
(It is not mandatory to present all above locators for each web element, so use whatever is present. But make sure ID should be the highest priority if it is present.
ID is the best way to locate web element if ID is present, as ID supposed to be unique for each element, it works fast to locate element than XPath. Look at bellow Image and HTML code and corresponding selenium code to locate element (Name text box) by using ID.
This kind of locators applies only on hyperlinks. Hyperlinks has anchor tag in HTML. This is anchor tag : a
XPath means XML Path. When any web page element does not have any unique locator then we have to use XPath. XPath can access almost any web element.
There are two types of XPath:
1) Absolute XPath
2) Relative XPath
It is the direct way to find the element, hence it is fast way to find element. but the disadvantage is that if there are any changes made in the path of the element then that XPath gets failed. It begins with the single forward slash(/) ,which means you can select the element from the root node. Syntax: html/head/body/table/tr/td Look at bellow image, I have shown you absolute XPath using Fire path.
In Relative XPath, path starts from the middle of the HTML DOM structure. ( from the node of your choice) It starts with double slash (//). Syntax: //table/tbody/tr/th Look at bellow image, I have shown you relative XPath using Fire path.
How to Identify XPath:
There are many ways and tools available to identify Xpath. Let see few ways to get XPath: Identify XPath using Fire path: In 4th tutorial above, I have mentioned how to install Fire Path Once you install Fire bug and its add-on Fire Path, inspect any web element using Fire Bug, it will give you XPath. See below image for the same.
Also you can manually identify XPath, watch video for the same.
Compared to XPath locators, CSS locators are faster. It is observed that, In Internet Explorer browser XPath works too slow, while CSS works pretty much faster. Syntax: tagName[attributename=attributeValue] input[id=FirstName]
In CSS, for ID property, we can use hash (#), so above CSS will become input#FirstName Also for Class, CSS use dot (.) For example: Input[class=fname] Input.fname
Selenium is a brilliant open source automation tool made available by ThoughtWorks Technologies. Simply it automates the browser.
We use Selenium to automate any kind of web application, Selenium supports various browsers as well as various programming languages.Indeed, it has limitations too, it cannot automate Windows component.
Selenium provides four packages; we can use anyone according to our requirement
It is Integrated Development Environment. Basically is a play and record tool works only with Firefox browser. we can record the scripts using IDE and convert it to programing languages like Java, C#, HTML etc. Like every tool, it has limitation too.
Very easy to install and use, its plugin to Firefox. No programing experience is required. We can debug and set breakpoints as well. Recorded script can convert to programing language and utilize it in RC and WebDriver.
Works only with Firefox browser. No logical statements and conditions like for and while loop. No database testing.
It cannot be used in the testing for iPhone and Android applications. Reading from external file like excel, xml, etc. not supported. Alerts, pop up not supported.
To overcome selenium IDE limitations, Selenium RC was initially developed. Basically it is developed to act as a proxy between application under test and selenium scripts. With RC we can write selenium script in any programing languages like java, c#, Perl, python etc. and run over all browsers.
Selenium RC components are: Selenium Server Selenium Server receives Selenium commands from your test program, interprets them, and reports back to your program the results of running those tests.
Client Libraries The client libraries provide the programming support that allows you to run Selenium commands from a program of your own design. There is a different client library for each supported language. A Selenium client library provides a programming interface (API), i.e., a set of functions, which run Selenium commands from your own program. Within each interface, there is a programming function that supports each Selenese command.
Supported API : JAVA, .Net, PHP, Python, Perl, Ruby.
But like selenium IDE, Selenium RC also has its limitations, every time we have to start & stop the RC server to execute scripts. As server acts as a middleware between scripts and browser, it directly impacts on execution speed to get down slow. Similarly, there are many other limitations, to overcome those limitations Selenium WebDriver came in a picture. So lets understand the advantages of WebDriver over RC,
1.With Selenium WebDriver, no need to start any server to run tests.
2.WebDriver is faster than Selenium RC since it speaks directly to the browser uses the browser's own engine to control it.
4.WebDriver can support the headless HtmlUnit browser.
5.Selenium RC cannot support the headless HtmlUnit browser. It needs a real, visible browser to operate on.
6.Web driver maintains the page load synchronization by default.
WebDriver is known as SELENIUM 2.0
Stable build of Selenium 2 (WebDriver) was released in July 2011.
Now SELENIUM 2.0 also enhanced to SELENIUM 3.0 this year 2016.
While migrating from Selenium 2.0 to Selenium 3.0, we have to take care bellow things:
You will need to be running Java 8 to use the Java pieces of Selenium.This is the oldest version of Java officially supported by Oracle, so hopefully you are using it already!
Support for Firefox is via Mozillas geckodriver.
Support for Safari is provided on macOS (Sierra or later) via Apples own safaridriver.
Support for Edge is provided by MS through their webdriver server.
Only versions 9 or above of IE are supported. Earlier versions may work, but are no longer supported as MS no longer supports them.