Testing with Behat Locally
- If you haven’t installed Sauce Connect Proxy on your machine; now is the time to do so. See Installing Sauce Connect Proxy below.
Prep Your Project for Behat Tests (a One Time Setup)
-
Install behat dependencies
cd profiles/express/tests/behat
composer install -
Start Lando
lando start
You need the Lando container for the rest of this. -
Install modules for testing
lando drush dl delete_all
lando drush en delete_all -y
Downloads Delete_All modules to /app/sites/all/modules/delete_all folder. This module makes it easy to delete all test content before starting tests over.lando drush en cu_behat_tests -y
This module enables all the bundles and installs local users. Go stretch your legs while it all installs.Note: We’ll especially need to use these local users when the WebExp team users are not longer automatically added to Express installs.
-
Put site in Mixed Mode
lando drush php-eval "variable_set('ldap_authentication_conf', array('authenticationMode' => 1));"
So our precious local users can login to the site.
(in the browser: (admin/config/people/ldap/authentication) -
Duplicate behat.local.yml to my.behat.local.yml and update it with local environmental variables (i.e. server URL and access info) In profiles/express/tests/behat
cp behat.local.yml my.behat.local.ymlYou’ll use my.behat.local.yml to run local tests. It is GitIgnored.
lando infoto verify your local server URL (http://mySiteName.lndo.site)
Edit my.behat.local.yml file and replace:extensions: Behat\MinkExtension: base_url: "yourLocalUrl"With your localhost site address:
extensions: Behat\MinkExtension: base_url: "http://mySiteName.lndo.site"DEPRECATED You’ll need to add the Environmental Variables username and access key to the session called ‘sauce’. (Get these from a team member.)
sauce: sauce_labs: username: USER-NAME access_key: ACCESS-KEY connect: trueYour project is now ready to run the automated tests.
Running the Behat Tests
Start the Servers
-
Stop and Start Lando
If you forgot to Cntl-C the server last night, you’ll have to force it to quit by stopping and starting Lando. Otherwise the next command may have trouble.
lando stop
lando start -
Start webserver
From project root:
lando drush runserver 127.0.0.1:8079 -
Start Chrome Headless Browser
From project root:/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-gpu --headless --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 --crash-dumps-dir=/tmp --user-data-dir="$HOME/Library/Application Support/Google/Chrome"
DEPRECATED
- Start Sauce Proxy Server
cd to {sauce-labs-proxy-folder} and runbin/sc -u USER-NAME -k ACCESS-KEY(Same info as in my.behat.local.yml; get from a team member)
Run the Tests
-
Run the tests
From behat folder (/profiles/express/tests/behat), run behat command.
The basic command is
./bin/behat --config my.behat.local.yml
./bin/behat --config my.behat.local.yml --verbose --strict --stop-on-failure --tags '@runThisTag'Add other parameters as necessary:
--verbose --strict --stop-on-failure --tags '@runThisTag'Tags: specify desired tag(s) either as parameters in the command or in my.behat.local.yml
Behat will run the goutte tests first, then will come back and run those tagged with@javascript
DEPRECATED
- Login to Sauce Connect website to view JS tests
Login to Sauce Connect Tunnel should you need to review what’s going on with JavaScript. The login credentials are shared with the team via LastPass.
Deleting content
Content must be deleted before tests can be re-run.
Delete nodes:
Install and enable Drupal module ‘delete-all’ in siteName/modules folder. (note: not the Web Express profile modules folder)
lando drush delete-all for info
lando drush delete-all all --reset sweeps all nodes, revisions and related taxonomy
(You’ll need to re-create homepage)
Delete blocks:
lando mysql
-> use drupal7;
-> delete from bean;
-> delete from bean_revision;
-> delete from embed_templates;
-> exit;
Troubleshooting
- If too many failed login attempts, empty the flood table.
lando mysql -> use drupal7; -> delete from flood; -> exit; - Log everybody out
lando drush sqlq "TRUNCATE sessions"
CU Boulder Express: Notes on setting up Behat for local testing
Hosted Selenium Service Can’t Connect To Travis
Installing Sauce Connect Proxy (One Time Setup)
- Download and install Sauce Connect Proxy for the JavaScript testing. Get Sauce Connect Proxy.