简体   繁体   English

使用无头 watir/firefox 时无法访问重定向到自定义协议/方案

[英]Redirect to custom protocol/scheme is not accessible when using headless watir/firefox

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.我正在为 dropbox oauth 序列进行一组集成测试,该序列在一系列 302 重定向中完成,最后一个是自定义协议/方案。 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.测试环境在 ubuntu 服务器(无 GUI)上运行,并且使用 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.客观地说,我实际上并不需要遵循自定义协议 URI,我只需要访问 URI 以确认内容符合预期。 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.我已经尝试了所有我能想到的方法来从 watir/selenium 中访问包含自定义方案的 URI,但我能找到的所有参考资料都表明,底层细节被设计故意隐藏了。

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.我还尝试了所有可以找到的选项,用于在 firefox 配置文件中创建自定义协议处理程序,但无论发生什么情况,都不会调用脚本。

Nothing useful is being left in the watir/selenium logs. watir/selenium 日志中没有任何有用的东西。

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.经过多年的追寻,事实证明,大多数用于在 mozilla 站点和论坛上添加自定义方案的文档已被弃用,并且没有任何新内容可以替代它。 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.通过反复试验,我发现 webdriver 使用的模型配置文件不需要完整,任何缺少的东西都会从默认配置文件中提取。 So all that is required is a handlers.json file containing the custom scheme/s and no more.所以所需要的只是一个包含自定义方案的 handlers.json 文件,仅此而已。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM