announce knysa: write phantomjs scripts in "sync" style, i.e. without callbacks

46 views
Skip to first unread message

Bo Zou

unread,
Jun 12, 2016, 6:11:39 PM6/12/16
to phantomjs
https://github.com/pahakia/knysa

download PDF from some web page can be done as follows:

kflow.knysa_open(url);
numPdfs = kflow.evaluate(function() {...});  // sandbox function
for (ix = 0; ix < numPdfs; ix++) {
   kflow.click(selector);
   kflow.sleep(5000); // sleep 5 seconds
   kflow.download(dir + '/' + filename_prefix + ix);
}

there is no callback!

Message has been deleted

Bo Zou

unread,
Jun 15, 2016, 9:50:32 AM6/15/16
to phantomjs
https://github.com/pahakia/knysa

compare knysa to casperjs:

casperjs script taken from http://docs.casperjs.org/en/latest/quickstart.html:

casper.start('http://google.fr/', function() {
    this.fill('form[action="/search"]', { q: 'casperjs' }, true);
});

casper.then(function() {
    links = this.evaluate(getLinks);
    this.fill('form[action="/search"]', { q: 'phantomjs' }, true);
});

casper.then(function() {
    links = links.concat(this.evaluate(getLinks));
});


knysa version:

kflow.knysa_open('http://google.fr/');
kflow.knysa_fill('form[action="/search"]', { q: 'casperjs' });
links = kflow.evaluate(getLinks);
kflow.knysa_fill('form[action="/search"]', { q: 'phantomjs' });
links = links.concat(kflow.evaluate(getLinks));

Bo Zou

unread,
Jul 22, 2016, 1:06:00 PM7/22/16
to phantomjs
https://www.infoq.com/articles/knysa-phantomjs-async-await

Intro to knysa: Async-Await Style PhantomJS Scripting

by Bo Zou on  Jul 21, 2016


Typical PhantomJS test frameworks suffer from callback hell and other tricks that reduce the clarity of how the program flows. Bo Zou created knysa which uses async-await style programming to eliminate these callbacks. Additionally, there's no need to resort to currying and common try-catch-fail constructs are used to maintain a sane path through the code.

Reply all
Reply to author
Forward
0 new messages