I’m working on a set of integration tests for the dropbox oauth sequence which finishes in a series of 302 redirects, the last of which is a custom protocol/scheme. Everything works as expected in the mobile app which the testing mimics, and everything bar this works in the integration tests.
The testing environment runs on ubuntu server (no GUI) and is headless using xvfb.
Objectively, I don’t actually need the custom protocol URI to be followed, I just need to get access to the URI to confirm the contents match expectations. I have tried everything I can think of to access the URI containing the custom scheme from within watir/selenium, but all the references I can find say that the underlying detail is deliberately hidden by design.
I have also tried all the options I can find for creating a custom protocol handler within the firefox profile, but no matter what happens the script isn’t called.
Nothing useful is being left in the watir/selenium logs.
Any thoughts?
Custom protocol handler snippet:
# initialise headless
headless = Headless.new( reuse: false )
headless.start
# initialise profile
profile = Selenium::WebDriver::Firefox::Profile.new
profile[ 'general.useragent.override' ] = 'agent'
profile[ 'network.protocol-handler.app.biscuit' ] = '/usr/bin/biscuit'
profile[ 'network.protocol-handler.external.biscuit' ] = true
profile[ 'network.protocol-handler.expose.biscuit' ] = true
profile[ 'network.protocol-handler.warn-external.biscuit' ] = false
# initialise client
client = Selenium::WebDriver::Remote::Http::Persistent.new
# initialise browser
browser = Watir::Browser.new :firefox, profile: profile, accept_insecure_certs: true, http_client: client
# run dropbox authentication cycle
# cleanup
browser.close
headless.destroy
After chasing this around for ages, it turns out that most of the documentation for adding custom schemes on the mozilla site and forums is deprecated and there’s nothing new to replace it. Grrr.
Through a process of trial and error, I found that the model profile used by the webdriver does not need to be complete, and anything that is missing it’ll pull from the default profile. So all that is required is a handlers.json file containing the custom scheme/s and no more.
Snippet to demonstrate:
# create a temporary model profile
profilePath = '/tmp/modelProfile'
FileUtils.mkpath profilePath
File.chmod( 0700, profilePath )
FileUtils.chown 0, 0, profilePath
open( profilePath + '/handlers.json', 'w' ) { |file| file.write '{ "defaultHandlersVersion": { "en-US": 4 }, "schemes": { "biscuit": { "action": 2, "handlers": [ { "name": "biscuit", "uriTemplate": "https://www.biscuit.me?url=%s" } ] } } }' }
# create profile
profile = Selenium::WebDriver::Firefox::Profile.new( '/tmp/modelProfile' )
# initialise browser
browser = Watir::Browser.new :firefox, profile: profile, accept_insecure_certs: true