How a headless browser works with Selenium

Yuta Fujii
4 min readFeb 5, 2019

When you might want to test your app by using user interface, you’ll certainly be faced with Selenium WebDriver.

Though lots of articles are published, I still feel I need to sum them up to understand the big picture. For my information, I’ll take them down here.

Keywords

  • Automated Testing
  • Selenium / Selenium WebDriver
  • Chrome driver / Firefox driver
  • Remote WebDriver
  • JSON wire protocol
  • Appium

What is Selenium and Selenium WebDriver

First, Selenium is a framework to test your app automatically.

In a nutshell, Selenium WebDriver is a middleman between a client and a browser. Command to manipulate the browser is scripted by different language depending on users, at the same time browsers may differ such as G Chrome, FF, Safari, etc. As such, Selenium WebDriver comes in to convert commands. In the past Selenium needed a special server(Selenium server) to run the test, but with the born of Selenium WebDriver, the WebDriver directly starts a browser instance and controls it (There is still use case for the standalone server, explained later).

As such, Selenium WebDriver is basically with a driver in accordance with the type of browser to handle that.

Workflow(https://www.ranorex.com/resources/testing-wiki/selenium-testing/)

What is Chrome Driver? Firefox Driver?

Chrome, Firefox, Edge, IE, Safari have their own drivers that really execute commands to the browser.

What is Remote WebDriver?

In Java source, Remote WebDriver is defined as a RemoteWebDriver Class in the package. It’s a parent class to each specific drivers.

ChromeDriver, EdgeDriver are the subclass of RemoteWebDriver(source)

In ruby gem, both Remote and WebDriver are defined as a module.

You can also use RemoteWebDriver as a commander of a test. Rather, we must use it, especially when you want to execute cloud-based tools like Sause Lab, Selenium Grid, Browser Stack. When you use RemoteWebDriver, you need to install selenium standalone server. Remote WebDriver gives you more flexibility.

$ java -jar selenium-server-standalone.jar

And in your source,

# ruby source file
driver = Selenium::WebDriver.for :remote
driver = Selenium::WebDriver.for :remote, url: "http://myserver:4444/wd/hub"
# To launch another browser with the default capabilities, use the :desired_capabilities option:driver = Selenium::WebDriver.for :remote, desired_capabilities: :firefox

What is JSON wire protocol?

Selenium explains JSON wire protocol as a RESTful web service using JSON over HTTP.

Selenium WebDriver gives commands to webdrivers (Chrome driver, Firefox driver, etc) using JSON wire protocol. This makes you be not bound to local machine nor a specific browser, and you can adopt any language as long as Selenium WebDriver can understand.

Selenium is the only choice?

Of course not, but Selenium becomes a defacto standard. If your server-side app is written with JavaScript, Cypress would be the choice since Selenium does not support JavaScript.

Web test or Mobile test?

By the way, what is your app for? Possible is that modern applications focus mainly on mobile use. Even if it’s not a native app but mobile web, you still need to think about the different configuration (e.g. OS is none of Linux, Mac, Windows.).

For automated mobile tests, Appium is developed. You can take advantage of this to run tests for mobile app/web.

“Appium is like Selenium — but for mobile apps and games“. You’ve probably read/heard this several times before, but in fact, Appium is much more than that. Appium is also suitable for mobile web testing when real devices and real browsers are used in testing.

--

--

Yuta Fujii

Web developer, Data analyst, Product Manager. Ex investment banker( structured finance ). Learn or Die.