This is a demonstration project to accompany the tutorial on how to use CodeceptJS with Chrome running with Selenium using Docker Compose. This example project uses an empty Wordpress site as the test subject.
Install Node & NPM min. version v8.9, but recommended node v9. Recommend installing node using nvm, because we're using .nvmrc to specify the node version.
Install Docker Compose by following the instructions: https://docs.docker.com/compose/install/
- Run
docker-compose up -d
WARNING: Step 2 needs to only be ran on first project setup or anytime you deleted docker volumes and want to create a new, clean DB.
- Run the following command (will load the DB dump in the container:
docker-compose exec db /bin/bash -c "mysql -uroot -psomepsw wordpress < /code/backup.sql"
This will populate the DB with some default wordpress date and user with the following credentials:
username: admin
password: secureP@ssw0rd1
- If you want to dump your wordpress DB you can run:
docker-compose exec db /bin/bash -c "mysqldump -uroot -psomepsw wordpress --result-file=/code/backup.sql"
Append wptests
mapping in hosts file:
sudo echo '127.0.0.1 wptests' | sudo tee -a /etc/hosts
For windows or other environments, you can use any other editor to append this line to your hosts file:
127.0.0.1 wptests
Test it in the browser by going to:
Run:
npm i
Run:
docker-compose up -d
This way of running the tests is good when developing them. However at the end you should always check if they also pass in the Docker Compose environment.
Only for the first time:
npm run selenium:install
Start selenium:
npm run selenium:start
Open a new terminal tab and run:
npm run test:selenium-standalone
Run the following command
npm test
Change in package.json script test:current
to grep the name of your feature.
Then run:
npm run test:current
Run:
npm run test:debug
Then attach to node debug process on port 51413.
Attaching to log of web container:
docker-compose logs -t -f wordpress
I did not want codeceptjs as global dependency, so I installed it as local and added an NPM script to be able to run codeceptjs commands.
Here is a shortcut to running the command:
npm run cjs [command_name]
Examples:
npm run cjs # lists all command options
npm run cjs shell # starts interactive shell
npm run cjs generate:test signup # generates new test named signup
npm run cjs gt signup # generates new test named signup (shortcut)
npm run cjs list # lists all available test actions