Loading...
 
Starting in Tiki18, PhantomJS and CasperJS will be available via the new Composer Web Installer


PhantomJS and CasperJS

Tested in Tiki17 and Tiki16, but will likely work on previous versions. This is for advanced users for now. In the future, it will be easier to install, and it will be possible to write recipes in wiki pages. See Browser Automation.



CasperJS is a navigation scripting & testing utility for PhantomJS and SlimerJS (still experimental). It eases the process of defining a full navigation scenario and provides useful high-level functions, methods & syntactic sugar for doing common tasks such as:

defining & ordering navigation steps
filling forms
clicking links
capturing screenshots of a page (or an area)
making assertions on remote DOM
logging & events
downloading resources, even binary ones
catching errors and react accordingly
writing functional test suites, exporting results as JUnit XML (xUnit)

PhantomJS is a headless WebKit with JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

PhantomJS is an optimal solution for fast headless testing, site scraping, pages capture, SVG renderer, network monitoring and many other use cases.



How to install CasperJS and PhantomJS for Tiki


1. Edit composer.json


Add, in the composer.json, the following lines to "post-install-cmd" and "post-update-cmd" of the "scripts" section:

"PhantomInstaller\\Installer::installPhantomJS",
"CasperJsInstaller\\Installer::install"


2. Install missing programs


Install composer (if missing) and the following PHP packages (by running these commands on the command line):

sudo apt-get install composer # or adapt to your distro/OS: "yum install composer", etc
composer require --prefer-dist "jerome-breton/casperjs-installer:dev-master"
composer require --prefer-dist "phpcasperjs/phpcasperjs"


3. Run setup.sh

Now you can run sh setup.sh in the tiki root folder, as usual, to run the installers of phantomjs and casperjs, and remove the unneeded dev packages added by composer.

sh setup.sh


4. Test the installation


Use the following script to test (in the root of tiki, adjust path if other folder):

Create a file (ex.: scrape.php) with the following content
<?php
// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';

use Browser\Casper;

$casper = new Casper(__DIR__ . '/bin/');
$casper->setOptions(array(
  'ignore-ssl-errors' => 'yes'
));

// screen shoot of homepage
$casper
  ->start('http://tiki.org')
  ->setViewPort(1024,800)
  ->waitForText('About Tiki')
  ->wait(200)
  ->capture(
    array(
      'top' => 0,
      'left' => 0,
      'width' => 1024,
      'height' => 800
    ),
    'custom-capture.png'
  )
  ->run();

echo "The image was captured 
<br>
<br>
<img alt='' border='0' src='custom-capture.png'>";


Once you visit the newly created file, it will fetch the info at http://tiki.org and generate custom-capture.png

5. Expose them system-wide (optional)

In case you need to run some custom programs on a server which require casperjs and phantomjs, you may expose those programs to the whole server so that they can get accessed system wide from the usual /usr/bin folder where all programs are located on symlinked.

Imagine that your root tiki folder is /var/www/html/. Then you can create a symbolic link for each of the programs:
ln -s /var/www/html/bin/casperjs /usr/bin/casperjs
ln -s /var/www/html/bin/phantomjs /usr/bin/phantomjs


This way you will be able to call casperjs or phantomjs from anywere in the server, if you need it for your other custom scripts doing scraping for you sever-side.

Troubleshooting

If you get the following error, just stop the script and try again later
> Tiki\Composer\BootstrapCompiler::build
> Tiki\Composer\CleanVendors::clean
> PhantomInstaller\Installer::installPhantomJS
  - Installing phantomjs (1.9.8)
    Downloading: Connecting...
Could not fetch https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2, please create a bitbucket OAuth token to to go over the API rate limit
Follow the instructions on https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html
to create a consumer. It will be stored in "/root/.composer/auth.json" for future use by Composer.
Ensure you enter a "Callback URL" or it will not be possible to create an Access Token (this callback url will not be used by composer)
Consumer Key (hidden):



To test, and check version
[root@ ~]# phantomjs -v
1.9.8




Open Hub







alias

doc.tiki.org


Bootstrap

AdminGuide

UserGuide

Keywords

Keywords serve as "hubs" for navigation within the Tiki documentation. They correspond to development keywords (bug reports and feature requests):

Accessibility (WAI and 508)
Accounting (7.x)
Articles and Submissions
Backlinks
Banners
Batch (6.x)
BigBlueButton audio/video/chat/screensharing (5.x)
Blog
Bookmark
Browser Compatibility
Link Cache
Calendar
Category
Chat
Clean URLs
Comments
Communication Center
Compression (gzip)
Contacts (Address Book)
Contact us
Content Templates
Contribution (2.x)
Cookie
Copyright
Credit (6.x)
Custom Home and Group Home Page
Date and Time
Debugger Console
Directory of hyperlinks
Documentation link from Tiki to doc.tiki.org (Help System)
Docs 8.x
Draw 7.x
Dynamic Content
Dynamic Variable
External Authentication
FAQ
Featured links
File Gallery
Forum
Friendship Network (Community)
Gmap Google maps
Groups
Hotword
HTML Page
i18n (Multilingual, l10n, Babelfish)
Image Gallery
Import-Export
Install
Integrator
Interoperability
Inter-User Messages
InterTiki
Kaltura video management (4.x)
Karma
Live Support
Login
Logs (system & action)
Look and Feel
Lost edit protection
Mail-in
Map with Mapserver
Menu
Meta Tags
Mobile Tiki and Voice Tiki
Mods
Module
MultiTiki
MyTiki
Newsletter
Notepad
Payment
Performance Speed / Load
Permissions
Platform independence (Linux-Apache, Windows/IIS, Mac, BSD)
Polls
Profiles
Profile Manager
Report
Toolbar
Quiz
Rating
Feeds
Score
Search engine optimization
Search
Search and Replace
Security
Semantic links (3.x)
Shadowbox
Shadow Layers
Share
Shopping cart
Shoutbox
Slideshow
Smiley
Social Networks
Spam protection (Anti-bot CATPCHA)
Spellcheck
Spreadsheet
Stats
Surveys
Tags (2.x)
Task
Tell a Friend, alert + Social Bookmarking
TikiTests (2.x)
Theme CSS & Smarty
Trackers
Transitions (5.x)
TRIM
User Administration including registration and banning
User Files
User Menu
Watch
WebHelp
WebDAV (5.x)
Webmail
Web Services
Wiki 3D
Wiki History, page rename, etc
Wiki Page Staging and Approval (2.x)
Wiki Plugin extends basic syntax
Wiki Syntax
Wiki structure (book and table of content)
Workspace
WSOD
WYSIWYCA
WYSIWYG (2.x)
XMLRPC


Tiki Newsletter

Delivered fresh to your email inbox!
Newsletter subscribe icon
Don't miss major announcements and other news!
Contribute to Tiki
Show php error messages