Skip to content

Instantly share code, notes, and snippets.

@dcypherthis
Created March 22, 2016 17:30
Show Gist options
  • Save dcypherthis/89f1202abac977493806 to your computer and use it in GitHub Desktop.
Save dcypherthis/89f1202abac977493806 to your computer and use it in GitHub Desktop.

What is Selenium?

Selenium, in the biological sense, is a mineral essential to the metabolic process of protein synthesis. Without it, individuals experience severe damage to the heart muscle and interference with brain chemistry that is essential to managing stress. In high doses, however, selenium has toxic qualities that damage the very things that need it to function. Like many other vital minerals and chemicals in our bodies, balance is key to health and prolonged wellness.

Selenium WebDriver is a tool for automating web and mobile application testing. It automates web browsers to mimic human interaction with user interfaces. It is built around an object-oriented API and set of native drivers for modern web browsers and mobile application frameworks. While based in java, API wrappers are maintained across dozens of languages and frameworks ensuring the right tool is available to everyone. With Selenium WebDriver, we create test cases that navigate through our web pages and applications, make assurances of intended behavior, and report errors when something fails.

Selenium WebDriver draws many parallels to its namesake; it is essential for engineering teams to survive. It is needed to build strong, reliable software. Without it, maintaining the health of our applications becomes unmanageable and a source of constant strain. Automation helps us catch issues faster & more efficiently than a single tester, so we can fix problems before they are passed on to customers & other stakeholders. It is a safeguard tool we can build into the software delivery process that gives us confidence our application is behaving as intended and alerts us when it is not.

Selenium can be a source of pain in excess. Metabolically, an overdose of Selenium can slowly shut down your heart and impede brain function, culminating in death. This draws another important parallel; not everything is cut out for automated testing. Understanding what not to test with automation is more important in some cases than the automation code itself, as you may end up with a lot of brittle or cumbersome tests that yield little value for the software delivery process. Automation is useless if you don't understand what you are testing and the value that a passing or failing test has. Too many brittle, cumbersome, or pointless tests will slowly consume resources and ultimately hurt the overall performance of the software team. We seek to find a balance between test coverage and value that informs developments teams and stakeholders on how our products are behaving.

How does selenium work?

We can explain how selenium works by thinking about taking a trip in a taxi. The taxi is driving around the city until someone hails it. The passenger gets in the taxi and tells the taxi driver where to go. The taxi driver executes the passenger's requests by sending his own requests to the car (by physically operating it). The car executes the driver's requests and moves to the intended destination.

In test automation, the test engineer writes the tests (plans where he wants to go) and then starts the executing the tests (hails the taxi). Once a connection is established to the selenium server (the passenger get gets in the taxi), the automation script (the passenger) tells the browser driver (the taxi driver) what to do. The browser driver then executes those instructions in the browser (the vehicle). The browser actually performs the actions (as the vehicle actually moves the passenger and driver to the destination). Once the test is complete (the fair is satisfied and the passenger has left the taxi), the browser and browser driver are ready to accept another test (the taxi can take on a new passenger).

Here is a more in-depth look at how this process works:

  1. Launch the Selenium server.

  2. The Selenium server loads all browser driver configurations (Chromedriver, Firefox driver, Safari driver, etc) and detects which browsers and versions are available.

  3. Start the client driver/ test runner (WebDriverIO in our case).

  4. Run the test suite from the client driver (WebDriverIO).

  5. The client driver searches for and connects to the Selenium server

  6. The client driver translates automation scripts into JSON wire protocol requests (Selenium or "Selenese" commands) to the Selenium server

  7. The Selenium server creates a unique session for each request (test case). Inside each session, it launches the browsers specified in the global test configuration or case-specific setup commands.

  8. Selenium commands (JSON) sent to the server are passed to each browser driver (Firefox driver, Chromedriver, safari driver, etc).

  9. The browser driver converts each JSON command into an HTTP request.

  10. The HTTP requests are sent over a proxy HTTP server to the actual web browser applications, and make requests to native API's. These requests invoke actions.

  11. When steps are executed in the browser, the execution status codes are sent back to the proxy HTTP server.

  12. The proxy HTTP server passes the status back to the browser driver (Chromedriver).

  13. the browser driver passes the status back to the Selenium server via JSON, which collects responses from other concurrent browsers executing the same requests.

  14. The Selenium server communicates results with the client driver (WebDriver IO) via the JSON Wire Protocol.

  15. The client driver (WebDriverIO) interprets the JSON response inside the test runner.

  16. The client driver(WebDriverIO) executes the next test case.

As we add more complexity with multiple browser nodes and job execution queues, this process becomes much more involved, but ultimately, this is what is a happening under the hood for each browser instance of each test.

@rtablada
Copy link

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment