Pages

WebDriver Introduction & Architecture

What is Automation Testing and Advantages?

Automation testing is the process of using specialized software tools to execute test cases and validate the functionality and performance of a software application or system. Automation testing can be used to supplement manual testing, or it can be used as a standalone testing method.

There are several benefits to using automation testing:

  1. Efficiency: Automation testing allows test cases to be executed faster and more accurately than manual testing, which can save time and resources.

  2. Repeatability: Automation testing allows test cases to be run multiple times with consistent results, which can be useful for verifying that changes to the application have not introduced any new defects.

  3. Coverage: Automation testing allows a larger number of test cases to be executed in a shorter time, which can help to improve the coverage of the testing effort and increase the chances of identifying defects.

  4. Reliability: Automation testing can be more reliable than manual testing, as it is less prone to human error.

Automation testing is not a substitute for manual testing, and it is typically used in conjunction with manual testing to provide a comprehensive testing approach. However, automation testing can be a valuable tool for improving the efficiency and effectiveness of the testing process.

When you can go for automating the applications?

There are several factors that can influence the decision to automate the testing of a software application or system:

  1. Complexity: Applications that have a high degree of complexity, such as those with many interdependent components or a large number of test cases, may be good candidates for automation testing.

  2. Frequency: Applications that need to be tested frequently, such as those with a rapid release cycle or those that are subject to constant changes, may benefit from automation testing to reduce the time and resources required for testing.

  3. Repeatability: Applications that have test cases that need to be run multiple times with consistent results, such as those that are subject to regression testing, may be good candidates for automation testing.

  4. Risk: Applications that have high risks associated with defects, such as those with mission-critical functions or those with high security requirements, may benefit from automation testing to ensure that defects are identified and addressed in a timely manner.

  5. Cost: Automation testing can be more expensive to set up and maintain than manual testing, so it may not be cost-effective for all applications. Applications that are likely to see a significant return on investment from automation testing, such as those with a high volume of test cases or those that require frequent testing, may be good candidates for automation.

Ultimately, the decision to automate the testing of an application will depend on a combination of factors, including the complexity and risk of the application, the frequency and repeatability of the testing, and the cost and resources required to automate the testing process.

when you should not go for automation of the applications?

There are several situations where automation testing may not be the most appropriate approach for testing a software application or system:

  1. When the application is still in the early stages of development: Automation testing requires a well-defined and stable application, and it may not be practical to automate the testing of an application that is still in the early stages of development and is subject to frequent changes.

  2. When the application has a short lifespan: Automation testing can be expensive to set up and maintain, and it may not be cost-effective for applications that have a short lifespan or are not expected to undergo significant changes.

  3. When the application has a complex user interface: Automation testing can be challenging for applications with complex user interfaces, as it can be difficult to automate interactions with the user interface in a reliable and consistent manner.

  4. When the application requires significant manual testing: Some types of testing, such as usability testing or exploratory testing, may be more effectively performed manually rather than automated.

  5. When the application has a low risk of defects: If the application has a low risk of defects and is not critical to the organization's operations, it may not be necessary to invest in automation testing.

Overall, the decision to automate the testing of an application should be based on a careful assessment of the specific characteristics and requirements of the application, as well as the cost and resources required for automation. Automation testing can be a valuable tool for improving the efficiency and effectiveness of the testing process

What are the different components of selenium?

Selenium is a suite of software tools that are used for the automated testing of web applications. The main components of Selenium include:

  1. Selenium WebDriver: This is a library that allows developers to automate the testing of web applications using the browser's native support for automation. It provides a common interface for interacting with web browsers, and it allows developers to write scripts in a variety of programming languages to simulate user actions and validate the functionality and performance of a web application.

  2. Selenium IDE (Integrated Development Environment): This is a browser extension that allows developers to record and replay user actions in a web application. It can be used to create test cases and test scripts, and it can be run against a web application to validate its functionality.

  3. Selenium Grid: This is a tool that allows developers to run Selenium test cases in parallel across multiple machines, browsers, and platforms. It can be used to improve the efficiency of the testing process by allowing tests to be run simultaneously on different machines and browsers.


