Git Product home page Git Product logo

drupal.go.js's Introduction

drupal.go.js

A node.js tool to automate and test Drupal using the headless browsers Phantom.js.

Introduction

This node.js package provides an easy way to automate and test Drupal using the headless browser Phantom.js. It provides some helpers that make working with Drupal within a headless browser fun and easy.

Installation

Step 1

Install node.js by going to http://nodejs.org

Step 2

You can now install this library using NPM.

npm install drupalgo

Configuration

The configuration for your automation and testing should be placed within a configuration file in *.json form. This file contains your configurations for your Drupal installation as well as other configurations that you would like to include in your automation and testing, such as content creation, etc.

{
  "host": "http://drupal.local/",
  "user": "admin",
  "nodes": [
    {
      "type": "article",
      "title": "Hello There",
      "body": "This is very cool!"
    },
    {
      "type": "article",
      "title": "This is another node",
      "body": "Nice!"
    }
  ]
}

Example

You can now include this library in your test application and then do stuff using the simple drupal.go command. You can also call methods on the Phantom browser instance using the jquerygo Interface. You can read up on how to work with jQuery.go.js by going to https://github.com/travist/jquery.go.js.

For example, if you wish to click the submit button, you could do the following.

var drupal = require('drupalgo');
var $ = drupal.load('config.json');
$('#edit-submit').click(function() {
  console.log('Clicked the submit button');
});

This function returns a Promise to be used with the popular Async.js library making it very simple to build intuitive tests without falling into callback hell.

Here is an example of how simple it is to write some automation with this library...

Login, then create some nodes....

var async =     require('async');
var drupal =    require('drupalgo');

// Load the config.json file... as seen above.
var browser = drupal.load('config.json');

// Login, then create some content...
async.series([
  drupal.go('login'),
  drupal.go('createMultipleContent', drupal.config.get('nodes'))
], function() {
  console.log('We are done!');
  drupal.close();
});

NOTE: It is very important to always close the browser using drupal.close() when you are done with your test to keep zombie browser processes from remaining.

Extending

This library is super easy to extend and create your own Drupal processes. You can do so by simply attaching them to the Drupal object and then they can be utilized with drupal.go like other processes. Here is an example.

var async =     require('async');
var drupal =    require('drupalgo');

// Add a new task to edit the node.
drupal.editNode = function(done) {
  async.series([
    this.go('visit', 'node/1234/edit'),
    this.go('fill', '#edit-title', 'Something else!'),
    this.go('pressButton', '#edit-submit')
  ], done);
};

// Load the config.json file... as seen above.
var browser = drupal.load('config.json');

// Login, then create some content, then EDIT A NODE!...
async.series([
  drupal.go('login'),
  drupal.go('createMultipleContent', drupal.config.get('nodes')),
  drupal.go('editNode')
], function() {
  console.log('We are done!');
  drupal.close();
});

Happy Automating....

drupal.go.js's People

Contributors

travist avatar

Watchers

James Cloos avatar Dinesh waghmare avatar

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.