Difference between revisions of "Testing/Behat Testing/Run Behat On Docker"

From Mahara Wiki
Jump to navigation Jump to search
(Run mahara container)
(Update behat settings in config.php)
 
(7 intermediate revisions by one other user not shown)
Line 53: Line 53:
 
For those who haven't got access to catalyst docker registry, the images are available to download via [https://seafile.catalyst.net.nz/d/ca18fd0a93/ catalyst seafile]
 
For those who haven't got access to catalyst docker registry, the images are available to download via [https://seafile.catalyst.net.nz/d/ca18fd0a93/ catalyst seafile]
  
* Download the file ubuntu1404_lappf.tar from [https://seafile.catalyst.net.nz/d/ca18fd0a93/ catalyst seafile]
+
* Download the file ubuntu1404_lappf.tar.gz from [https://seafile.catalyst.net.nz/d/ca18fd0a93/ catalyst seafile]
 
* Load it to your local docker
 
* Load it to your local docker
  $ sudo docker load -i <path to ubuntu1404_lappf.tar> <image name>
+
  $ sudo docker load -i <path to ubuntu1404_lappf.tar.gz> <image name>
 
  $ sudo docker images
 
  $ sudo docker images
  
 
== Run behat tests on docker ==
 
== Run behat tests on docker ==
 
=== Useful scripts ===
 
=== Useful scripts ===
You can download two shell script files from [https://seafile.catalyst.net.nz/d/ca18fd0a93]
+
You can download shell script files from [https://seafile.catalyst.net.nz/d/ca18fd0a93]
  
 
* '''run_mahara_container.sh''' helps you to run mahara container;
 
* '''run_mahara_container.sh''' helps you to run mahara container;
 +
 +
* '''stop_mahara_container.sh''' stop a mahara container;
  
 
* '''run_mahara_tests.sh''' is for running behat tests.
 
* '''run_mahara_tests.sh''' is for running behat tests.
Line 69: Line 71:
 
  $ run_mahara_container.sh <name of container> <port> <path to mahara code> <path to mahara dataroot> [<image name>]
 
  $ run_mahara_container.sh <name of container> <port> <path to mahara code> <path to mahara dataroot> [<image name>]
  
You will choose a <name of container> to identify the container in case you are running multiple mahara container. The <name of container> will be also used for running behat tests (see below).
+
* Choose a <name of container> to identify the container in case you are running multiple mahara containers. The <name of container> will be also used for other commands(see below).
  
<port> is used for access the mahara site on the docker via web browser. After your docker container is succesfully launched, you can access the mahara site via the URL: http://localhost:<port>/.
+
* Choose a <port> to access the mahara site on the docker via web browser. After your docker container is succesfully launched, you can access the mahara site via the URL: http://localhost:<port>/.
  
<path to mahara code> is the path to your mahara code directory on the host machine. This must contain the 'htdocs' directory.
+
* <path to mahara code> is the path to your mahara code directory on the host machine. This must contain the 'htdocs' directory and must be '''readable''' by user www-data.
  
Please make sure your <path to mahara code>/htdocs/config.php is updated correctly and
+
* <path to mahara dataroot> is the path to store the mahara site data on the host machine. The cron.log file will be stored in this as well. This must  be '''readable and writable''' by user www-data. Run the following command to create it
the <path to mahara code> is readable by user www-data and <path to mahara dataroot> is readable and writable by www-data
+
$ sudo -u www-data mkdir -p <path to mahara dataroot>
 +
 
 +
* Update the <path to mahara code>/htdocs/config.php file with:
  
 
  $cfg->wwwroot  = 'http://localhost:<port>/';
 
  $cfg->wwwroot  = 'http://localhost:<port>/';
Line 89: Line 93:
 
  $cfg->dbpass  = 'mahara';
 
  $cfg->dbpass  = 'mahara';
  
In order to access the postgres db server on the container, run
+
You can use the postgres server running on your host machine.
 +
 
 +
$cfg->dbhost  = '<your host machine IP address>';
  
$ sudo docker exec -it <name of container> sudo -u postgres psql mahara-db
+
You will see the text '''You can now access the mahara site at http://localhost:<port>/''' if succeeded.
  
Please note that the database on the docker container will be deleted when you stop the container
+
The script will generate css and install PHP Composer and required components if needed.
  
You can use the postgres server running on your host machine.
+
=== Stop a running mahara container ===
 +
$ stop_mahara_container.sh <name of container>
  
  $cfg->dbhost  = '<your host machine IP address>';
+
=== Access the postgres database on the running container ===
 +
  $ sudo docker exec -it <name of container> sudo -u postgres psql mahara-db
 +
Please note that the database on the docker container will be deleted when you stop the container
  
 
=== Run mahara behat tests ===
 
=== Run mahara behat tests ===
 +
While the container running, you can run behat tests in another terminal.
 
==== Update behat settings in config.php ====
 
==== Update behat settings in config.php ====
 
* Create the 'behat' directory inside <path to mahara dataroot>, and make sure it is  writable by www-data
 
* Create the 'behat' directory inside <path to mahara dataroot>, and make sure it is  writable by www-data
Line 107: Line 117:
 
  $cfg->behat_wwwroot  = 'http://localhost/';
 
  $cfg->behat_wwwroot  = 'http://localhost/';
 
  $cfg->behat_dataroot = '/var/lib/sitedata/behat';
 
  $cfg->behat_dataroot = '/var/lib/sitedata/behat';
 +
$cfg->behat_selenium2 = "http://127.0.0.1:4444/wd/hub";
 +
 
==== Run tests ====
 
==== Run tests ====
 
  $ run_mahara_tests.sh <name of container> run|rundebug [@tag_name|<feature file>]
 
  $ run_mahara_tests.sh <name of container> run|rundebug [@tag_name|<feature file>]

Latest revision as of 14:50, 15 November 2016

You can use docker to run mahara behat tests on your local machine without concern for os, php or firefox compatibility. Using docker, you can run the tests on your Linux, Windows or Mac machine.

Install Docker on your machine

Please read more detailed information for Mac users and for Windows users.

Here are a quick start for Ubuntu users

Install Docker on Ubuntu machine

These instructions are for Ubuntu 14.04 and 16.04 You should have sudo privilege to install.

Update your apt sources

  • Update package info
$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates
  • Add the new GPG key for Docker’s APT repository
$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
  • Add an line for your Ubuntu to the /etc/apt/sources.list.d/docker.list file
    • On Ubuntu Trusty 14.04 (LTS)
$ sudo bash -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" >> /etc/apt/sources.list.d/docker.list'
    • On Ubuntu Xenial 16.04 (LTS)
$ sudo bash -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" >> /etc/apt/sources.list.d/docker.list'
  • Update the APT package index and verify APT repository for docker
$ sudo apt-get update
$ apt-cache policy docker-engine

Install linux-image-extra-* packages

$ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
$ sudo reboot

Install docker

$ sudo apt-get install docker-engine
$ sudo service docker start

Docker images for mahara developers and testers

Catalyst Docker Registry

All internal docker images should be pulled/pushed from/to our catalyst private registry. If you don't have a login credential on it, please make a new request on the WR #245259.

Login to catalyst docker registry

$ sudo docker login https://cat-prod-dockerregistry.catalyst.net.nz
Username (<your username>): 
Password: 
Login Succeeded
$ sudo docker info

Pull mahara docker images

$ sudo docker pull cat-prod-dockerregistry.catalyst.net.nz/sonn/mahara-dev:trusty64-apache24-php55-postgres-firefox45

The image name 'cat-prod-dockerregistry.catalyst.net.nz/sonn/mahara-dev:trusty64-apache24-php55-postgres-firefox45' will be the default image when run the script run_mahara_container.sh

Mahara docker images on seafile

For those who haven't got access to catalyst docker registry, the images are available to download via catalyst seafile

  • Download the file ubuntu1404_lappf.tar.gz from catalyst seafile
  • Load it to your local docker
$ sudo docker load -i <path to ubuntu1404_lappf.tar.gz> <image name>
$ sudo docker images

Run behat tests on docker

Useful scripts

You can download shell script files from [1]

  • run_mahara_container.sh helps you to run mahara container;
  • stop_mahara_container.sh stop a mahara container;
  • run_mahara_tests.sh is for running behat tests.

Run mahara container

$ run_mahara_container.sh <name of container> <port> <path to mahara code> <path to mahara dataroot> [<image name>]
  • Choose a <name of container> to identify the container in case you are running multiple mahara containers. The <name of container> will be also used for other commands(see below).
  • Choose a <port> to access the mahara site on the docker via web browser. After your docker container is succesfully launched, you can access the mahara site via the URL: http://localhost:<port>/.
  • <path to mahara code> is the path to your mahara code directory on the host machine. This must contain the 'htdocs' directory and must be readable by user www-data.
  • <path to mahara dataroot> is the path to store the mahara site data on the host machine. The cron.log file will be stored in this as well. This must be readable and writable by user www-data. Run the following command to create it
$ sudo -u www-data mkdir -p <path to mahara dataroot>
  • Update the <path to mahara code>/htdocs/config.php file with:
$cfg->wwwroot  = 'http://localhost:<port>/';
$cfg->dataroot = '/var/lib/sitedata';

The container has a PostgreSQL server running on it. You can use it with the following settings

$cfg->dbtype   = 'postgres8';
$cfg->dbhost   = 'localhost';
$cfg->dbuser   = 'maharauser';
$cfg->dbname   = 'mahara-db';
$cfg->dbpass   = 'mahara';

You can use the postgres server running on your host machine.

$cfg->dbhost   = '<your host machine IP address>';

You will see the text You can now access the mahara site at http://localhost:<port>/ if succeeded.

The script will generate css and install PHP Composer and required components if needed.

Stop a running mahara container

$ stop_mahara_container.sh <name of container>

Access the postgres database on the running container

$ sudo docker exec -it <name of container> sudo -u postgres psql mahara-db

Please note that the database on the docker container will be deleted when you stop the container

Run mahara behat tests

While the container running, you can run behat tests in another terminal.

Update behat settings in config.php

  • Create the 'behat' directory inside <path to mahara dataroot>, and make sure it is writable by www-data
$ sudo -u www-data mkdir <path to mahara dataroot>/behat
  • Update behat settings in <path to mahara code>/htdocs/config.php
$cfg->behat_dbprefix  = 'behat_';
$cfg->behat_wwwroot  = 'http://localhost/';
$cfg->behat_dataroot = '/var/lib/sitedata/behat';
$cfg->behat_selenium2 = "http://127.0.0.1:4444/wd/hub";

Run tests

$ run_mahara_tests.sh <name of container> run|rundebug [@tag_name|<feature file>]