Nowadays, application development is much faster. So there is a need to test those applications fast within a short period of time. Here ‘Automation’ is testing plays an important role. It reduces the manual testing time/effort and produces more appropriate testing output. There are lots of automation testing tools available in the market.
Selenium is one of the most popular and widely used automation testing suites. It is open source and appropriate for web based application testing across different platforms and browsers. Selenium was first introduced in 2004.
Selenium is not just a single automation testing tool. But it actually comprises of a bunch of software, supporting different testing needs of the application. Let us have a look at its four basic components.
- Selenium IDE: This is a Firefox plugin used to create simple automated tests. It has a recording feature which allows recording user actions and saving it as a script. This script is a reusable component.
- Selenium Remote Control (RC): This is a tool which allows users to control the browser by using programming languages
- Selenium Webdriver: It allows scripts to communicate directly with the browsers.
- Selenium Grid: It allows running testes in parallel on various remote machines.
Now let us have a look at some advanced tips used in Selenium scripting
Efficient use ‘waits’: The most common solution for ‘waiting’ (for some processing to be completed) is to use Thread.Sleep (). But it is not confirmed that the processing will be completed within the specified time mentioned in Thread.Sleep (). So the solution is to use WebDriverWait class. It uses a mechanism to pool the query after a specified time period until the wait condition is fulfilled. This is also known as ‘explicit’ wait.
Keep environmental parameters in a text/xml file: It is always recommended to keep all your environmental parameters in a central text/xml file. And then parse the file to get the correct information. It helps your tests to be independent of a particular parameter/value.
Perform Drag & Drop: Always use WebDriver’s Action Builder API for ‘Drag & Drop’ operations. The two methods are ‘DragAndDrop’ and ‘DragAndDropToOffset’. More low level ‘Drag & Drop’ can be performed but those techniques are rarely used.
Windows and iframe switching: Always use driver.SwitchTo ().Frame () and driver.SwitchTo ().Window () methods for switching between windows and iframes.
Closing browsers: Use WebDriver’s following APIs to close the browser after the test is complete.
- Quit (): This is used to close all the browsers.
- Close (): This is used to close the current browser
- Dispose (): This will internally call Quit () method and has the same effect
Selenium as a testing suite is evolving continuously and it will have more new features in near future. Hope the above tips will help you running Selenium testing more efficiently.