Last active
December 16, 2015 00:19
-
-
Save abbood/5347252 to your computer and use it in GitHub Desktop.
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
var page = new WebPage(), testindex = 0, loadInProgress = false; | |
page.onConsoleMessage = function(msg) { | |
console.log(msg); | |
}; | |
page.onLoadStarted = function() { | |
loadInProgress = true; | |
console.log("load started"); | |
}; | |
page.onLoadFinished = function() { | |
loadInProgress = false; | |
console.log("load finished"); | |
}; | |
var steps = [ | |
function() { | |
//Load Login Page | |
page.open("https://site/login.html"); | |
}, | |
function() { | |
//Enter Credentials | |
page.evaluate(function() { | |
var inputElements = document.getElementsByTagName("input"); | |
inputElements["login"].value = "login"; | |
inputElements["passwd"].value = "pwd"; | |
}); | |
}, | |
function() { | |
//Login | |
page.evaluate(function() { | |
//assuming there is only one form in the page | |
//if not, just iterate through them and pick | |
//the one matching a specific attribute | |
var loginForm = document.getElementsByTagName("form")[0]; | |
loginForm.submit(); | |
}); | |
}, | |
function() { | |
// enter search criteria | |
page.evaluate(function() { | |
var inputElements = document.getElementsByTagName("input"); | |
inputElements['field'].value = "software engineer"; // search value | |
}); | |
}, | |
function() { | |
// perform search | |
page.evaluate(function() { | |
//assuming there is only one form in the page | |
//if not, just iterate through them and pick | |
//the one matching a specific attribute | |
var searchForm = document.getElementsByTagName("form")[0]; | |
searchForm.submit(); | |
}); | |
}, | |
function() { | |
// Output content of page to stdout after form has been submitted | |
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() { | |
console.log("this is results table: "+jQuery('#resultsTable').length); | |
console.log(document.querySelectorAll('html')[0].outerHTML); | |
}); | |
} | |
]; | |
interval = setInterval(function() { | |
if (!loadInProgress && typeof steps[testindex] == "function") { | |
console.log("step " + (testindex + 1)); | |
steps[testindex](); | |
testindex++; | |
} | |
if (typeof steps[testindex] != "function") { | |
console.log("test complete!"); | |
phantom.exit(); | |
} | |
}, 50); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this demonstrates how the session persists within the same phantomjs page