0

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

Community
  • 1
  • 1
TechnicalSmile
  • 1,387
  • 5
  • 16
  • 30
  • May be related: [SPNEGO authentication in Phantom](http://stackoverflow.com/questions/24761138/spnego-authentication-in-phantom) – Artjom B. Oct 01 '14 at 09:17
  • Are you allowing Basic Auth with windows Auth ?system.webServer/security/authentication/basicAuthentication – Ammaroff Oct 01 '14 at 16:19
  • is curl working fine by using : CURL [http://testsite](http://testsite) -u username:password ? – Ammaroff Oct 02 '14 at 11:28
  • @Ammaroff basic authentication is disabled on my site and I don't have CURL installed on my server. – TechnicalSmile Oct 07 '14 at 09:18
  • 3
    I think phantomjs does not support ntlm auth. you can build an aspx page that used as proxy then use phantom to visit this page – Ammaroff Oct 08 '14 at 13:57
  • this question looks similar to http://stackoverflow.com/questions/20080933/windows-authentication-using-phantomjs – chiccodoro Dec 03 '14 at 15:24
  • @Ammaroff Do you know of a strategy to proxy an entire application without having to create separate aspx pages for each page? I've been trying to think of ways to proxy ntlm auth in my IIS application and haven't had any success to date (couldn't get cntlm to work). – itslittlejohn Aug 31 '15 at 18:18
  • 1
    @itslittlejohn you can use https://www.npmjs.com/package/httpntlm as proxy for the whole application. but this will work only as nodejs server. you can host it on IIS using https://github.com/tjanczuk/iisnode – Ammaroff Sep 01 '15 at 05:29

0 Answers0