I am trying to use phantomjs for UI test automation in my project. Project has windows authentication implemented and that doesn't seems to be working for me while accessing pages through phantom console.
Below is simple code that I am trying to run:
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open('http://testSite/myPage.aspx', function(status) {
if (status !== 'success') {
console.log('could not retrieve!');
} else {
console.log('done!');
page.evaluate(function(){
console.log(document.title);
var item = document.getElementById("myDiv");
if(item) {
console.log('Item found!');
} else {
console.log('I wanna cry loud!');
}
});
}
phantom.exit();
});
I tried passing credentials using below methods:
Method 1: page.customHeaders={'Authorization': 'Basic '+ btoa('username:password')};
Method 2: page.settings.userName = 'username'; page.settings.password = 'password';
Method 3: steps suggested by albertein in this answer
Method 4: Passing credentials along with URL, like
page.open("http://username:password@testSite/myPage.aspx", function(status) {
if (status !== 'success') {
console.log('could not retrieve!');
} else {
While using method 4, where I passed credentials along with URL, status returned by page.open is "success". But still I can't access DOM in it. Also it seems success status is returned if I pass false credentials.
Please suggest what I am doing wrong or if this is plain impossible.
Thanks, Ravi