Introduction To Selenium
What is Selenium?
Selenium is an open-source test automation tool used to test web applications and mobile applications. It allows testers to automate the testing process, making it more efficient and reliable.
- Open Source: Free to use and modify.
- Test Automation Tool: Software used to test other software.
- Web Application: Applications accessed via a web browser.
- Mobile Application: Applications designed to run on mobile devices such as smartphones or tablets.
Key Points:
- To test web applications, use Selenium WebDriver.
- To test mobile applications, use Appium.
- Selenium is a headless tool, meaning it does not have a user interface.
Advantages of Selenium
- Open Source: Selenium is free to download and use for both personal and business purposes. Its source code is open for:
- Downloading: Free to Download
- Viewing: Easy debugging.
- Customization: Enhancements can be made.
- Distribution: Share enhancements with the community.
- Integration: Can be integrated with third-party tools.
- Multiple Programming Languages: Selenium supports various programming languages, providing flexibility and making it easier for developers to use without learning new languages. Supported languages include:
- Java
- C#
- Python
- JavaScript
- PHP
- Perl
- Ruby
- Haskell
- Dart
- Go
- Kotlin
- Multiple Operating Systems: Selenium supports all major operating systems like:
- Windows
- Mac
- Linux
- Appium extends this support to Android and iOS for mobile apps.
- Multiple Browsers: Selenium supports several major browsers, including:
- Chrome
- Opera
- Firefox
- Internet Explorer
- Microsoft Edge
- Safari
- Headless browsers like PhantomJS and HTMLUnit for GUI-less testing.
Disadvantages of Selenium
- Limited to Web and Mobile Applications: Selenium can automate only web and mobile applications, not standalone applications.
- Programming Skills Required: Test engineers need programming skills to write and maintain Selenium scripts.
- Maintenance of Scripts: Small changes in the application’s UI can break the scripts, requiring constant updates.
Selenium vs. QTP (Quick Test Professional)
Selenium:
- Open Source
- Supports Windows, Mac, and Linux
- Supports multiple browsers
- Supports 11+ programming languages
- Automates web and mobile applications
QTP:
- Licensed
- Supports only Windows
- Supports IE and MS Edge
- Uses VBScript and JavaScript
- Automates all kinds of applications
Flavors of Selenium
- Selenium Core: The first version supporting Java.
- Selenium RC (Remote Control): Supported multiple languages but had proxy server issues.
- Selenium IDE: A record and playback tool supporting only Chrome and Firefox.
- Selenium WebDriver: Supports all programming languages and browsers.
- Selenium Grid: Runs tests on remote machines.
- Appium: Tests mobile applications.
Selenium WebDriver Architecture
![Selenium_Architecture](https://browserstack.wpenginepowered.com/wp-content/uploads/2023/09/Selenium-WebDriver-Architecture.png)
Selenium WebDriver architecture includes four main components:
- Selenium Client Bindings/Language Bindings: Libraries provided for different programming languages.
- JSON Wire Protocol: A standard for data exchange between client and server.
- Driver Executable Software: Browser-specific drivers that receive requests and perform actions on the AUT.
- Browser and AUT: The browser and the application under test.
Components in Detail:
- Client Bindings: Libraries for various languages, e.g., selenium-server-standalone.jar for Java.
- JSON Wire Protocol: Converts automation scripts into a standard format that drivers can understand.
- Driver Executable Software: Includes server and browser-specific APIs for performing actions.
- Browser and AUT: Where the actual testing is performed.
Getting Started with Selenium WebDriver in Eclipse
Prerequisites:
- JDK 1.8 and above
- Eclipse Photon and above (2020 or 2021)
Setup Steps:
- Create a Java project in Eclipse.
- Create a package.
- Write and run a “Hello World” program.
- Create folders for drivers and JAR files.
- Copy driver executables and Selenium JAR files to respective folders.
- Add Selenium JAR files to the build path.
Downloading Java Client Bindings and Drivers
Java Client Bindings:
- Visit Selenium Downloads .
- Click on the latest stable version .
Chrome Driver:
- Check the browser version.
- Visit Selenium Downloads .
- Scroll to the browser section and expand it.
- Click on the documentation link under Chrome or any Browser.
- Download the latest stable version .
- Extract and locate chromedriver.exe.
Launching a Browser in Selenium WebDriver
- Set the Driver Executable Path: Use
System.setProperty()
with the browser-specific key and driver path.Example: System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
- Create Browser Class Object: Create an object of the browser class to launch the browser.
Example: WebDriver driver = new ChromeDriver();
Selenium WebDriver Hierarchy
![selenium_webdriver-hierarchy](https://www.lambdatest.com/blog/wp-content/uploads/2023/01/selenium252520webdreiver252520hierarchy-2.png)
- SearchContext: Interface for finding elements (findElement(), findElements()).
- TakesScreenshot: Interface for taking screenshots (getScreenshotAs()).
- JavaScriptExecutor: Interface for executing JavaScript (executeScript(), executeAsyncScript()).
- RemoteWebDriver: Concrete class implementing all major interfaces.
- WebDriver: Core interface for controlling the browser with methods like get(), getTitle(), navigate(), etc.
By understanding and leveraging Selenium’s capabilities, you can enhance your testing process, ensuring efficient and reliable test automation.
Author: Akash Deb (SDET)
Comments
Post a Comment