Sunday, February 21, 2016

Installing SlimerJS-lightweight edition


SlimerJS is similar to PhantomJs, a scriptable browser, except that it runs on top of Gecko, the browser engine of Mozilla Firefox (specifically, version 31), instead of Webkit, and is not yet truly headless.

Since SlimerJS  uses the version of firefox passed in the SLIMERJSLAUNCHER environment variable, edge builds of Firefox can be used. That can be useful for testing and experimenting with modern web-functionality, which is not yet present in PhantomJS.

Since I already have Firefox installed, i will install SlimerJS Lightweight edition from
https://slimerjs.org/download.html:

First download the lightweigt edition 0.9. 6  .zip file to the Downloads directory, then:

cd Downloads
mkdir slimedir
unzip slimerjs-0.9.6.zip -d slimedir



Then open the .bashrc file in a texteditor and at the end insert:

export PATH=$PATH:/Downloads/slimedir/slimerjs-0.9.6

export PATH=$PATH:/Downloads/slimedir/slimerjs-0.9.6/chrome/icons/default

Then reboot.

Basic examples
Get options:


slimerjs --help


A casperjs scriptfile ,here denoted file.js, can be run in context of slimerjs via:

casperjs file.js --engine=slimerjs

From slimerjs.org, an example.js file is:


var webpage = require('webpage').create();
webpage
  .open('http://somewhere') // loads a page
  .then(function(){ // executed after loading
    // store a screenshot of the page
    webpage.viewportSize =
        { width:650, height:320 };
    webpage.render('page.png',
                   {onlyViewport:true});
    // then open a second page
    return webpage.open('http://somewhere2');
  })
  .then(function(){
    // click somewhere on the second page
    webpage.sendEvent("click", 5, 5,
                        'left', 0);
    slimer.exit()
  });

 

The above is run via:
slimerjs example.js





Installing PhantomJS and CasperJS

PhantomJS is a scripted headless browser, based on the WebKit engine. It is used for automating web-page interactions and provides a JavaScript API which enables automation, taking screenshots, simulating user behavior such as submitting forms, clicking links, etc.

Although PhantomJS contains the above utilities on its own, it is easier to use together with
CasperJS  which provides a more intuitive way to script the browser-webpage workflow.

Installing PhantomJS 

cd /usr/local/share
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-i686.tar.bz2
tar xjvf phantomjs-2.1.1-linux-i686.tar.bz2


Make a symlink and point it to the package , then make symlink in /usr/local/bin to the binary in
/usr/local/share/phantomjs :


ln -s /usr/local/share/phantomjs-2.1.1 /usr/local/share/phantomjs

ln -s /usr/local/share/phantomjs/bin/phantomjs /usr/local/bin/phantomjs



The version of PhantomJS on your system can now be obtained via:


phantomjs --version


Installing CasperJS 

 cd  /usr/local/share

git clone git://github.com/n1k0/casperjs.git
cd casperjs
ln -s /usr/local/share/bin/casperjs /usr/local/bin/casperjs



The installed casperjs version can now be shown via:

casperjs --version

For more details see:
http://phantomjs.org/
http://casperjs.org/