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

8
  • May be related: SPNEGO authentication in Phantom Commented Oct 1, 2014 at 9:17
  • Are you allowing Basic Auth with windows Auth ?system.webServer/security/authentication/basicAuthentication Commented Oct 1, 2014 at 16:19
  • is curl working fine by using : CURL http://testsite -u username:password ? Commented Oct 2, 2014 at 11:28
  • 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 Commented Oct 8, 2014 at 13:57
  • 1
    @itslittlejohn you can use 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 github.com/tjanczuk/iisnode Commented Sep 1, 2015 at 5:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.