I’ve been working with Hound library for headless browser testing in my Elixir project. Got the basic setup running with PhantomJS in remote WebDriver mode using phantomjs -w command. My config file has config :hound, driver: "phantomjs" set up and basic navigation works fine.
I’m stuck on two specific issues though:
First issue: Need to modify the User Agent string for requests. When I check the PhantomJS logs, I can see the default user agent in the page.settings:
[INFO] Session [abc123-def4-56gh-78ij-klmnop901234] - page.settings -
{"userAgent":"Mozilla/5.0 (Macintosh; PPC Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.7 Safari/534.34",
"javascriptEnabled":true,"loadImages":true}
How can I change this user agent string when using Hound? I know how to do it with direct PhantomJS CLI but not sure about the Hound approach.
Second issue: I need to configure HTTP proxy with authentication. Again, I can handle this with direct PhantomJS commands but can’t figure out where to set proxy settings when using Hound wrapper.
Anyone know the proper way to configure these settings?
I had the same issues with Hound capabilities. Skip the capabilities and use browser_options in your config instead: config :hound, driver: "phantomjs", browser_options: %{"phantomjs.page.settings.userAgent" => "your-custom-agent"}. For the proxy stuff, I created a wrapper script that starts PhantomJS with proxy settings first, then connects Hound to it. Also try the --load-images=no flag with your proxy settings to save bandwidth. Don’t forget to restart your app after config changes - Hound caches everything on startup.
For user agent modification, use additional_capabilities instead of desired_capabilities. In your config file, add config :hound, driver: "phantomjs", additional_capabilities: %{"phantomjs.page.settings.userAgent" => "Your Custom User Agent String"}. This worked reliably in my tests. For proxy authentication, PhantomJS through Hound has limited support for authenticated proxies. You’ll probably need to start PhantomJS manually with proxy parameters like phantomjs --proxy=proxy.server:port --proxy-auth=user:pass --wd and then configure Hound to connect to that instance using config :hound, driver: "phantomjs", host: "http://localhost", port: 8910. This gives you more control over PhantomJS startup options while still using Hound for browser automation.
have u checked the phantomjs capabilities? u can set them in the hound config using desired_capabilities. try something like config :hound, driver: "phantomjs", desired_capabilities: %{"phantomjs.page.settings.userAgent" => "custom ua"}. not too sure about proxy support tho. good luck!