What is a selenium webdriver?
Selenium WebDriver is a software testing tool that allows developers to automate the testing of web applications using the browser's native support for automation. It is a widely-used open-source tool that is compatible with a range of different browsers, including Chrome, Firefox, Safari, and Internet Explorer.
Selenium WebDriver is designed to provide a common interface for interacting with web browsers, and it allows developers to write scripts in a variety of programming languages, including Java, Python, C#, and Ruby. These scripts can be used to simulate user actions, such as clicking links, entering text into forms, and navigating between pages, and they can be run against a web application to validate its functionality and performance.
Selenium WebDriver is often used in conjunction with other testing tools, such as Selenium IDE (Integrated Development Environment) and Selenium Grid, to provide a comprehensive testing solution for web applications. It is a powerful tool that is widely used in the software testing industry and is well-suited for automated testing of web applications.
What Are the Selenium’s Advantages?

Selenium, as a powerhouse in the realm of test automation, brings a host of advantages to the table, making it a preferred choice for many organizations and individual testers alike. Here are some key benefits of Selenium automated testing:

  • Suitable with major types of browsers: One of the standout features of Selenium is its ability to run tests across a variety of browsers like Chrome, Firefox, Safari, and Internet Explorer. This ensures that web applications function smoothly across all user platforms;
  • Language flexibility: Unlike some other testing tools, Selenium supports all modern languages, including Java, C#, Python, Ruby, and JavaScript. This flexibility allows testers to write scripts in the language they are most comfortable with or one that aligns best with the project requirements;
  • Can run tests in parallel: Using Selenium Grid, you can run several tests in parallel, reducing the time for test execution and speeding up the feedback loop for development teams;
  • Huge community: Being open-source, Selenium has a robust and active community. This community contributes to constant improvements and updates, providing a wealth of resources, guides, and forums for troubleshooting and learning;
  • Vast integration capabilities: Selenium can be easily integrated with other tools like TestNG and JUnit for managing test cases and generating reports and with tools like Jenkins for Continuous Integration/Continuous Deployment (CI/CD) pipelines;
  • No cost: Being open-source, it's free to use, which makes it accessible for small businesses or individual developers without the budget for expensive proprietary tools;
  • Versatility and high performance: Selenium WebDriver’s ability to interact directly with the browser brings a high level of realism to testing scenarios, making it possible to simulate almost any action a user could perform;
  • Platform independent: Tests written using Selenium can be run on different operating systems like Windows, Mac, and Linux, offering a great deal of flexibility in terms of test environments.

These pros make Selenium an ultimate all-in-one tool, suited for a wide range of web app testing scenarios, from simple to complex.

What Are the Selenium’s Disadvantages?

While Selenium stands as a robust tool in the automation testing landscape, Selenium-based testing does come with certain limitations. Understanding these can help QA professionals make informed decisions when selecting tools for their projects:

  • Little support for desktop apps: Selenium is primarily designed for web application testing. It does not support testing of desktop applications, which can be a limitation for projects requiring testing beyond web environments;
  • No built-in reporting and test management: Selenium lacks built-in features for reporting and test management. Creating reports or managing tests, requires integration with third-party tools, adding an extra layer of complexity;
  • Requires good programming skills: To effectively use Selenium, testers need to have a strong grasp of programming. This can be a barrier for teams with limited coding expertise or for manual testers looking to transition into automated testing;
  • Handling dynamic web elements is hard: Dealing with dynamic and complex web elements, such as pop-ups, can be tricky in Selenium, often requiring additional coding efforts to handle them accurately;
  • Browser support issues: Though Selenium supports multiple browsers, sometimes tests may behave differently on different browsers, necessitating additional efforts to ensure cross-browser compatibility;
  • Lack of support for image testing: Selenium does not natively support image-based testing. This means it cannot validate visual aspects like font, color, or layout directly;
  • No built-in object repository: Unlike some other testing tools, Selenium does not have a built-in object repository, which can make managing and maintaining web elements more challenging, especially for large projects;
  • Short mobile testing possibilities: While Selenium can be used for mobile testing through tools like Appium, it is not inherently designed for this purpose, and thus, might not offer the same level of efficiency as specialized mobile testing tools.

Each of these disadvantages underscores the importance of understanding project requirements and team capabilities when choosing Selenium as your automation tool.

WEB DIVER VS Selenium RemoteControl:


WEBDRIVER
                 REMOTE CONTROL
1.Webdriver is very faster because of its simpler architecture
Rc is very slow  because of its complicated  architecture
2.Webdriver directly talks to the browser
Rc needs the help of Rc server,inorder to talks to the browser.
3.Webdriver API is more concise
Rc  Apis  are duplicate ones and confusing
4.Webdriver supports html unit browser
Rc doesn’t supports html unit browser
5.Webdriver supports mobile application testing like android, iphone
Rc doesn’t support mobile application testing
6.Webdriver supports multiple programming languages like java, ruby,  perl, php, python, javascript, c#
Rc also supports multiple programming languages.
7.Webdriver support multiple browser like firefox, ie, chrome, safari, opera,edge, ghost(HtmlUnit browser).
  
