Skip to content

Web-Application testing using PHPUnit.

Installing selenium and web-drivers for Chrome & Firefox on Linux x64 and using phpunit.

Installation

General

In your home directory create directory ~/lib/selenium to start running selenium from.

mkdir -p ~/lib/selenium

Browser Web-drivers (download)

Webdriver for Chrome

Download the webdriver for Chrome from Google.

cd ~/lib/selenium
wget https://chromedriver.storage.googleapis.com/108.0.5359.22/chromedriver_linux64.zip
unzip chromedriver_linux64.zip

Webdriver for Edge

Download the webdriver for Edge driver from Microsoft

Not spend any time to it.

Webdriver for Firefox

Download the Selenium for Firefox (v107.0) from GitHub

cd ~/lib/selenium
wget https://github.com/mozilla/geckodriver/releases/download/v0.32.0/geckodriver-v0.32.0-linux64.tar.gz
unzip chromedriver_linux64.zip

Selenium Standalone

Create shell script start.sh to start the server with the downloaded webdriver locations.
When in the same directory it is not needed pass them on the command line. It seems it also tries to find using the path environment variable.

When on Linux

#!/usr/bin/env bash

java -jar \
-Dwebdriver.chrome.driver=./chromedriver \
-Dwebdriver.firefox.driver=./geckodriver \
selenium-server-4.6.0.jar standalone --port 4444 

When on Windows

@echo off

java 
-Dwebdriver.chrome.driver=.\chromedriver.exe ^
-Dwebdriver.firefox.driver=.\geckodriver.exe ^
-jar selenium-server-4.6.0.jar -port 4444

PHP Unit Testing (Linux)

Installing

Got the information from the PHPUnit Website.

Install using PHP composer the following modules in the root of your PHP project.
The <project-root>/vendor directory is created in the root of the project where the composer command is executed.

You need composer v2 because v1 is obsolete.

Added option --ignore-platform-reqs to ignore required and not installed PHP-modules (). Als added option --dev since they are only used during development and not for deployment.

composer require --ignore-platform-reqs --dev phpunit/phpunit
composer require --ignore-platform-reqs --dev phpunit/phpunit-selenium

Running PHP remote using local Browser

Tunneling port 4444 of localhost back the local running Selenium server for when running a test from the command line on a remote machine.
Adding the debugging port tunnel for your IDE can be achieved adding -R 9000:localhost:9000 at the end.

ssh <user>@<machine> -R 4444:localhost:4444
# And fro debugging at the same time.
ssh <user>@<machine> -R 4444:localhost:4444 -R 9000:localhost:9000

Selenium Firefox

For selenium on Firefox you need a profile called selenium

Goto the profile manager by entering about:profiles as the address in the omni-bar. Click on the 'Create New Profile' button and enter the name 'selenium'`.