【问题标题】:Redirect to custom protocol/scheme is not accessible when using headless watir/firefox使用无头 watir/firefox 时无法访问重定向到自定义协议/方案
【发布时间】:2019-04-05 14:07:00
【问题描述】:

我正在为 Dropbox oauth 序列进行一组集成测试,该序列以一系列 302 重定向完成,其中最后一个是自定义协议/方案。在测试模仿的移动应用程序中,一切都按预期工作,而在集成测试中,一切都正常。

测试环境在 ubuntu 服务器上运行(无 GUI),使用 xvfb 无头。

客观地说,我实际上并不需要遵循自定义协议 URI,我只需要访问 URI 以确认内容符合预期。 我已经尝试了所有我能想到的从 watir/selenium 中访问包含自定义方案的 URI,但我能找到的所有参考资料都说底层细节是故意隐藏的。

我还尝试了所有我能找到的在 firefox 配置文件中创建自定义协议处理程序的选项,但无论如何都不会调用脚本。

watir/selenium 日志中没有留下任何有用的信息。

有什么想法吗?

自定义协议处理程序 sn-p:

# 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

【问题讨论】:

    标签: ruby firefox watir headless xvfb


    【解决方案1】:

    在研究了很久之后,事实证明,大多数在 mozilla 网站和论坛上添加自定义方案的文档都已被弃用,并且没有新的东西可以替代它。咕噜。

    通过反复试验,我发现 webdriver 使用的模型配置文件不需要完整,任何缺少的东西都会从默认配置文件中提取。所以只需要一个包含自定义方案的 handlers.json 文件,仅此而已。

    要演示的片段:

    # 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
    

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 1970-01-01
      • 2020-02-09
      • 2018-05-25
      • 1970-01-01
      • 2017-04-25
      • 1970-01-01
      • 2017-06-06
      • 2011-02-22
      相关资源
      最近更新 更多