【问题标题】:How to do persistent http basic authentication with Watir?如何使用 Watir 进行持久的 http 基本身份验证?
【发布时间】:2019-06-21 05:01:00
【问题描述】:

我在下面添加了我正在使用的完整代码。

require 'watir-webdriver'
b = Watir::Browser.start'http://user:password@siteaddress.com' 
b.driver.manage.window.maximize


Given /^I press "(.*)", with id "(.*)"$/ do |text, id|
  b.button(id: id, :text => text).when_present.fire_event :click
end

Then(/^checkbox validation$/) do
  b.link(data_search_text_english: 'Italy').click
end

Then(/^checkbox sailingxp$/) do
  b.link(data_search_text_english: 'comp').click
end

Then(/^check availability$/) do
  b.link(:href, "/vacation-options/bareboat-yacht-charter/destinations/mediterranean/italy/procida/availability").click
end

Then(/^check options and extras$/) do
  b.link(:class, "button lb-loading-spinner-booking-link lb_general_loading_spinner-processed").click
  sleep(8)

end

我面临的问题是,在浏览这些页面后,我再次看到用户名和密码弹出窗口,但这次是通过 https。无论如何我可以设置用户名和密码并忘记它吗?每当它点击需要身份验证的页面时,它就会自动登录。如果这不可能,有人可以告诉我如何在弹出窗口中输入用户名和密码并进行身份验证吗?

【问题讨论】:

    标签: ruby-on-rails ruby authentication watir


    【解决方案1】:

    我们只是为此使用http_basic_authenticate_with

    #app/controllers/application_controller.rb
    class ApplicationController < ActionController::Base
       http_basic_authenticate_with name: "dhh", password: "secret", except: :index
    end
    

    【讨论】:

    • 谢谢,我刚刚注意到,当它再次要求输入用户名和密码时,它是通过 https 的。第一次出现弹出窗口是在第一次导航到该站点时通过 http。
    • 你能解释一下吗?
    • 我在代码开头使用以下内容 require 'watir-webdriver' b = Watir::Browser.start 'admin:password@yourwebsite.com' 然后点击一些搜索结果并浏览一些页面。然后,当我单击将我带到网站预订流程的链接时,我会看到一个通过 https 而不是 http 进行身份验证的弹出窗口
    • 用完整代码更新了我的问题。希望有人能帮忙!
    猜你喜欢
    • 2015-09-07
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-27
    • 2012-10-21
    • 2015-08-12
    • 2017-05-25
    相关资源
    最近更新 更多