I’ve been working with Hound library for headless browser testing in my Elixir project. It’s working great for basic web automation tasks, but I’m stuck on two configuration issues.
First problem: I need to modify the User Agent string when using PhantomJS in WebDriver mode. Currently running phantomjs --webdriver=8910 locally and configured Hound with config :hound, driver: "phantomjs" in my config file. Basic navigation works fine, but I can’t figure out how to customize the User Agent header.
# Current setup
defmodule MyTest do
use ExUnit.Case
use Hound.Helpers
test "visit homepage" do
navigate_to "http://example.com"
# Need custom User Agent here
end
end
Second issue: I also need to configure HTTP proxy settings with authentication. I know how to do this with standalone PhantomJS using command line arguments, but not sure where to set these options when working through Hound.
Has anyone dealt with these configuration challenges? What’s the proper way to pass these settings to the WebDriver session?
you can set the user agent in hound using desired capabilities. add this to your config: config :hound, additional_capabilities: %{"phantomjs.page.settings.userAgent" => "your custom ua string"}. as for the proxy with auth, it’s easier to start phantomjs manually with the --proxy args instead of using hound.
For the User Agent issue, configure it directly at the driver level instead of relying on Hound’s settings. When you start PhantomJS, set capabilities with these parameters: --load-images=no --disk-cache=false --web-security=false --ssl-protocol=any --ignore-ssl-errors=true --webdriver=8910. In your test module, create a desired capabilities object that includes the right phantomjs.page.settings properties. For proxy authentication, environment variables work better than configuring through Hound. Store your proxy credentials in environment variables and reference them when launching PhantomJS. Just heads up - PhantomJS isn’t maintained anymore, so you might want to switch to ChromeDriver for better proxy authentication support.
Had the same headaches migrating from Selenium to Hound last year. For the User Agent issue, don’t use global config - set it in your test setup instead. Use Hound.start_session(additional_capabilities: %{"phantomjs.page.settings.userAgent" => "Mozilla/5.0 (compatible; MyBot/1.0)"}) before you navigate. Way more control per session. The proxy auth thing is trickier - PhantomJS has crappy proxy auth support through WebDriver. I ended up using SSH port forwarding or setting up a local proxy without auth that forwards to the authenticated one. PhantomJS proxy options just don’t mesh well with how Hound handles sessions.