It doesn’t support ghost/edge browser. And remaining other browsers will support
8.Webdriver supports multiple operating sytem like windows,linux,Mac
Rc supports multiple operating system.


9.Webdriver supports multiple built-in frameworks like Junit,TestNg,Nunit,test unit frameworks
RC also supports built-in framework






LIMITATIONS OF WEBDRIVER:

  1. Webdriver has no built in commands that automatically generates a test result file.
  2.  Webdriver report is very bad because it will be in html file.
List some scenarios which we cannot automate using Selenium WebDriver?
  1.  Bitmap comparison Is not possible using Selenium WebDriver.
  2.  Automating Captcha is not possible using Selenium WebDriver.
  3.  We can not read bar code using Selenium WebDriver

ARCHITECTURE:


There are four components of Selenium Architecture:

  1. Selenium Client Library
  2. JSON Wire Protocol over HTTP
  3. Browser Drivers
  4. Browsers
Selenium Client Libraries/Language Bindings:
Selenium supports multiple libraries such as Java, Ruby, Python, etc., Selenium Developers have developed language bindings to allow Selenium to support multiple languages. Check out Selenium Libraries in the official site.
JSON WIRE PROTOCOL Over HTTP Client:
JSON stands for JavaScript Object Notation. It is used to transfer data between a server and a client on the web. JSON Wire Protocol is a REST API that transfers the information between HTTP server. Each BrowserDriver (such as FirefoxDriver, ChromeDriver etc.,)  has its own HTTP server.
Browser Drivers:
Each browser contains separate browser driver. Browser drivers communicate with respective browser without revealing the internal logic of browser’s functionality. When a browser driver is  received any command then that command will be executed on the respective browser and the response will go back in the form of HTTP response..
Browsers:
Selenium supports multipe browsers such as Firefox, Chrome, IE, Safari etc.,

Let’s see how Selenium WebDriver works internally,
In real time, you write a code in your UI (say Eclipse IDE) using any one of the supported Selenium client libraries (say Java).
Example:
WebDriver driver=new ChromeDriver();
driver.get("https://google.com");
Once you are ready with your script, you will click on Run to execute the program. Based on the above statements, Firefox browser will be launched and it will navigates to google website.
Here we see what will happen internally after you click on Run till the launch of chrome browser. 
Once you click on Run, every statement in your script will be converted as a URL with the help of JSON Wire Protocol over HTTP. The URL’s will be passed to the Browser Drivers. (In the above code, we took FirefoxDriver). Here in our case the client library (java) will convert the statements of the script to JSON format and communicates with the FirefoxDriver. URL looks as shown below.
{url:{"localhost:8080 http://google.com"}
Every Browser Driver uses a HTTP server to receive HTTP requests.  Once the URL reaches the Browser Driver, then the Browser Driver will pass that request to the real browser over HTTP. Then the commands in your selenium script will be executed on the browser.

If the request is POST request then there will be an action on browser.
If the request is a GET request then the corresponding response will be generated at the browser end and it will be sent over HTTP to the browser driver and the Browser Driver over JSON Wire Protocol and sends it to the UI (Eclipse IDE).
This is all about Selenium WebDriver Architecture
================================================


What are the new features of Selenium 4?


1.WebDriver became W3C (World Wide Web Consortium) Standardization:

Selenium WebDriver is now W3C Standardized, and this WebDriver provides a friendly and flexible API for browser automation

• W3C standard encourages compatibility across various software implementations of WebDriver and API.

• Most of the W3C standards revolve around the standardization of web technologies, making the framework more stable and reducing complexities across browsers

2) Selenium Grid enhanced with updates:

The earlier versions of Selenium Grid were complex as it was based on Hub and Node(s) architecture. The Hub and Node(s) need to be separately started when performing automation tests.

• In Selenium 4, Hub and Node (s) are packed in a single jar file, which means once the server starts, it acts as both Hub and Node.

• The Grid also supports IPV6 addresses, allowing its users to communicate with the Grid using the HTTPS protocol with support for TLS connections.

• Selenium Grid has a more scalable and traceable infrastructure that supports four processes: Router, Session Map, Distributor, and Node.

