0

I'm using phantomJS driver to automate some tests. On the home page if I get a webElement and output the href I can copy it to a browser and the page opens but in the test when I do driver.get(loginLink.getAttribute("href")) it just stays on the same page.

It works fine on the live site but not on our internal staging site.

I've added caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

but I still can't open the login page. Please can anybody suggest what can be causing this?

Update: More testing I've found it's only https pages that wont load

Doctor Who
  • 1,287
  • 5
  • 25
  • 46
  • driver.get(loginLink.getAttribute("href")) , you mean it should redirect you to on another page? – Helping Hands Dec 02 '15 at 10:20
  • Yes. I'm outputting loginLink.getAttribute("href") and if I copy the output into a browser it works fine but the driver.get is just staying on the home page. I'm guessing it's something to do with security because it works fine on the live site – Doctor Who Dec 02 '15 at 10:25
  • did you try to fine exact issue by putting try/catch? – Helping Hands Dec 02 '15 at 10:29
  • When I do driver.get I take a screenshot and it's just black I then try to access an element which throws an error because the element isn't found. No error is thrown from the actual driver.get – Doctor Who Dec 02 '15 at 10:31
  • Ok I've found it's only https pages that are not loading through the driver – Doctor Who Dec 02 '15 at 10:40
  • 1
    @user2239784 Please, see this answer: http://stackoverflow.com/a/26604617/2715393 – Vaviloff Dec 02 '15 at 10:44
  • Thank you! I had already seen that answer but stupid me was setting PHANTOMJS_CLI_ARGS 3 times instead of all in one so I was obviously clearing whichever one fixed the problem. – Doctor Who Dec 02 '15 at 10:59

1 Answers1

0

phantomjs defaults to SSL 3.0 when using https. Since SSL 3.0 is disabled on lots of hosts because it is insecure, the SSL handshake will fail. Use phantomjs --ignore-ssl-errors=true, --web-security=false, --ssl-protocol=any to make phantomjs use a more modern version (TLS1.0 or higher).

phantomJS uses different mechanism in setting capabilities

static ArrayList<String> cliArgsCap = new ArrayList<String>();
capabilities = DesiredCapabilities.phantomjs();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
capabilities.setCapability("takesScreenshot", true);
capabilities.setCapability(
    PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
capabilities.setCapability(
    PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS,
        new String[] { "--logLevel=2" });
this.driver = new PhantomJSDriver(capabilities);

Hope it will help :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125