Selenium WebDriver for Cross-Browser Testing, Part 1 – DZone Web Dev | xxxSelenium WebDriver for Cross-Browser Testing, Part 1 – DZone Web Dev – xxx
菜单

Selenium WebDriver for Cross-Browser Testing, Part 1 – DZone Web Dev

十二月 31, 2018 - MorningStar

Over a million developers have joined DZone.
Selenium WebDriver for Cross-Browser Testing, Part 1 - DZone Web Dev

{{announcement.body}}

{{announcement.title}}

Let’s be friends:

Selenium WebDriver for Cross-Browser Testing, Part 1

DZone’s Guide to

Selenium WebDriver for Cross-Browser Testing, Part 1

In Part 1 of this two-part series, we delve into the theory behind Selenium WebDriver and why it’s great for cross-browser testing.

Jan. 18, 19 · Web Dev Zone ·

Free Resource

Join the DZone community and get the full member experience.

Join For Free

Jumpstart your Angular applications with Indigo.Design, a unified platform for visual design, UX prototyping, code generation, and app development.

Selenium is a popular automation testing framework that is primarily used for the cross-browser testing. It is open source and is ideal for automating testing of web applications across different browsers like Firefox, Chrome, Internet Explorer, Microsoft Edge, etc. Selenium has become a renowned framework and is giving stiff competition to other test frameworks like HP QTP (Quick Test Professional) and AKA HP UFT (Unified Functional Testing). This look at Selenium WebDriver will help you develop the basic understanding of the components of the Selenium suite, Selenium WebDriver architecture, and show you how to run automated tests for cross-browser compatibility.

Components of the Selenium Suite

Below are the core components of the Selenium Test Suite

  • Selenium Integrated Development Environment (IDE).
  • Selenium Remote Control (RC).
  • Selenium WebDriver.
  • Selenium Grid.

Selenium Integrated Development Environment (IDE)

The Selenium IDE is a simple Firefox Plugin and it is used to record and playback scripts. However, the Selenium IDE can only be used to write automation scripts for automating testing of simple use cases. The Selenium IDE does not support conditional statements, exception handling, loops, screenshot captures, etc. For automating complex use cases, a majority of developers and testers prefer to opt for Scripting testing instead of Record and Replay testing. The Selenium test suite consists of Selenium Remote Control (RC) or Selenium WebDriver.

The Selenium IDE is available for different operating systems, namely Windows, Linux, macOS, etc. The Selenium IDE for Firefox can be downloaded from here.

Selenium Remote Control (RC)

For testing complex scenarios, Selenium Remote Control (RC) can be used. It is based on the client-server model which makes it possible to execute tests on the browser that is controlled by the server. There are client libraries in different programming languages which make it easy for developers to write effective test cases in a programming language in which they are comfortable and have expertise. Since version 2.25.0, RC has supported Java, C#, Python, Perl, Ruby, etc.

Selenium Server is the core component of the Selenium RC. Some of the core features/responsibilities of the Selenium RC are listed below: 

  • Contains the core Selenium Framework and it is mainly responsible for injecting the same in the browser [Chrome, Firefox, Internet Explorer, Microsoft Edge, etc.].
  • The client program sends commands to the RC which are then interpreted by the server and then sent to the browser.
  • After execution, the results are sent back to the client.
  • The client and server communicate via the normal mechanism of HTTP GETs and POSTs. Which is well versed with client-server concepts can manage to write test code with Selenium and WebDriver with ease.

As mentioned earlier, the Selenium RC supports different browsers, unlike the Selenium IDE which is only available for Mozilla Firefox. The downside of Selenium RC is that it does not support record ad playback functionalities, which can be vital in the automation of test cases where tasks are repetitive, especially for regression testing. Before executing the tests using Selenium RC, an instance of the Selenium RC Server should be manually invoked and that instance should be running throughout your entire test cycle.

Selenium WebDriver

The Selenium IDE is GUI-based, whereas Selenium RC is a standalone Java program that will allow you to execute HTML test suites. The Selenium WebDriver framework is more widely used when compared to Selenium IDE and Selenium RC. Unlike Selenium RC which is based on the client-server model, the Selenium WebDriver framework is implemented through a browser-specific driver; i.e., each browser will have its corresponding WebDriver application on which the automation testing would be performed.

