
Basics of Selenium Automation
Learn the Basics of Selenium Automation for web testing. Understand key features, setup, and benefits to kickstart your automation testing journey.
SELENIUM OVERVIEW
Selenium came into existence in 2004 when Jason Huggins, an engineer at Thoughtworks, was testing an application and developed a JavaScript library to run tests against different browsers
In 2006, an engineer at Google named Simon Stewart started work on Webdriver
In 2008, the Selenium team decided to merge Webdriver and Selenium RC into Selenium 2
WHAT IS SELENIUM?
Selenium is a widely adopted open-source automation testing framework that is designed to help users test web applications across various browsers and platforms.
Selenium is not just a single tool but a set of tools that help testers to automate web-based applications more efficiently.
COMPONENTS OF SELENIUM
Selenium Components are often referred to as a suite of Selenium tools. There are a total of four tools which are together called the Selenium Components.
Let us discuss the various components of Selenium • Selenium IDE
• Selenium RC
• Selenium Webdriver
• Selenium Grid
SELENIUM IDE - FEATURES
• An automated testing tool that is released as a Firefox plug-in
• Simplest and easiest tools to install, learn, and to create test scripts
• It is based on a record and playback fundamental, and also allows editing of the recorded scripts
• User is not required to possess any prior programming knowledge
• Exporting test cases to different languages
SELENIUM IDE - LIMITATIONS
• Being a Firefox plug-in, Selenium IDE supports only Firefox; thus, the created test scripts could be executed only on Firefox.
• Random Test case execution is not possible • Test results are generated in the form of a summary
• Doesn't support control flow statements
• Data-driven testing (executing tests with multiple sets of Test data) is not possible
SELENIUM RC -FEATURES
• Supports various languages like Java, C#, Python, Perl, Ruby and hence supports
• control flow
• Iterations
• Exception handling
• Test reporting
• Database testing
• Capturing screenshots
• Supports random Test case execution
• Supports multiple browsers for test execution
SELENIUM RC -LIMITATIONS
• Test case execution time is longer because the client request first gets sent to Selenium Server and then to Browser
• Test results are generated in the form of a summary
• Data-driven testing (executing tests with multiple sets of Test data) is not possible
• Test execution in parallel is not possible
• Doesn't support headless browsers like the HTMLUnit browser
SELENIUM GRID
• Selenium Grid is a tool used to run parallel tests across different machines and different browsers simultaneously, which results in minimized execution time.
• Allows the Selenium RC solution to scale for large test suites that run in
multiple environments
• Different tests can be run on different remote machines
SELENIUM WEBDRIVER
• It is designed in a simpler and more concise programming interface, along with addressing some limitations in the Selenium-RC API
• Selenium WebDriver is the successor to Selenium RC, which sends commands directly to the browser and retrieves results.
• WebDriver is a compact object-oriented API when compared to Selenium 1.0
• It drives the browser much more effectively and overcomes the limitations of Selenium 1.x, which affected functional test coverage, like the file upload or download, pop-ups, and dialog barriers
• Selenium 1.0 + WebDriver = Selenium 2.0
ADVANTAGES OF SELENIUM
• Selenium is a free and open-source tool.
• Can be extended for various technologies that expose the DOM.
• Supports multiple browsers.
• Supports multiple operating systems, and platforms. • Supports mobile devices.
• Supports headless and parallel executions. • Has a big community support for help in case of issues.
Explore Other Demanding Courses
No courses available for the selected domain.
LIMITATIONS OF SELENIUM
• Supports only web-based applications.
• No support for QR, captcha, and barcode, scenarios.
• No feature such as Object Repository/Recovery Scenario.
• No default test report generation.
• Programming and technical knowledge required.
• It requires time to be more compatible and stable with new browsers.
WHAT SELENIUM CAN NOT DO?
• Selenium cannot test mobile applications (requires integration with Appium),
• Selenium cannot test handle Captchas and barcodes directly
• Selenium cannot test desktop applications
• Selenium cannot automatically manage test cases and generate reports
• Handling of dynamic web content is a major challenge
IMPORTANCE OF SELENIUM WEBDRIVER
Selenium Webdriver came into existence to overcome the problems of the Selenium RC. The architecture of Selenium RC is not an easy one, and it requires a lot of time to complete the test execution.
Selenium Webdriver, on the other hand, has a simpler architecture, and communicates directly with the web browsers, thereby making execution time shorter. Hence, Selenium WebDriver became more popular than Selenium RC.
SELENIUM AS AN AUTOMATION TOOL
✓Free of Cost
✓Application architecture support only for web ✓Support for multiple Programming languages in Automation script – Java, C#, Ruby, Perl, PHP, Python
✓Multiple Browser support – Firefox, IE, Safari, Chrome, Opera, Android, IOS, headless browser – HTMLUnit, PhantomJS
✓TestNG for Reporting
✓Has API support available to update results in the Test Management tool like Testlink
AUTOMATION USING SELENIUM WEBDRIVER
Selenium-WebDriver makes direct calls to the browser using each browser’s native support
Selenium Webdriver – Multi-browser support to open Firefox Browser
import org.openqa.selenium.firefox.FirefoxDriver;
System.setProperty(“wedriver.gecko.driver”, “path of driver file”)
WebDriver driver = new FirefoxDriver();
To open the Chrome Browser
Import org.openqa.selenium.chrome.ChromeDriver;
System.setProperty(“wedriver.chrome.driver”, “path of driver file”)
WebDriver driver = new ChromeDriver();
To open the HTMLUnit Browser
import org.openqa.selenium.htmlunit.HtmlUnitDriver; WebDriver
driver = new HTMLUnitDriver();
IMPORTANT METHODS IN SELENIUMWEBDRIVER Browser Commands
get(String args)
The above Selenium command launches a new browser window and navigates to the specified URL.
The command accepts a single string-type parameter, which is usually the URL of the application under test
Syntax:
driver.get(“http://www.google.com”);
getCurrentUrl()
As the name suggests, this Selenium command gives us the URL of the page
Currently loaded in the browser.
Syntax:
getTitle()
String url = driver.getCurrentUrl();
If you want to retrieve the title of the currently opened web page, you can use
The above command.
Syntax:
String j = driver.getTitle();
getPageSource()
The above command will help you to get the source of the last loaded page and
also to verify if a particular content is present or not by using the contains
method.
Syntax:
String j=driver.getPageSource();
boolean result = driver.getPageSource().contains("String to find");
Public static WebDriver driver;
getClass()
If you’re looking to return the run-time class name of the object, you can use the above command to get it done. Syntax: driver.getClass();
Navigation Command:
navigate().to() :
It creates a new browser window with a new web page. It takes a String parameter and returns a void value. Syntax: driver.navigate().to("http://www.google.com")
refresh() : to refresh the current window.
Syntax: driver.navigate().refresh();
back() : go back to the previous page that you visited. Syntax: driver.navigate().back();
forward() :
Similar to back action, the forward action is also a widely used navigation action. So you can use the above command to redirect to the page you were in before clicking on the back button.
Syntax: driver.navigate().forward();
close():
The close() command is used to close the currently open
WebDriver-controlled browser window. If the current window is the only
active window in WebDriver, the browser will also be closed.
Syntax: driver.close();
quit() :
There is a minor distinction between the quit() and close()
methods. The quit() method terminates all open browser instances, whereas
the close() method terminates only the current browser instance.
Syntax: driver.quit()