Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhantomJS cannot visit Self-signed HTTPS pages Codeception

Im currently making an acceptance test with the following tools:

  • Codeception
  • Selenium Webdriver
  • PhantomJS (as headless browser ghost)

My problem is My Tests fail when visiting a self-signed (https) page

What I've tried:

  1. phantomjs --webdriver=5555 --ignore-ssl-errors=true --ssl-protocol=any
  2. Adding this in capabilities phantomjs.cli.args: ["--ignore-ssl-errors=true"] in my acceptance.suit.yml

So far these options doesnt give me any luck.

Here is my acceptance.suit.yml file

class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver
    config:
        WebDriver:
            url: https://myproject.com
            browser: firefox
            capabilities:
                unexpectedAlertBehaviour: 'accept'

env:
    phantom:
        modules:
            enabled:
                - WebDriver
            config:
                WebDriver:
                    url: https://myproject.com
                    http_proxy: 192.1.1.1
                    http_proxy_port: 3000
                    browser: phantomjs
                    capabilities:
                        phantomjs.cli.args: ["--ignore-ssl-errors=true"]

UPDATE

This error shows up [ModuleException] WebDriver: Current url is blank, no page was opened

I don't know why this error happens since I've indicated a page. Here is a sample of my test

public function tryToTestThis(AcceptanceTester $I)
{
    $I->wantTo('Test this function');
    $I->amOnPage('/mypage/');
    $I->see('This text');
}

An answer in Codeception would be preferable. Thanks

like image 529
Þaw Avatar asked Mar 08 '16 09:03

Þaw


Video Answer


1 Answers

We figured out the cause if this problem. It was because I was running Selenium and phantomJS at the same time. (I got this idea from some tutorial.)

I was doing

java -jar selenium.jar

then I do this since it causes an error running phantomjs at port 4444 (Obviously selenium is using it) I use port 5555 instead.

phantomjs --webdriver=5555 --ignore-ssl-errors=true --ssl-protocol=any

Note: Everything works fine if not involved with https / ssl self-signed pages.

We think that codeception prioritize port 4444 and disregarding any option indicated in my phantomjs i.e. --ignore-ssl-errors=true --ssl-protocol=any thats why in fails to visit https/self-signed pages.

So basically, the fix was just running phantomjs alone without selenium.

phantomjs --webdriver=4444 --ignore-ssl-errors=true --ssl-protocol=any

Thank you

like image 192
Þaw Avatar answered Nov 15 '22 06:11

Þaw