Thus, Selenium WebDriver directly communicates with the browser due to which it does not require any separate components like the Selenium Server. It supports various languages, such as C#, Ruby, Java, Python, and Perl. Before you go ahead in this Selenium WebDriver tutorial, make sure to download Selenium WebDriver for the browser on which your cross-browser testing is being performed. You can download Selenium WebDriver from the links below:

Firefoxhttps://github.com/mozilla/geckodriver/releases
Chromehttp://chromedriver.chromium.org/downloads
Internet Explorerhttps://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
Microsoft Edgehttps://blogs.windows.com/msedgedev/2015/07/23/bringing-automated-testing-to-microsoft-edge-through-webdriver/

Selenium Grid

Serial testing is fine until you have to test code that is confined to a few browsers, operating systems, or devices. However, the testing methodology would falter once testing has to be formed in an environment that has multiple combinations. This is where parallel testing can be extremely useful since it can accelerate the whole testing process. Parallel testing can allow you to perform a similar test case across different test configurations, simultaneously. You could also simultaneously execute different test cases in the same browser.

Back to the basics. Selenium Grid is mainly used for parallel testing since it helps in running tests on different machines against different browsers and operating systems, simultaneously. It does the job in conjunction with Selenium RC. An example that showcases the usage of Selenium Grid is below:

from selenium  import webdriver from selenium.webdriver.common.keys  import Keys  desired_cap = { 'platform' : 'win10', 'browserName' : 'chrome', 'version' : "67.0", }  url = "https://username:acsessToken@{LMABDA GRID URL}/wd/hub"  driver = webdriver.Remote( desired_capabilities=desired_cap, command_executor= url )  driver.implicitly_wait(1)  driver.get("http://www.google.com/")  driver.quit()

Selenium WebDriver Architecture

As a part of this Selenium WebDriver tutorial, it is imperative to have a look at the major blocks that comprise the Selenium WebDriver architecture:

  • Selenium Client Libraries
  • JSON Wire Protocol
  • Browser Drivers
  • Browsers

Let’s have a look at each component in more detail.

Selenium Client Libraries

As mentioned earlier, developers can use Selenium to write test code in different languages like C#, Java, Python, Perl, etc. The multi-language support is possible due to Selenium Client Libraries or Selenium Language Bindings. For example, if you are writing code in Python, you would require Python client libraries. Selenium Client Drivers for different programming languages can be downloaded from here.

JSON Wire Protocol

JSON (JavaScript Object Notation) Wire Protocol facilitates the transfer of data between the client and server. It is a REST (Representational State Transfer)-based API. Each browser will have its own browser driver.

Browser Drivers

Browser Driver is mainly used for communicating with the browsers. Since the internal logic of the browser and its functionality is not revealed, Browser Driver ensures the necessary layer of ‘encapsulation’ in order to keep execution level details more abstract. Each browser has its corresponding Browser Driver. Please refer to the section titled ‘Selenium WebDriver’ in this post, which contains information about the location from where you can download the Browser Drivers.

Browsers

Since Browser Drivers are available for popular browsers like Chrome, Firefox, Internet Explorer, Safari, Microsoft Edge, etc., you can use either of them for performing cross-browser testing. It should be noted that you cannot perform cross-browser testing of a website on a browser whose Browser Driver is not publicly available.

Selenium WebDriver for Cross-Browser Testing, Part 1 - DZone Web Dev

That’s all for Part 1! Tune back in on Monday when we’ll look at the Python code you need to implement Selenium across multiple browers.

Take a look at an Indigo.Design sample application to learn more about how apps are created with design to code software.

Topics:
web dev ,selenium tutorial ,cross-browser testing ,web application testing

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.linkDescription }}

{{ parent.urlSource.name }}

· {{ parent.articleDate | date:’MMM. dd, yyyy’ }} {{ parent.linkDate | date:’MMM. dd, yyyy’ }}


Notice: Undefined variable: canUpdate in /var/www/html/wordpress/wp-content/plugins/wp-autopost-pro/wp-autopost-function.php on line 51