Selenium is a suite of tools for automated web testing. It is composed of
- Selenium IDE (Integrated Development Environment) : It is a tool for recording and playing back. It is a firefox plugin
- WebDriver and RC: It provide the APIs for a variety of languages like Java, .NET, PHP, etc. With most of the browsers Webdriver and RC works.
- Grid: With the help of Grid you can distribute tests on multiple machines so that test can be run parallel which helps in cutting down the time required for running in browser test suites
Selenium 3.0 is the latest version of Selenium. It has released 2 beta versions of selenium 3.0 with few of the below changes:
Here are few new features added to Selenium 3.0
|Beta 1 updates
||Beta 2 updates (Only for Java)
- Minimum Java version is now 8+
- System property webdriver.firefox.marionette now forces the server in marionette or legacy firefox driver mode, ignoring any related Desired Capability
- It will support for Firefox Via Mozilla’s geckodriver
- Grid fixes NPE’s on registration when -browser not specified
- Support for Edge is provided by MS
- It now supports Safari on MacOS via Apple’s own Safari driver
- Update GeckoDriver –port argument in all bindings
In Selenium every object or control in a web page is referred as an elements, there are different ways to find an element in a web page they are
- PartialLink Text
- Xpath etc
For web based application testing selenium can be used
The test types can be supported are
a) Functional, Learn More about Functional testing
For post release validation with continuous integration automation tool could be used
c) Quick Build
Assertion is used as a verification point. It verifies that the state of the application conforms to what is expected. The types of assertion are “assert” , “verify” and “waifFor”.
X-Path is used to find the WebElement in web pages. It is also useful in identifying the dynamic elements.
Refer Complete Guide on Xpath
Technical challenges with Selenium are
- Selenium supports only web based applications
- It does not support the Bitmap comparison
- For any reporting related capabilities have to depend on third party tools
- No vendor support for tool compared to commercial tools like HP UFT
- As there is no object repository concept in Selenium, maintainability of objects becomes difficult
Assert: Assert allows to check whether an element is on the page or not. The test will stop on the step failed, if the asserted element is not available. In other words, the test will terminated at the point where check fails.
Verify: Verify command will check whether the element is on the page, if it is not then the test will carry on executing. In verification, all the commands are going to run guaranteed even if any of test fails.
In JAVA a special form of syntactic meta-data can be added to Java source code, this is know as Annotations. Variables, parameters, packages, methods and classes are annotated some of the Junit annotations which can be useful are
To click on specific part of element, you would need to use clickAT command. ClickAt command accepts element locator and x, y co-ordinates as arguments- clickAt (locator, cordString)
Selenium is more popular than QTP as
- Selenium is an open source whereas QTP is a commercial tool
- Selenium is used specially for testing web based applications while QTP can be used for testing client server application also
- Selenium supports Firefox, IE, Opera, Safari on operating systems like Windows, Mac, Linux etc. however QTP is limited to Internet Explorer on Windows.
- Selenium supports many programming languages like Ruby, Perl, Python whereas QTP supports only VB script
Four parameters that you have to pass in Selenium are
- Port Number
Both will delay the speed of execution.
Thread.sleep () : It will stop the current (java) thread for the specified period of time. Its done only once
- It takes a single argument in integer format
Ex: thread.sleep(2000)- It will wait for 2 seconds
- It waits only once at the command given at sleep
SetSpeed () : For specific amount of time it will stop the execution for every selenium command.
- It takes a single argument in integer format
Ex: selenium.setSpeed(“2000”)- It will wait for 2 seconds
- Runs each command after setSpeed delay by the number of milliseconds mentioned in set Speed
This command is useful for demonstration purpose or if you are using a slow web application
The “Same Origin Policy” is introduced for security reason, and it ensures that content of your site will never be accessible by a script from another site. As per the policy, any code loaded within the browser can only operate within that website’s domain.
To avoid “Same Origin Policy” proxy injection method is used, in proxy injection mode the Selenium Server acts as a client configured HTTP proxy , which sits between the browser and application under test and then masks the AUT under a fictional URL
The purpose of heightened privileges is similar to Proxy Injection, allows websites to do something that are not commonly permitted. The key difference is that the browsers are launced in a special mode called heightened privileges. By using these browser mode, Selenium core can open the AUT directly and also read/write its content without passing the whole AUT through the Selenium RC server.
You can use “submit” method on element to submit form-
element.submit () ;
Alternatively you can use click method on the element which does form submission
Implicit Wait: Sets a timeout for all successive Web Element searches. For the specified amount of time it will try looking for element again and again before throwing a NoSuchElementException. It waits for elements to show up.
Explicit Wait : It is a one-timer, used for a particular search.
You can use…..driver.findElements(By.xpath(“//iframe”))….
This will return list of frames.
You will ned to switch to each and every frame and search for locator which we want.
find element ():
It finds the first element within the current page using the given “locating mechanism”. It returns a single WebElement
findElements () : Using the given “locating mechanism” find all the elements within the current page. It returns a list of web elements.