• The new Selenium Grid comes with Docker support, allowing testers and developers to spin up containers rather than setting up heavy virtual machines.

The above feature gives users the flexibility of deploying Selenium Grid on Kubernetes. Selenium Grid 4 can be beneficial and can result in the DevOps process as it supports tools like AWS, Azure, and more.

3) Improvement in Selenium 4 IDE Selenium IDE is a record and playback tool that was available as an add-on for Firefox in the earlier Selenium versions but got deprecated as the latest Firefox versions were standardized under the Web Extension Mechanism.

• Selenium 4 version has it as an add-on for major web browsers such as Firefox, Chrome, MS Edge, etc.

• The latest update has a user interface to deliver an intuitive user experience, and it also comes with a SIDE tool, i.e., Selenium IDE runner, that allows QAs to run projects on a node.js platform.

• This feature enables QA teams to run cross-browser tests on local or Cloud Selenium Grid. It has an improved control flow mechanism that allows testers to write better “while” and “if” conditions.

• Another feature includes the code for test cases recorded using updated Selenium IDE can be exported to the desired programming language like Java, C#, Python, .NET, and JavaScript, thus giving more flexibility to testers.

4)Relative Locators for automation scripts:

Relative Locators, also known as Friendly Locators, were introduced in Selenium 4 to make it easier to locate elements based on their relationship with other elements.

The primary methods in the RelativeLocator class include 𝐧𝐞𝐚𝐫(), 𝐚𝐛𝐨𝐯𝐞(), 𝐛𝐞𝐥𝐨𝐰(), 𝐭𝐨𝐑𝐢𝐠𝐡𝐭𝐎𝐟(), 𝐚𝐧𝐝 𝐭𝐨𝐋𝐞𝐟𝐭𝐎𝐟().

𝐓𝐡𝐞𝐫𝐞 𝐚𝐫𝐞 5 𝐦𝐚𝐢𝐧 𝐫𝐞𝐥𝐚𝐭𝐢𝐯𝐞 𝐥𝐨𝐜𝐚𝐭𝐨𝐫𝐬 𝐢𝐧 𝐒𝐞𝐥𝐞𝐧𝐢𝐮𝐦, 𝐚𝐧𝐝 𝐭𝐡𝐞𝐲 𝐚𝐫𝐞:

1. 𝐧𝐞𝐚𝐫:
– Finds an element that is located near another element.
– Example:
driver.findElement(RelativeLocator.with(By.tagName("input")).near(loginBtn));

2. 𝐚𝐛𝐨𝐯𝐞:
– Finds an element that is located above another element.
– Example:
driver.findElement(RelativeLocator.with(By.tagName("input")).above(loginBtn));

3. 𝐛𝐞𝐥𝐨𝐰:
– Finds an element that is located below another element.
– Example: driver.findElement(RelativeLocator.with(By.tagName("input")).below(loginBtn));

4. 𝐭𝐨𝐋𝐞𝐟𝐭𝐎𝐟:
– Finds an element that is located to the left of another element.
– Example: driver.findElement(RelativeLocator.with(By.tagName("input")).toLeftOf(loginBtn));

5. 𝐭𝐨𝐑𝐢𝐠𝐡𝐭𝐎𝐟:
– Finds an element that is located to the right of another element.
– Example: driver.findElement(RelativeLocator.with(By.tagName("input")).toRightOf(loginBtn));

𝐔𝐬𝐞 𝐂𝐚𝐬𝐞 :
We want to locate the ‘Password’ text box field that is above the ‘LOGIN’ button and then write some text inside the ‘Password’ field (see figure below).

public class RelativeLocators {

public static WebDriver driver;
public static void main(String[] args) {

driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(15));
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(25));
driver.manage().window().maximize();
driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login");

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));

WebElement username = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@placeholder='Username']")));
username.sendKeys("Admin");
WebElement loginBtn = driver.findElement(By.xpath("//button[normalize-space()='Login']"));
//By using Relative Locator -above()
WebElement password = driver.findElement(RelativeLocator.with(By.tagName("input")).above(loginBtn));
password.sendKeys("admin123");
loginBtn.click();
}
}




5)Chrome Debugging Protocol (CDP):

 One of the most anticipated features for Selenium 4 is the new APIs in the Chrome DevTools Protocol. As we know the Chrome DevTools is a set of tools built directly in chrome-based browsers like Chrome Opera and Microsoft Edge to help the developers debug and investigate the websites. 

