Difference between revisions of "Testing Area/Behat Testing/Error & Solutions"
From Mahara Wiki
(→Dropping only the behat_ tables: Add a statement that will generate the drop tables call for MySQL/MariaBD)
|(One intermediate revision by the same user not shown)|
|Line 434:||Line 434:|
This happens when you interrupt behat 🤭 It doesn't like interruptions -_-
This happens when you interrupt behat 🤭 It doesn't like interruptions -_-
If it's still not fixed, try running a test again and *let it finish 😉* It might shut behat down properly and give you your local Mahara back to you 🌈
If it's still not fixed, try
running a test again and *let it finish 😉* It might shut behat down properly and give you your local Mahara back to you 🌈
Revision as of 10:19, 8 November 2021
Errors when using Behat
This is a place where you can log errors and come to fix yours. If you log an error please be sure to put down how you fixed it
If you are getting a permission denied:
- [WAR] 7e (/var/www/maharacode/mahara/external/vendor/behat/gherkin/src/Behat/Gherkin/Cache/FileCache.php:88) file_put_contents(/tmp/behat_gherkin_cache/412/7852eac8b52e46380d27aa7d2702426c.feature.cache): failed to open stream: Permission denied
Make sure the following files are owned by the apache user:
- sitedata (directory in your $cfg->behat_dataroot)
If not, update their permissions:
- sudo chown -R www-data.www-data /tmp/behat_gherkin_cache
- sudo chown -R www-data.www-data /tmp/behat_rerun_cache
- sudo chown -R www-data.www-data sitedata (directory in your $cfg->behat_dataroot)
- For Ubuntu, apache runs with user www-data
- For Centos, apache runs with user apache
Behat tests cannot run unless $cfg->behat_wwwroot, $cfg->behat_dataroot, and $cfg->behat_dbprefix are defined in config.php
Make sure the following following lines of code are in your config.php file
$cfg->behat_dbprefix = 'behat_'; // must not empty $cfg->behat_dataroot = "/var/lib/maharadata/master_behat"; // Behat's copy of maharadata $cfg->behat_wwwroot = 'http://localhost:8000'; // Must be this $cfg->behat_selenium2 = "http://127.0.0.1:4444/wd/hub"; // Must be this
Version of OpenJDK is too new
In some cases, depending on the version of Ubuntu you have, the wrong version of OpenJDK will be installed. Selenium only runs with OpenJDK 8, but Ubuntu Bionic tends to install OpenJDK 11 (especially if 'default-jre' was installed)
If it says you're using OpenJDK 10 or 11 (which can ship with Ubuntu 18.04 depending on which service pack is used), this needs to be uninstalled first:
sudo apt remove --purge openjdk*
Once this is removed, you will need to re-run the OpenJDK 8 installation:
$ sudo apt install openjdk-8-jre-headless
Server not started
When Selenium upgrades causing firefox to try run headless and not open firefox. It can also throw an error when you try to run the test. It will mention something about the Selenium server not being able to start up.
- First try the 'Shut down incorrectly' steps below - if you have had behat running successfully in the past
- Go to the script: mahara/test/behat/mahara_behat.sh script.
- Update the version (around lines number 95 and 96 of the sh file):
* SELENIUM_VERSION_MAJOR=x.xx * SELENIUM_VERSION_MINOR=x
- Download the latest jar file from: http://www.seleniumhq.org/download/
- Save the jar file to /mahara/test/behat/
- Auto update by running:
sudo -u www-data ./test/behat/mahara_behat.sh rundebug @tag
To find out if Selenium has updated to a new version, go to http://www.seleniumhq.org/download/ and see the version of the Selenium Server is available.
You might need to do some more debugging. But this information should point you in the right direction.
Shut down incorrectly
Another bug with Selenium is if you are using Moodle or running Behat from two diff versions of Mahara is sometimes the Selenium Server doesn't shut down properly. You will know this is happening if you've run the tests and it says at the end "Selenium server not not shut down" or it just won't say that's it has shut down. It will be written the same way it does when Selenium starts up when you run the tests.
Eg: Composer installing... PHP server running, Selenium running. At the end of the tests running, it says the same thing.. the PHP server shut down... Selenium shut down.
When you try to run the tests it may also say "Selenium server is not running or could not be run" or something similar. This is because there are 2 running and it's getting confused
Temporary fix, go to the terminal and type
ps aux | grep selenium
And then kill the process ID. This is the first number after your username.
<username>@<computername>:~$ ps aux | grep selenium
<username> 6590 0.0 0.0 12960 936 pts/26 S+ 10:31 0:00 grep --color=auto selenium
So the command will be
However, don't kill the one that says --color=auto selenium you should kill the other one.
Then run the command again to make sure that the server was killed
ps aux | grep selenium
This will just kill selenium running so you can finish what you are working on and run the test properly.
Once you have done that, if you are a dev take a look into the /test/behat/mahara_behat.sh script because there will be something up with the way that selenium is shutting down. Also, check that this issue isn't happening with Jenkins. However, keep in mind that Jenkins runs headless.
If you aren't a dev then go tell one of the devs that it's not shutting down properly. Or you can do this by writing a bug on Launchpad here: https://bugs.launchpad.net/mahara/+filebug In the summary write Behat: tell them what the issue is here. Just so they can tell instantly it's a Behat issue you are having.
Can't log in
Firefox upgrades and when you run the tests Firefox won't pop up with the Mahara instance in it. Another issue is the window opening but Behat not being able to run the test properly and it will say that you cant log in. It will run the first log in steps (say as an admin) but it won't pass the next step (to verify that the admin can be logged in) and if you actually look at Behat running (requires you to not be running it headless) then you will see it's not actually logging in.
LINK TO ROLLBACK FIREFOX VERSION 28
ROLLBACK TO VERSION 42
sudo apt-get purge firefox wget https://launchpad.net/~ubuntu-mozilla-security/+archive/ubuntu/ppa/+build/8220812/+files/firefox_42.0+build2-0ubuntu0.14.04.1_amd64.deb
sudo dpkg -i firefox_42.0+build2-0ubuntu0.14.04.1_amd64.deb
sudo apt-mark hold firefox
Follow instructions in the link above to unhold and update.
Generally, Firefox and Selenium are heavily entwined. When Firefox breaks, go to http://www.seleniumhq.org/download/ and download the newer version of Selenium. When one upgrades it's usually best to upgrade the other at the same time so they are compatible.
If all else fails then revert back to the previous stable version.
I change the directory to downloads and run this in a separate terminal. This requires you to have the previous version of Firefox downloaded and still sitting in downloads. java -jar selenium-server-standalone-2.44.0.jar -Dwebdriver.firefox.bin=/home/jinelleb/Downloads/firefox/firefox
PHP server issues
Server not closing
Same as the Selenium server issues, you can get errors with the PHP server not closing or running multiple servers. You can tell this because it will give an error message when you try to run the tests. It will generally throw an error with the keywords "localhost 8000" or "PHP server".
There could be multiple things causing this issue including the config file not point to the right hostname.
Grep search for PHP server and kill the process ID.
Go to your Mahara config.php and read the Behat section and make sure that everything is pointing to the right place.
If these fail then if you aren't a dev file a bug here https://bugs.launchpad.net/mahara/+filebug with the summary Behat: description of what's happening when you try to run tests.
If you are a dev then you need to look into the mahara_behat script and check the PHP server is closing properly. A way to debug is to run a test locally and check if the PHP server is starting up and shutting down properly. It will say in the terminal if you run "rundebug". I think it runs with just run as well.
Originally composer wasn't pegged. Now it has been you can often get a yellow error when you run Behat that mentions composer dependencies being out of date. It will say "Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies".
- Run update to update them.
- Delete the lock file (mahara/external/composerlock.php) and then run Behat again.
Debugg steps that are failing
Test keeps failing
When you are trying to write a test but the test keeps failing on a step and you don't know why it's failing. You need to be able to find a way to hold the window open so you can see what's happening.
For a start when you run the test run using the debug option instead of just "run" this will give you a more human-readable output. The step that is failing will go red. EG:
./test/behat/mahara_behat.sh rundebug @youtagthatyouwanttorun
To hold the window open so you can add a step right before the one breaking saying And I wait "30" seconds. Another way of holding the window open for a longer period of time is to click on the terminal in the and hit ctrl+z this will pause the test from running right where it is. You then need to type fg to bring the test back into the foreground and let it keep running till the end.
Stopping a test
A test has started running and you need to stop it in the middle of it.
Press ctrl+c this will stop it from running
Dropping only the behat_ tables
If you want to drop your behat_ tables but not the whole database, first connect to the db:
(NB: if the database you're using is not called mahara-master, replace with your DB's name)
psql -U maharauser -h localhost mahara-master
When you see the db prompt
you can run this command:
DO $do$ DECLARE _tbl text; BEGIN FOR _tbl IN SELECT quote_ident(table_schema) || '.' || quote_ident(table_name) -- escape identifier and schema-qualify! FROM information_schema.tables WHERE table_name LIKE 'behat_' || '%' -- your table name prefix AND table_schema NOT LIKE 'pg_%' -- exclude system schemas LOOP -- RAISE NOTICE '%', EXECUTE 'DROP TABLE ' || _tbl || ' CASCADE'; END LOOP; END $do$;
If you just want to see what it will delete before running it change these two lines
-- RAISE NOTICE '%', EXECUTE
RAISE NOTICE '%', -- EXECUTE
Once you've run the commands, use Ctrl D to exit the DB.
Connect to the DB as a user that can drop tables and then run the following:
SET SESSION group_concat_max_len = 1000000; SELECT CONCAT( 'SET FOREIGN_KEY_CHECKS = 0; DROP TABLE IF EXISTS ', GROUP_CONCAT(table_name), '; SET FOREIGN_KEY_CHECKS = 1;' ) AS statement FROM information_schema.tables WHERE table_schema = 'maharatest2' AND table_name LIKE 'behat_%';
This will generate an SQL statement. Copy and paste that into your db session and this will clean up the tables.
Having trouble getting your Behat testing started up again
Sometimes if Behat crashing in an unexpected way it can be a bit of a bother to get it started up again.
If you follow these 3 steps it should fire up again.
- Kill any still running Selenium processes
- Drop the behat prefixed tables from the database
- Delete the 'behat' subdirectory of the $cfg->behat_dataroot directory
Doing things in this order should make sure that localhost ports in use are released, that the behat site is not installed and that the behat dataroot flag that indicates the behat system is setup is also removed - so your system is set back to the point before you ever ran behat for the first time.
Tests failing erratically since Chrome/Chromium upgrade to version 61
If you have suddenly noticed tests are failing to find visible items on the page sometime in September 2017, you're not alone! The latest stable version of Chrome/Chromium, 61.0.3163.100, is playing havoc with webdriver's ability to find stuff. Hopefully this issue will be fixed in a subsequent release, but in the meantime you can work around it by installing the previous stable version.
For Chromium, run:
or for chrome, run:
If the answer is:
Google Chrome 61.0.3163.100
it looks like this is your problem. The previous stable version of Chrome/Chromium is 60.0.3112.113.
If you don't have a copy of the old version saved already, you will need to search for it online. Try searching for your OS name with Chrome/Chromium 60.0.3112.113.
For Chromium on Ubuntu, I can help you.
For 14.04, go to:
And for 16.04, go to:
And for 17.04, go to:
You'll need to download two packages:
(If you don't know which codecs you need, just grab the 'extra' version.)
You've downloaded the file/s. Now what?
Back on your system, you'll need to uninstall the current version before you try to install the older version. In Ubuntu:
sudo apt-get remove chromium-browser sudo apt-get remove chromium-codecs-ffmpeg-extra sudo apt-get remove chromium-codecs-ffmpeg
(One of the codec packages will tell you it wasn't installed in the first place. Don't worry about that.)
Chrome doesn't have a separate codecs package, so for Chrome:
sudo apt-get remove google-chrome
The easiest way to install is to go to the directory you downloaded the packages in and double click to install. For Chromium, you will need to install the codec package before the browser package or you'll get an error.
Installing old packages
Go to the directory where you downloaded them and install the codecs first:
sudo dpkg -i chromium-codecs-ffmpeg-extra_60.0.3112.113-0ubuntu0.16.04.1298_amd64.deb
Then the browser:
sudo dpkg -i chromium-browser_60.0.3112.113-0ubuntu0.16.04.1298_amd64.deb
Now you should be good to run your tests again without things breaking... (fingers crossed).
Stopping Chrome/Chromium auto-updating and undoing all your hard work
You'll need to lock the version you just installed, to save having to do this all again soon. I can help with Ubuntu:
sudo apt-mark hold chromium-browser
and, depending on the codecs you installed,
sudo apt-mark hold chromium-codecs-ffmpeg-extra
sudo apt-mark hold chromium-codecs-ffmpeg
sudo apt-mark hold google-chrome
Requested config file does not exist
Drop the behat tables
sudo - postgres dropdb behat_master && sudo -u postgres createdb -Omaharauser behat_master
weirdly enough it seems connected to the master-behat db too, so if that doens't work
sudo -u postgres dropdb mahara-master & sudo -u postgres createdb -Omaharauser mahara-master
and this time when you ./test/behat/mahara_behat.sh rundebugheadless test.feature --format=pretty
The site should install at the start of your behat -- this is a good sign ;)
window.isMaharaPageReady is not a function
Check folders (/var/lib/maharadata/master_behat) exist give permissions to folders again with behat steps
It might mean that it didn't shut down properly (accidentally or deliberate interruption), before trying to hack your way around this problem, try to run a basic test to let the normal process shut down behat and give you your local site back
= Try running a test to shut it down normally
An example of a basic test: run.feature
Feature: Test Shut down behat normal process by finishing a test Background: Given the following site settings are set: | field | value | | licensemetadata | 0 | Given the following "users" exist: | username | password | email | firstname | lastname | institution | authname | role | | UserA | Kupuh1pa!| [email protected] | Painterio | Mahara | mahara | internal | member | And the following "pages" exist: # Available fields: title*, description, ownertype*, ownername*, layout, tags | title | description | ownertype | ownername | | Page One A | UserA Page 1 | user | UserA |
Scenario: login as different users to see blocktypes and interaction Given I log in as "UserA" with password "Kupuh1pa!"
Then run ./test/behat/mahara_behat.sh rundebug run.feature --format=pretty
= If that doesn't work
try sudo chmod 777 /var/lib/maharadata/master_behat -R
This happens when you interrupt behat 🤭 It doesn't like interruptions -_- If it's still not fixed, try...
- running a test again and *let it finish 😉* It might shut behat down properly and give you your local Mahara back to you 🌈
- deleting your local mahara database (not the behat one) and installing a new site - something about the set up of Behat looks at your local instance before doing behat stuff... can't explain it but it fixes most problems when the error message is not clear.