Elixir and hound headless browser

Hound is pretty good for testing web applications, etc. when you need a browser without a browser. I got it working, playing around with tests, etc, but there are dog questions that maybe someone can explain who is familiar with Elixir :)

1.) I am using PhantomJSs remote WebDriver mode ( phantoms -w

on localhost). Ive set 'config: hound, driver: "phantomjs" in config.exs, so a simple "navigate_to @url" starts the PhantomJS instance and works correctly. Now I want to change the HTTP User Agent String for this request. PhantomJS provides a page.settings hash page. Executing the above query against a local PhantomJS in a remote WebDriver shows me the following settings:

[INFO  - 2014-08-24T21:54:00.232Z] Session [27b92460-2bd9-11e4-a77f-1daa5df28587] - 
page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,
"loadImages":true,"localToRemoteUrlAccessEnabled":false,
"userAgent":"Mozilla/5.0 (Macintosh; PPC Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.7 Safari/534.34","webSecurityEnabled":true}
[INFO  - 2014-08-24T21:54:00.232Z] Session [27b92460-2bd9-11e4-a77f-1daa5df28587] - page.customHeaders:  - {}
[INFO  - 2014-08-24T21:54:00.232Z] Session [27b92460-2bd9-11e4-a77f-1daa5df28587] - Session.negotiatedCapabilities -
{"browserName":"phantomjs","version":"1.9.7","driverName":"ghostdriver","driverVersion":"1.1.0",
"platform":"mac-unknown-64bit","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"}}

      

Question: how to change userAgent above? I haven't found any examples that deal with this. I know what it would look like to launch an instance of PhantomJS directly as a CLI tool with the appropriate JS configuration, but not sure how this controls this.

2.) I also need to use an authenticated HTTP proxy. Same as 1. I know how to deal with starting PhantomJS from the command line, but what place should I define for them to work on the hound?

+3


source to share


2 answers


You must pass the map as the Additional_capabilities parameter to any function that starts the session.

Hound.start_session(%{userAgent: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36"})

      

For the proxy parameter, the value must be a different map with properties.



Hound.start_session(%{proxy: %{property: "parameter", property: "parameter"}})

      

I've never used it with a proxy, so I'm not sure how to set it up correctly.

+1


source


I've spent quite some time trying to get this to work. The answer from cevado didn't work for me, but I was able to install the user agent by installing the following.

Hound.start_session(%{"phantomjs.page.settings.userAgent" => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36"})

      



Hope it helps.

+1


source







All Articles