Selenium 4 enables developers to perform all the Chrome DevTools functions by adding native support for the Chrome DevTools API. These new API’s unable to perform the following functions:

  • Capture and monitor the network traffic and performance.
  • Mock geolocations for location-aware testing, localization, and internationalization.
  • Change the device mode and exercise the responsiveness of the application.

Apart from this, the Selenium 4 introduced the new Chromium Driver Class which includes the two methods to access the Chrome DevTools: getDevTools() and executeCdpCommand().

Hence Selenium 4 enables to programmatically access the chrome dev tools, unlike the other versions of selenium, Selenium 4 enables to access the Chrome dev tools to invoke its various functionalities and reap its benefits like simulating the network speed, mocking the geo-locations, accessing the console logs, capturing the performance metrics, bypassing the pops for authentication through CDP API’s, etc.

• QA teams can also leverage the APIs offered by Chrome DevTools to simulate poor network conditions and perform geolocation testing.

• This feature also allows testers to check how the product performs under varying network conditions such as 3G, 4G, 5G, etc.

6. Multiple Windows and Tabs Management

 While testing the software testers have to switch across multiple windows, tabs, or applications in a single test flow.

• In the earlier versions on Selenium, it was not easy to manage multiple windows or tabs as it required testers to create a new Web Driver object. Post which used to switch to the new window (or tab) using the unique WindowHandle to perform subsequent actions in that window (or tab).

This can be done with the help of these two methods newWindow() and navigate to() method. 

The WindowType. Window and WindowType.Tab will help you to select a new window or a new tab without giving a new driver reference.

7. Telemetry and GraphQL:


A framework called Open Telemetry has been added to Selenium Grid. This feature brings more observability into Grid as it allows testers to see what’s happening inside the Grid, especially when something goes wrong while running the test.

Also, the Grid now has a new front-end console, which is powered by a GraphQL endpoint. It allows testers to run a GraphQL query against the Selenium grid, either distributed or on the local machine. This feature helps testers extract useful metrics and information from the Grid to fulfill the monitoring needs.

8. Improved Documentation:


With the earlier versions of Selenium, users use to face a lot of difficulties with the documentation part as there were some lackings in the documentation capabilities of Selenium.

This has significantly improved in the latest versions of Selenium. Selenium 4.0 provides better documentation capabilities.

• Its documentation part has been completely revamped with a neat UI that allows users to easily navigate to the desired section of the page and covers all information about tools and APIs that comes under the Selenium umbrella.

What is deprecated and changed in Selenium 4?


1. Deprecation of Desired Capabilities

Desired capabilities were primarily used in the test script for defining the test environment (browser name, version, operating system) for executing tests on Selenium Grid. This has now been replaced with Options. It means testers now have to create an Options object, set test requirements, and pass the object to the Driver constructor. Below listed are the Options objects that have been included in Selenium 4.0

Firefox – FirefoxOptions

Chrome – ChromeOptions

Internet Explorer (IE) – InternetExplorerOptions

Microsoft Edge – EdgeOptions

Safari – SafariOptions

2. Changes in the Action Class

Action class is used to simulate input actions from a keyboard or mouse on specific web elements. For e.g, Left-click, Right-click, Double-click, etc.

Following changes have been made to Action Class in Selenium 4.0

• click(WebElement) has replaced moveToElement(onElement).click() {}

• clickAndHold(WebElement) has replaced moveToElement(onElement).clickAndHold()

• contextClick(WebElement) has replaced moveToElement(onElement).contextClick()

• doubleClick(WebElement) has replaced moveToElement(element).doubleClick()

• release() which was ealier a part of org.openqa.selenium.interactions.ButtonReleaseAction class has now been moved to Action class as per new update of Selenium 4.0

3. Deprecation of FindsBy:

In the older version of Selenium, FindsBy interfaces were a part of org.openqa.selenium.internal package. It contains findElement(By) and findElements(By) methods, implemented by the RemoteWebDriver class. However, these have now been deprecated in Selenium 4.0.

4. Changes in FluentWait:

In Selenium 4.0, the methods withTimeout() and pollingEvery() that are a part of the FluentWait class have been modified. The pollingEvery() method only accepts one parameter – Duration that can be in Seconds, MilliSeconds, NanoSeconds, Hours, Days, etc. Similarly, the withTimeOut() method also accepts only one parameter – Duration.


INSTALLATION OF WEBDRIVER AND CONFIGURING ECLIPSE:

