Insights from Our Experts
Automation testing with Selenium using Python!
Software testing is an indispensable and integral part of the software life cycle in the Agile software world. Testing is done end to end to detect issues and get them resolved at every phase of development. Testing verifies that the system conforms to requirements including, functional, performance, reliability, security and usability.
Automation testing is done for Regression. Testing is done on pre-existing application functions that are carried forward to new versions to ensure that new code changes do not adversely affect them. Another reason is Smoke Testing which is carried out for getting a quick assessment of the quality of a build and making go / no-go decision on further testing. Static and repetitive tasks that remain unchanged from one cycle to the next easily give to automation. Data Driven Testing where applications are tested by inputting huge amounts of data is better automated. Performance testing including Load, Volume, and Stress are carried out only using automation tools.
Automation testing is conducted using Testing tools. Economic and technical feasibility studies are carried out on the tool before deploying it.
Some of the popular tools for conducting regression testing, performance testing and unit testing are:
Selenium is a portable software testing framework for web applications. It provides a record/playback tool for authoring tests without learning a test scripting language. It also provides a test-specific language called Selenese to write tests in a number of popular programming languages. The tests can be run against most web browsers. Selenium is open-source software and deploys on Windows, Linux and OSX platforms.
Selenium with Python
Python is well known for its dynamic and simple nature. All languages compete hard with Python in its reduced code version in few lines and quality for a common scenario. Selenium is reliable to be used with most of the popular languages but synced with Python it produces great results.
Why use Python over other languages?
- Easiness in coding and readability
- Runs faster when compared with popular languages such as Java
- Dynamic typing nature when compared with the static typing nature of Java
- Advantageous over traditional complex braces system through simple indentations
- The Python APIs can be empowered to connect with the browser through Selenium
How does this work?
Selenium test works in a three tier system namely,
- Selenium automation code written by Test engineer
- The browser driven component which executes the code and sends its own request to the browser
- Browser for running browser driven requests and returning the responses back
The following steps happen when the automation script is executed.
- HTTP request is created and sent to the browser driver for each Selenium command
- HTTP requests are served using http servers by browser driver
- HTTP server decides appropriate actions needed for executing the Selenium command
- the implementation steps are carried out on the browser
- the execution status is sent back to the HTTP server
- the HTTP server sends the status back to the automation script.
The two main flavors of Selenium are Selenium IDE and Selenium WebDriver. Both automate browsers in support of web application testing. WebDriver is typically used to create browser-based regression tests, whereas Selenium IDE is used for creating unit tests, exploratory tests and one-off bug reproduction scripts.
Selenium IDE is an integrated development environment (IDE) for Selenium tests. It is implemented as a Firefox Add-on and allows recording, editing, and debugging tests. Scripts are automatically recorded in Selenese and edited manually. Selenese provides commands for performing actions in a browser like click a link or select an option, and for retrieving data from the resulting pages.
Selenium WebDriver is the successor to Selenium Remote Control (RC), a server written in Java that accepts commands for the browser via HTTP. Selenium WebDriver accepts commands (sent in Selenese, or via a Client API) and sends them to a browser. This is implemented through a browser-specific browser driver, which sends commands to a browser, and retrieves results. Most browser drivers actually launch and access a browser application; there is also an HtmlUnit browser driver, which simulates a browser using HtmlUnit. Selenium WebDriver supports the following browsers along with the operating systems they are compatible with.
- Google Chrome
- Internet Explorer
- Android (with Selendroid or appium)
- iOS (with iOS-driver or appium)
Selenium is clearly the leader among automation tools in the industry. Because of the rapid test development that it enables, it is quite popular for quick-cycle development methodologies such as Agile or Extreme Programming. Selenium does not restrict QA’s choice of reporting tools, build systems or any other aspect of their testing framework. It integrates well with popular tools such as Hudson, SauceLabs, Selenium-Grid and QMetry.