Watir PhantomJS driver optional argument for ignoring SSL errors?

2.1k Views Asked by At

Good day all,

I'm working on automating some Ruby scripts to make them headless. My initial approach was to try Watir and its PhantomJS module. Our local test environment uses a self-signed certificate that I know some browser will error out on. I know that PhantomJS has a ignoreSSLerrors option but don't know how to specify that the PhantomJS driver should use it. I can create a headless browser phantom-js session without any problem but when I try to navigate to the webpage using the self-signed certificate, I get nothing - no errors, no text, no indication of why my page wasn't loaded.

Basically, this is what happens (the odysseyURL was defined elsewhere as a string URL that Firefox can load without a problem):

irb(main):035:0* driver = Watir::Browser.new :phantomjs
PhantomJS is launching GhostDriver...
[INFO  - 2013-12-05T15:48:49.998Z] GhostDriver - Main - running on port 8910
[INFO  - 2013-12-05T15:48:50.219Z] Session [bc1bd280-5dc4-11e3-8b99-7bac3d2f1d15]
 -_decorateNewWindow - page.settings{"XSSAuditingEnabled":false,
"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"
javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,
"userAgent":"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.34 (KHTML, like 
Gecko) PhantomJS/1.9.2 Safari/534.34","webSecurityEnabled":true}
[INFO  - 2013-12-05T15:48:50.252Z] Session [bc1bd280-5dc4-11e3-8b99-7bac3d2f1d15]
- page.customHeaders:  - {}
[INFO  - 2013-12-05T15:48:50.262Z] Session [bc1bd280-5dc4-11e3-8b99-7bac3d2f1d15]
- CONSTRUCTOR - Desired Capabilities:{"browserName":"phantomjs","version":"",
"platform":"ANY","javascriptEnabled":true,"cssSelectorsEnabled":true,
"takesScreenshot":true,"nativeEvents":false,"rotatable":false}
[INFO  - 2013-12-05T15:48:50.283Z] Session [bc1bd280-5dc4-11e3-8b99-7bac3d2f1d15]
- CONSTRUCTOR - Negotiated Capabilities: {"browserName":"phantomjs","version":
"1.9.2","driverName":"ghostdriver","driverVersion":"1.0.4","platform":
"windows-8-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":
false,"databaseEnabled":false,"locationContextEnabled":false,
"applicationCacheEnabled":false,"browserConnectionEnabled":false,
"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,
"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO  - 2013-12-05T15:48:50.327Z] SessionManagerReqHand -
_postNewSessionCommand - New Session Created: bc1bd280-5dc4-11e3-8b99-7bac3d2f1d15
=> #<Watir::Browser:0x73fac05c url="about:blank" title="">
irb(main):036:0>
irb(main):037:0* =begin
<en processed and works headless.  Everything below is still being modified
irb(main):039:0= =end
irb(main):040:0*
irb(main):041:0* driver.goto(odysseyURL)
=> "about:blank"
irb(main):042:0> puts(driver.text)

=> nil
irb(main):043:0> puts(driver.html)
<html><head></head><body></body></html>
=> nil

I've searched and researched both Watir and Ghostdriver for documentation on anything like this but have found very little and nothing that could help me.

Any assistance will be appreciated, mpozos

1

There are 1 best solutions below

2
On

I'm facing same problem through launching watir / phantomjs on https page, with same result

<html><head></head><body></body></html>

So I tried with mechanize to bypass it, but I was facing another problem ..

It was due to ssl certificate. I solve it adding ssl version and 'do not take account of ssl error' in the new instance .. But I still need to solve the main watir problem..

I've found following informations that I will test tonight..

first one, include more informations when launching phantomjs :

switches = ['--proxy=69.106.88.7:60199', '--proxy-auth=username:password123']
browser = Watir::Browser.new :phantomjs, :args => switches

second, phantomjs usage :

Usage: phantomjs [options] script.[js|coffee] [script argument [script argument ...]]
Options:
    --load-images=[yes|no]             Load all inlined images (default is 'yes').
    --load-plugins=[yes|no]            Load all plugins (i.e. 'Flash', 'Silverlight', ...)  (default is 'no').
    --proxy=address:port               Set the network proxy.
    --disk-cache=[yes|no]              Enable disk cache (at desktop services cache storage location, default is 'no').
    --ignore-ssl-errors=[yes|no]       Ignore SSL errors (i.e. expired or self-signed certificate errors).

so I think to test that solution :

switches = ['--ignore-ssl-errors=yes']
browser = Watir::Browser.new :phantomjs, :args => switches

I will publish results then

edit : I didn't succes with this solution .. I go watir headless directly .. hope this help