run tests that involve Javascript

run tests that involve Javascript

by Amin Farajzadeh -
Number of replies: 2
Hi smile


I want to use behat to test my code using this documentation :

Running_acceptance_test


But when i run test it gives me this error : 

Selenium server is not running, you need to start it to run tests that involve Javascript. More info in http://docs.moodle.org/dev/Acceptance_testing#Running_tests

In documentation i saw a NOTE abut:



But this site does not exist any more:

http://www.installationpage.com/selenium/how-to-run-selenium-headless-firefox-in-ubuntu/


On the other hand when i ignore javascript  using '~@javascript' tag, behat works fine

What should i do?sad

Average of ratings: -
In reply to Amin Farajzadeh

Re: run tests that involve Javascript

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You don't have to run Selenium in a headless environment.  If you've got a GUI session running, you can just run that java -jar line in a shell and it will work, it will just display the browser window and show it completing the steps.

If you do want to run it headlessly, you could try the recent work to support headless chrome (this actually bypasses Selenium entirely, which is nice):

https://tracker.moodle.org/browse/MDL-58948

Or if you want to do it with firefox, it's something like this:

  • Install a headless X server like Xvfb (exactly how differs according to your OS, something like apt-get install xvfb)
  • Start an instance of the headless X server to create a virtual display, e.g Xvfb :1 -screen 0 1600x1200x32
  • In a new shell, set the display environment variable to the display you just created.  In the example above, I think it will be export DISPLAY=0:1
  • In the same shell, run the java -jar line. This will start selenium within the virtual display.
  • Run behat, pointing it at the selenium sever (probably localhost:4444).  The javascript tests should run, but you wont see them.
In reply to Mark Johnson

Re: run tests that involve Javascript

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Make sure you are running the right version of the browser, it defaults to Firefox, see the docs for the right version (from memory it is v.45)