Skip to content

Instantly share code, notes, and snippets.

View n1k0's full-sized avatar
✏️
writing a github status

Nicolas Perriault n1k0

✏️
writing a github status
View GitHub Profile
@n1k0
n1k0 / location.js
Created July 4, 2012 08:46
PhantomJS test script for window.location
var page = require('webpage').create();
var base = phantom.args[0];
var path = phantom.args[1];
var expected = phantom.args[2];
page.onNavigationRequested = function(url, navigationType, navigationLocked, isMainFrame) {
console.log('Navigation requested: ' + navigationType + '; ' + url);
if (!page.testStarted) {
return;
}
@n1k0
n1k0 / casper.js
Created July 12, 2012 16:49 — forked from thom4parisot/casper.js
Bootstrap Dropdown CasperJS check.
casper.start('http://twitter.github.com/bootstrap/javascript.html#dropdowns', function() {
this.test.assertExists('#navbar-example');
this.click('#dropdowns .nav-pills .dropdown:last-of-type a.dropdown-toggle');
this.waitUntilVisible('#dropdowns .nav-pills .open', function() {
this.test.pass('Dropdown is open');
});
});
casper.run(function() {
this.test.done();
@n1k0
n1k0 / kw-positions.js
Created July 15, 2012 08:50
CasperJS script to retrieve keyword occurence positions within a given page
var casper = require('casper').create();
var positions = [];
var kw = 'JSON';
casper.start('http://phantomjs.org/', function() {
var pageHeight = this.evaluate(function() {
return document.body.scrollHeight;
});
if (pageHeight < 1) {
this.echo('no page height', 'ERROR').exit();
@n1k0
n1k0 / pre-commit.py
Created July 20, 2012 13:23 — forked from streeter/pre-commit.py
Python .git/hooks/pre-commit hook
#!/usr/bin/env python
import os
import re
import subprocess
import sys
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)')
CHECKS = [
$ casperjs t.js
[info] [phantom] Starting...
[info] [phantom] Setting HTTP authentication for user user
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: https://www.google.com, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.google.com/, type=Other, lock=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://www.google.fr/, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "https://www.google.fr/"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step 2/2 https://www.google.fr/ (HTTP 0)
@n1k0
n1k0 / pre-commit
Created September 17, 2012 08:56
Git pre-commit hook for checking your python project
#!/usr/bin/env python
import os
import re
import subprocess
import sys
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)')
CHECKS = [
@n1k0
n1k0 / Howto.md
Created October 1, 2012 17:59
CasperJS test cli hooks example

Put test1.js and test2.js into a tests/ directory, then run the suite:

$ casperjs test tests/ --pre=pre.js --includes=inc.js --post=post.js
Test file: /Users/nperriault/tmp/pre-inc/pre.js                                 
Hey, I'm executed before the suite.
Test file: /Users/nperriault/tmp/pre-inc/tests/test1.js                         
# this is test 1
Hi, I've been included.
PASS Subject is strictly true
@n1k0
n1k0 / proposition.eml
Created November 12, 2012 17:18
Proposition de conférence parisweb 2011 (archive email)
Bonjour,
Sans grand espoir d'être retenu faute d'avoir pu trouver le temps de
formuler plus finement le sujet, je prends tout de un moment pour vous
soumettre une idée de conférence sur une thématique qui me turlupine
depuis plus de 10 ans tant elle pleine d'enjeux et dure à cerner dans
nos métiers…
Le titre (provisoire, car relativement moisi) est "Quand, comment et
pourquoi faut-il savoir dire non ?" (oui, je sais, ça va)
@n1k0
n1k0 / log.xml
Created December 18, 2012 21:49
Sample JUnit XML (XUnit) test report logs for CasperJS test suite. See https://github.com/n1k0/casperjs/pull/329
<?xml version="1.0" encoding="UTF-8"?>
<testsuites duration="50.5">
<testsuite failures="0" name="Untitled suite in /Users/niko/Sites/casperjs/tests/suites/casper/agent.js" package="tests/suites/casper/agent" tests="3" time="0.256">
<testcase classname="tests/suites/casper/agent" name="Default user agent matches /CasperJS/" time="0.103"/>
<testcase classname="tests/suites/casper/agent" name="Default user agent matches /plop/" time="0.146"/>
<testcase classname="tests/suites/casper/agent" name="Default user agent matches /plop/" time="0.007"/>
</testsuite>
<testsuite failures="0" name="Untitled suite in /Users/niko/Sites/casperjs/tests/suites/casper/alert.js" package="tests/suites/casper/alert" tests="1" time="0.449">
<testcase classname="tests/suites/casper/alert" name="alert event has been intercepted" time="0.449"/>
</testsuite>
@n1k0
n1k0 / casperjs-link-checker.md
Last active August 5, 2016 04:58
A link checker using CasperJS