© 2019 Matt Thomas

Automated Tests

with Selenium

...from a developers perspective

About Me:

Matt Thomas - Full Stack Developer

~2 years experience writing automated tests with Selenium


Testing the functionality of the web app to verify it does what it was meant to do.

We would like to test the application as the User would interact with it.

We will not be covering other kinds of tests. I.E.: Unit Testing

The Solution:

Selenium - Browser Automation Server

Often referred to as "Selenium Web Driver"
or "Standalone Selenium Server"

APIs for many languages
(PHP, Java, JavaScript (including Node.js), Ruby, Python C#)

Integrates with all modern browsers

Grid can be used to run many tests on numerous "servers" in parallel using different configurations

Getting it up & running...

It's Java.... easy right?!?!?

Documentation can be found on the Selenium website

  • Install Java JRE
  • Download Selenium
  • Download Web Drivers (Chrome & Firefox or IE???)
  • Start Selenium server

Install Java

Oracle JRE 1.8 or greater or Open JRE 1.8 or greater

Download Selenium


The server is a Java Jar file, so it is cross platform by nature.

Move to an easily accessible location i.e.: ~/bin

Download Web Drivers

(Chrome & Firefox or IE???)

Most Web Drivers are third party and are developed by the browser manufacturers.

They can be accessed via the Selenium Download page

Download to the same location as the Selenium server Jar file.

Getting Internet Explorer to work with Selenium

...can make you want to...

Requires Admin permissions to the computer to allow:
Registry key creation/edit using regedit
Set Internet Explorer security settings
Disable Enhanced Protected Mode

Must use Native Events
Have browser focus
Set zoom level set to 100%
IE WebDriver Documentation

Start Selenium server

java -Dwebdriver.chrome.driver=./chromedriver -jar selenium-server-standalone-3.4.0.jar

Using the Selenium Web Driver API

Various frameworks have abstracted the use in many languages

API support varies for each testing framework.

Locating elements

The API supports locating elements in various ways including:

  • By ID
  • By Class Name
  • By Tag Name
  • By Name
  • By Link Text
  • By Partial Link Text
  • By CSS
  • By XPath
  • By Javascript

Interacting with elements

The API supports interacting with the browser in the following ways:

  • Retrieving text values
  • Filling in Forms inputs
  • Clicking Links and Buttons
  • Moving between Windows, Tabs, Frames
  • Handling Popup Dialogs (in browser)
  • Navigation, including History and Location (URL)
  • Cookies
  • User Agent (Firefox only?)
  • Drag and Drop
  • Via Javascript

Selenium & PHP

using Codeception PHP testing framework

Implements Acceptance, Functional & Unit tests

Integrates with Laravel, Zend (1 & 2), Symfony, Yii (1 & 2)

Built on top of PHPUnit

Codeception Example

                            public function register(AcceptanceTester $I)
                                $I->wantTo('Register a new user ' . $this->email);
                                $I->see("Your Application's Landing Page.");


                                $I->fillField('name', $this->name);
                                $I->fillField('email', $this->email);
                                $I->fillField('password', $this->password);
                                $I->fillField('password_confirmation', $this->password);

                                $I->see($this->name, 'a.dropdown-toggle');

Selenium & Python

using Python API

Python Example

                            from selenium import webdriver

                            driver = webdriver.Chrome()



                            driver.find_element_by_id('task-name').send_keys('Mocha task for STL Full Stack Meetup')


                            driver.find_element_by_link_text('Matt Thomas').click()


Selenium & JavaScript

using Mocha testing framework

Implements Acceptance, Functional & Unit tests

Integrates with Node.js, React, Angular

Mocha Example

                            test = require('selenium-webdriver/testing'),
                            webdriver = require('selenium-webdriver');

                            test.describe('Create a task', function () {
                                test.it('should work', function () {
                                    var driver = new webdriver.Builder().

                                    driver.findElement(webdriver.By.className("btn btn-primary")).click();

                                    driver.findElement(webdriver.By.id('task-name')).sendKeys('Mocha task for STL Full Stack Meetup');
                                    driver.findElement(webdriver.By.className("btn btn-default")).click();

                                    driver.findElement(webdriver.By.className("btn btn-danger")).click();

                                    driver.findElement(webdriver.By.linkText("Matt Thomas")).click();



No Code Required!!! but does requires Firefox

Some knowledge of HTML/CSS and possibly XPath is helpful

Even though Selenium IDE has a "Save"feature that allows users to keep the tests in a table-based format for later import and execution, it is not designed to run your test passes nor is it designed to build all the automated tests you will need.
Selenium IDE is simply intended as a rapid prototyping tool.

Can also be played back using Selenium HTML Runner


It's not hard... unless you have to use IE :P

Install it and write your first test!

One step at a time, write small chucks and test, rinse and repeat

While writing your test, do the process manually, inspecting the DOM

If required, XPath is your best friend or your worth enemy.

All projects can use a limited set of acceptance tests, ok, maybe not APIs

Define a process for when and how your Acceptance tests should be run


Slides: /presentations/automated-tests-with-selenium

Print the presentation
Created with Reveal.js