1)Install java on your computer(Windows 32bit or windows 64bit)

2)Download the eclipse and unzip the folder.

3)Downloading webdriver jar.

4) Open Selenium.dev website 

5)click on download tab 

6) go to selenium client and webdriver language bindings section

7)Click on java download link -->selenium-java.zip will be downloaded

8)Place the Zip file either in C or D drive in one folder

9)unzip or extract the file--> we will get selenium 4.0.

10)Configure the webdriver jars with eclipse

11)Open the eclipse 

12)Create a Java Project

13) right click on project 

14)select build path

15)click on Library tab

16)Click on Add external Jars button

17)goto the webdriver jars location in c or d drive

18)select all the jars & add all the jars to project

19)click on Finish

WEBDRIVER 3 Implementation:


WEBDRIVER4 IMPLEMENTATION: 
    
In Selenium 4, a change was made to the drivers. ChromeDriver and EdgeDriver extend ChromiumDriver while RemoteWebDriver is the parent to ChromiumDriver. Here are some screenshots showing the relationship between each driver:




Webdriver is an interface. It is implemented by many classes.
package name:org.openqa.selenium

Interface Classname Browser
    WebDriver FirefoxDriver Firefox
ChromeDriver Google chrome
SafariDriver Safari
OperaDriver Opera
InternetExplorerDriver IE
HtmlUnitDriver htmlUnit/ghost(headless browser)
EventFiringWebDriver   to execute the javascript code/listener
RemoteWebDriver to run on remote browser/operaing system
EdgeDriver microsoft latest browser

Can i create like this?
WebDriver driver=new WebDriver();
Ans:
Why we cannot create an object for WebDriver?
Ans:interface contains all abstract methods, those methods are not implemented(no definition), without definition we cannot use them.
    When we first start with selenium automation our very first line of code comes as :-
    Where you have used runtimepolymorphysm or method overriding concept in your automation?
    interface variable=new implementingclass();
    WebDriver driver = new FireFoxDriver();

    Have we ever thought what is the meaning of this code of line ...WebDriver driver ?
    Simple answer to this is :

In the statement WebDriver driver = new ChromeDriver();, the purpose of driver is to serve as a reference variable that holds an instance of the ChromeDriver class. Here's a breakdown of what each part of the statement does:

  1. WebDriver: This is an interface in the Selenium WebDriver library. It defines a set of methods for interacting with web browsers. The WebDriver interface is implemented by various driver classes, each corresponding to a different browser (e.g., ChromeDriver for Chrome, FirefoxDriver for Firefox).

  2. driver: This is a reference variable of type WebDriver. By declaring driver as WebDriver, you ensure that it can hold any object that implements the WebDriver interface, providing flexibility to switch between different browsers by simply changing the instantiation part.

  3. new ChromeDriver(): This is the instantiation of the ChromeDriver class, which is an implementation of the WebDriver interface specific to the Chrome browser. When you create a new ChromeDriver instance, it launches a new Chrome browser window that you can control through the driver variable.

PPurpose of driver

  • Controlling the Browser: The driver variable is used to control the browser. You can use it to navigate to web pages, find HTML elements, interact with web elements (e.g., click, type text), execute JavaScript, and retrieve information about the web page
  • Flexibility: By using the WebDriver interface type for the driver variable, you can easily switch to a different browser by changing only the instantiation part (e.g., new FirefoxDriver() instead of new ChromeDriver()).

  • Browser Control: The driver variable provides methods to control the browser, making it possible to automate web interactions for testing purposes.

  • Resource Management: It's important to properly manage the browser instance by closing it after the tests are done using methods like driver.quit() to free up resources.


==================================================
    Webdriver+seleniumRC=seleniumWebdriver/selenium2.0
    What is the superinterface for WebDriver?
    Ans):SearchContext

    public interface WebDriver extends SearchContext{}

============================================================================

Selenium 4 Architecture



  • Unlike Selenium 3, Selenium 4 has direct communication between the client and server. The client still has 2 parts (Selenium Client & WebDriver Language Bindings) while Browser Drivers are the server.

    • Selenium Client sends out a request to perform a command.
    • The WebDriver Language Bindings is a code library designed to drive actions.
    • Browser Drivers receive the request and then return a response after an automation Test Script executes on the Web Browser:

The Selenium Client & WebDriver Language Bindings is a part of the architecture where each language has their own unique bindings. Bindings mean that the same commands written for one language are also written for another language. For example, Java has a set of commands that have also been written for other languages (C#, Python JavaScript, and Ruby).

When it comes to the Browser Drivers and Web Browsers, WebDriver drives each browser using the browser’s built-in automation support. A Browser Driver such as ChromeDriver controls the Chrome browser.

Key Differences between Selenium 4 and Selenium 3

As you have read about Selenium and its architectures in this section, you will learn about the critical differences between Selenium 4 and Selenium 3.

FeaturesSelenium 4Selenium 3
WebDriver ManagerSelenium 4 integrates Selenium Manager as a built-in feature, offering automated management of browser drivers. WebDriver Manager downloads driver binaries, handles configuration, and ensures compatibility.Selenium 3 lacked a built-in WebDriverManager, requiring developers to download browser driver binaries and manually perform manual configuration.
DevTools APISelenium 4 uses the W3C standard protocol for DevTools API.Selenium 3 uses the JSON wire protocol for DevTools API.
PerformanceSelenium 4 shows improved performance and faster test execution.Selenium 3 may experience potential performance issues.
Selenium GridSelenium 4 offers an optimized Selenium Grid with enhanced GUI and Docker support.Selenium 3 allows parallel testing through Selenium Grid but lacks support for Docker.
ChromeDriverIn Selenium 4, the Chrome Driver class extends the Chromium driver class.In Selenium 3, the Chrome Driver class extends the Remote WebDriver class.
New FeaturesSelenium 4 introduces Relative Locators, Grid enhancements, and Chrome DevTools.Selenium 3 has a limited feature set.
Overall ImprovementsSelenium 4 brings significant architectural improvements, using DevTools API, introduces new features, enhances performance, improves stability, benefits from active community support, and provides a more advanced and feature-rich platform than Selenium 3.Selenium 3 needs more architectural advancements, DevTools API integration, and new features found in Selenium 4, making it less advanced and feature-rich.

============================================================






Top 11 Challenges in Automation Testing Using Selenium

1. Pop-Up Windows

The pop-ups that we receive on the screen during automation testing are part of the operating system, but Selenium often fails to record these pop-ups in web apps, which makes it hard for developers to automate this process. Moreover, windows-based alerts are beyond Selenium's capabilities as they are part of the operating system, not the browser. Although, the Selenium WebDriver can operate multiple windows, so you can handle web-based alerts generally with the help of the switchTo technique to control the pop-up while the browser runs in the background.
Another method to handle pop-up alert is to apply a  getAlert function . Before running your Selenium script, import a package to it to generate a WebDriver script, which has the following commands – getText () ,  void dismiss () , and  void accept () . The last two commands will work as the Cancel or OK command to control pop-ups.

2. Identifying Dynamic Elements

Many web apps or websites often have web elements that are dynamic in nature, which are not visible when you visit the site for the first time. This means that the web pages are user-specific and display different data for different users based on their requirements; new data appears on the web page after a certain period of time or when a user clicks something on the page. For example, if the ID of an element is changing on every page load, then it’s not easy to handle this situation in a normal way.
The dynamic elements can be handled with dynamic XPath or dynamic CSS selectors. You can also use functions, such as contains, ends with, starts-with, etc. to handle dynamic objects.

3. Timeout or Sync Issue

Whether you call it a timeout or sync issue, it is one of the most common challenges in Selenium test automation. If you don’t handle this issue carefully, most of your testing script might fail. It is even proved many times that around 80% of scripts fail due to improper sync while executing automation testing. Though this problem can be avoided using smart waits like Implicit waits, Fluent waits, and explicit waits that are available within Selenium. You can write your own custom method to handle the sync issues.
For example, if you use explicit waits, you can make the Selenium WebDriver freeze the execution and wait until certain conditions are met. This is just one example; you can accomplish the explicit wait in multiple ways.

4. Cross Browser Testing

Selenium is widely used for automated cross-browser testing of web apps because it supports multiple languages and operating systems. While automating cross-browser testing with Selenium, many developers found that some elements of the web app work in one browser and not in others. It is necessary to make sure that your web app works well and appropriately in every browser; otherwise, you can lose out on a high traffic rate.
To avoid this issue, you should run the script again and again on different browsers and analyze the results. If it fails on some browsers, then you will have to change the locator strategy. 

5. Testing of Mobile Apps

Selenium allows us to test web apps on any operating system and browser on desktops, but when it comes to mobile app testing, it cannot work with operating systems like Android and iOS. For instance, the version of Twitter that you run in the Safari browser on your Mac system can be tested with Selenium, but it cannot be tested in a mobile Safari browser on your iPhone or Android phone.
There is an alternative solution to this. Appium, an open-source automation testing framework that uses WebDriver protocol to drive native, hybrid, and iOS and Android mobile apps can be used.

6. Page Loading

As mentioned earlier, some of the web pages in a web app are user-specific and load different elements depending on the user. Some features even appear based on the user’s previous activity. For example, if you have a drop-down menu for Italian food, then food items related to that category will appear in the food dropdown. During the runtime, the Selenium script might not be able to identify the element. Therefore, to overcome this issue, you can use explicit waits to provide elements enough time to load and to discover the element.

7. Scalability

Because it is an open-source platform, Selenium allows you to test on almost every browser and operating system, but there are still limitations on the number of tests you can run at once with Selenium and how quickly it can execute them based on the number of hub/node configurations you have.
The primary goal of automation testing is to execute as many tests as possible for an extensive test coverage in minimum time. At the initial stage, your web app might have short test builds, but as it grows, the test will expand with every sprint. With Selenium WebDriver, you can sequentially perform automation testing, but it might not be as effective as you want it to be. So, Selenium is not the most scalable approach for automation testing.
Selenium Grid can empower your testing process by running tests in parallel. Though there is one drawback with it; you cannot test your web app across multiple combinations of OS and browsers. It only allows you to run tests on a specific browser and OS at one time. However, using a cloud-based tool, you can test your web app across multiple browsers and OS at once. It will reduce the time to run automated tests while increasing the configurations you can test on.

8. Multi-Tab Testing

Selenium provides you the ability to test your web app in multiple tabs, but this functionality can turn out to be an obstacle if you don’t know the exact commands. For example, if you want to perform a specific action on a new tab without closing the current tab, you won’t be able to control both the tabs and go back to the parent tab.
To overcome this challenge, try to store the current window handle in one variable, and then go to the new window and store it in the second variable. After that, use the switchTo method to switch between both the windows as per your needs.

9. Limited Reporting

No doubt Selenium can enormously improve automated testing capabilities, but due to some limitations, it cannot generate good testing reports. Every tester needs a good testing report after executing test cases, as it helps analyze the entire test scenario and find bugs in it. 

10. Limited Captcha Handling

With Selenium, you cannot handle captcha completely. Though there are some third-party tools that can help in automating captcha, achieving one hundred percent results is still not possible.

11. Supports Only Web-Based Applications

Selenium only supports automated testing for web-based applications, which means you cannot test windows-based apps with it.
It is also necessary to note that Selenium cannot automate everything. There are still some tasks that you will have to execute manually. Therefore, it’s vital to have knowledge of programming languages for using Selenium.
==========================================================



   HOW TO RUN ON DIFFERENT BROWSERS And THIER CONFIGURATIONS -Selenium 4.8.X version onwards no need to use any browser.exe file we can directly launch the browsers
  
-----------------------------------------------------------------
   1)FireFox Browser:  
