Giter VIP home page Giter VIP logo

elife-behat-public's Introduction

Behat - elifesciences.org

If you want to run javascript tests, please check the prequisites below, otherwise for non-javascript tests just:

In order to modify the location of the site you are testing, for example if you want to test a dev site, vs the live site, you can specify the base url in the behat.yml file.

Setting up Javascript testing with Sahi and phantomjs

Prerequisites

If you haven't already got them on the machine, you'll need to install sahi and phantomjs for testing javascript behaviours.

Sahi

phantomjs

Setup

Be sure Behat knows to use sahi and phantomjs, behat.yml should look like this:

default:
  paths:
    bootstrap:  '%behat.paths.features%/bootstrap'
  extensions:
    Behat\MinkExtension\Extension:
      base_url: URL_UNDER_TEST
 >>>  javascript_session: sahi
 >>>  browser_name: phantomjs
      goutte: ~
      sahi: ~

Additionally, Sahi needs to know where phantomjs is, and how to handle it. Tell it by adding the following to [sahi_location]/userdata/config/brower_types.xml. Ensure that the <path> to phantomjs is correct for your environment, and edit <options> to provide the full path to phantom-sahi.js.

<browserType>
    <name>phantomjs</name>
    <displayName>PhantomJS</displayName>
    <icon>chrome.png</icon>
>>> <path>/usr/local/bin/phantomjs</path>
>>> <options>--proxy=localhost:9999 $userDir/config/phantom-sahi.js</options>
    <processName>phantomjs</processName>
    <capacity>100</capacity>
        <force>true</force>
</browserType>

What's phantom-sahi.js?

It bridges between sahi and phantom. Copy the following, save it to the path specified in <options> above, and there you go:

if (phantom.args.length === 0) {
console.log('Usage: sahi.js <Sahi Playback Start URL>');
    phantom.exit();
} else {
    var address = phantom.args[0];
        console.log('Loading ' + address);
    var page = new WebPage();
        page.open(address, function(status) {
        if (status === 'success') {
            var title = page.evaluate(function() {
                    return document.title;
    });
            console.log('Page title is ' + title);
        } else {
            console.log('FAIL to load the address');
            }
    });
}

(Sahi and phantomjs info abstracted from http://shaneauckland.co.uk/2012/11/headless-behatmink-testing-with-sahi-and-phantomjs/

Running

  • Start Sahi:

    • cd [sahi_location]/bin/
    • ./sahi.sh
    • This should tell you that Sahi is running on port 9999, and that it's reading the browser_types.xml file from the location you edited above.
  • Run the tests:

    • cd [root of this repo]
    • All tests: ./bin/behat
    • All except JavsScript tests: ./bin/behat --tags '~@javascript'
    • Only JavaScript tests: ./bin/behat --tags '@javascript'

Troubleshooting

Sahi doesn't start, or starts, but not on port 9999

Check browser_types.xml contains a definintion (<browserType> element), for phantomjs, its path is correct, and that a proxy is defined for it on port 9999 (within <options>).

Behat times out when running JavaScript tests

One reason this happens is that Sahi can't find phantom-sahi.js. Ensure that its path is correct in the definition of phanotomjs in browser_types.xml.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.