Created
January 3, 2014 20:21
-
-
Save jimkang/8245790 to your computer and use it in GitHub Desktop.
A really basic Phantom.js test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Run with phantomjs test.js http://whatever.com | |
| // var chai = require('./node_modules/chai/index.js'); | |
| var page = require('webpage').create(); | |
| var system = require('system'); | |
| if (system.args.length === 1) { | |
| console.log('Usage: test.js <some URL>'); | |
| phantom.exit(); | |
| } | |
| var assert = function assert(condition, message) { | |
| if (!condition) { | |
| console.log('Assertion failed:', message); | |
| } | |
| }; | |
| var t = Date.now(); | |
| var address = system.args[1]; | |
| page.open(address, function onPageOpened(status) { | |
| if (status !== 'success') { | |
| console.log('FAIL to load the address'); | |
| } | |
| else { | |
| t = Date.now() - t; | |
| console.log('Loading time ' + t + ' msec'); | |
| frontPageSuite(page); | |
| } | |
| phantom.exit(); | |
| }); | |
| function frontPageSuite(page) { | |
| var loginLink = page.evaluate(function findLoginLink() { | |
| return document.querySelector('a[href="/something/login"]'); | |
| }); | |
| assert(loginLink, 'Login link exists.'); | |
| page.onLoadFinished = function(status){ | |
| console.log('hey'); | |
| } | |
| page.sendEvent('click', loginLink.offsetLeft + 20, loginLink.offsetTop + 20); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment