Codeception Selenium Setup

This video is available to view for members only.

Click here to Join!

Already a member?


To be able to test our applications as they are used in the real world, we need to move away from the PHPBrowser, and instead, use a tool that more accurately carries out our test tasks as though a real human being were sat at the desk, completing each step.

Because PHPBrowser uses cURL internally, it's impossible for it to interact with modern web pages that contain Javascript. As such, we are forced to use a different tool to complete our tests, if our pages are anything but the most basic.

Selenium is a tool for automating web browsers. It can commandeer a number of installed browsers, but generally Firefox seems easiest, followed by Chrome Canary. At least, that's been my experience. It seems to play nicely with Safari also, but I personally prefer Firefox.

To get Selenium working with Codeception is - at first - quite daunting. But once you've watched this video, you'll see just how easy it is. As ever, there's some initial config to be done in our acceptance.yml file, but after you've done this once, you rarely need to go in and change it.

You can grab a copy of Selenium from here, and the file you're after is the Selenium Server - it's currently at version 2.44, but it changes pretty frequently, so rather than link to it directly, I am going to suggest following the link and grabbing whichever version is available.

You're also going to need Java installed. This differs from OS to OS, but for reference, on my Macbook and Ubuntu PC right now I have:

java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

And the above runs Selenium tests from Codeception just fine. You'll notice this is newer than the version shown in the video.

You'll also need to update your acceptance.suite.yml to comment out PHPBrowser, and add in the WebDriver, eg:

class_name: AcceptanceTester
        - WebDriver
        - AcceptanceHelper
            browser: firefox
            host: # this is the ip address of the machine running the instance of Selenium, not necessarily the server
            url: ''

The good news is, your tests won't need to be changed. If anything, you actually gain a lot more functionality. But to get that functionality available to your test suite, you need to re-run the build command:

php vendor/codeception/codeception/codecept build

Aside from that, there's really not much to it. It's your classic - sounds more scary than it is.

Code For This Course

Get the code for this course.

Share This Episode

If you have found this video helpful, please consider sharing. I really appreciate it.

Episodes in this series

# Title Duration
1 Installing Codeception in Your Symfony 2 Project 04:20
2 Bootstrapping Codeception 03:29
3 Codeception's Folder Structure 06:42
4 Generating Tests 06:28
5 How to Run Codeception Tests 02:43
6 Our First Acceptance Test 08:00
7 An Alternative Perspective on Acceptance Testing 04:33
8 Acceptance Testing Symfony Forms 08:22
9 Acceptance Testing and Javascript (Part 1 of 2) 07:31
10 Acceptance Testing and Javascript (Part 2 of 2) 08:05
11 An Introduction to Unit Testing in Codeception 04:24
12 Unit Testing a Symfony Service 11:59
13 Integration with Symfony 2 06:27
14 Databases and Unit Tests 14:21
15 Real World Unit Testing - Database Clean Up Issues 06:15
16 Fast PHP Unit Testing with SQLite Database 10:19
17 Mocking the Entity Manager 20:22
18 Codeception Selenium Setup 06:08
19 How to Setup XDebug with PHPStorm 07:36
20 Step Objects and Page Objects 09:35
21 Fizz Buzz Kata 24:43
22 Code Coverage Reports 10:10
23 Running Acceptance Tests Faster With Phantom JS 01:30
24 Mobile Browser Tests 01:18