WebDriver driver = new FirefoxDriver(); //empty browser will launch
   


=============================================
  2)Chrome browser:
  
    WebDriver driver = new ChromeDriver();
==================================================
   3)IE Browser

   WebDriver driver = new InternetExplorerDriver();
==================================================
  4)EDGE browser


    WebDriver driver = new EdgeDriver();
==================================================


--------------------------------------------------------------------------------------------------------------
Advanced Browser Configurations:

==================================================================
Element Locators:
---------------------------------------------------------------------------------------------------------------------------
Browser Methods:

====================================================================
Navigation Methods:

====================================================================
Handle Cookies:

=========================================================================


Element Action Methods:


-----------------------------------------------------------------------------------------------------------------------
Handle Dropdowns using Select class methods:



==========================================================
Handle Alerts:

-----------------------------------------------------------------------------------------------------------------------
Handle Frames:


=====================================================================
Handle Windows:

---------------------------------------------------------------------------------------------------------------------
CaptureElementHeightAndWidth:
-----------------------------------------------------------------------------------------------------------------------
ScrollDown or Up WebPage:

-------------------------------------------------------------------------------------------------------------------------
ScreenshotsCapture:

----------------------------------------------------------------------------------------------------------------------
UploadFileWith Selenium Sendkeys():

------------------------------------------------------------------------------------------------------------------------
Actions class Methods for handling mouse & keyboard Actions:

=========================================================================


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.