0

我正在尝试使用以下代码访问 Braintree 的托管字段:

within_frame('braintree-hosted-field-number') do
  fill_in 'Credit card number', with: '4111-1111-1111-1111'
end

inspect框架的名称是正确的,我从Chrome的面板中复制了它。但我得到这个错误

Capybara::Webkit::InvalidResponseError:
   Unable to locate frame.

我究竟做错了什么?或者,更重要的是,我该如何调试/查看发生了什么?


编辑

这是我的代码,按要求。请注意,如果我通过并手动填写字段并提交表单,整个系统工作正常。

= f.fields_for :user do |u|
    .control-group.col-24.payment-details
      label.half
        .field-title First Name
        = u.text_field :first_name
      label.half
        .field-title Last Name
        = u.text_field :last_name
      label.full
        .field-title Email for receipt
        = u.email_field :email
      label.full
        .field-title Credit card number
        .bt-field#credit-card
      label.half
        .field-title Expiry date
        .bt-field#exp-card
      label.half
        .field-title CVC
        .bt-field#cvv-card

script src="https://js.braintreegateway.com/js/braintree-2.24.0.min.js"

咖啡脚本

braintree.setup(clientToken, "custom", {
          id: "donate-form",
          onPaymentMethodReceived: (obj)->
            formdata = donationForm.getFormData()
            formdata.set "payment_method_nonce", obj.nonce
            donationForm.send(formdata)
          onError: (obj)->
            errors = []
            switch obj.type
              when "VALIDATION"
                errors.push "Invalid payment details. Please correct your payment details."
              else
                errors.push "Something went wrong. Please check your payment details and try again."
            donationForm.printErrors("donation-errors", errors)
          hostedFields: {
            styles: {
            "input": {
              "font-size": "14px",
              "font-weight": "bold",
              "font-family": "Lato, Helvetica, Arial, Geneva, sans-serif",
              "color": "#464646;",
              "transition": colorTransition,
              "-webkit-transition": colorTransition
              },
            ".invalid": { color: "#DD0000"} },
            number: {selector: "#credit-card"},
            cvv: {selector: "#cvv-card"},
            expirationDate: {selector: "#exp-card", "placeholder": "dd/mm"}
          }
        })

编辑 2

捐赠模块规格.rb

require "rails_helper"

RSpec.feature "Donation Module", type: :feature do

  scenario "Wrong public token" do
    visit "/donate?t=BAD_URL&frame=1"
    expect(page).to have_content("Are you sure you're installing this on the correct website?")
  end

  scenario "Public visitor creates a new donation", driver: :webkit do

    #load page
    website = create(:website)
    page.driver.header 'Referer', website.website
    visit "/donate?t=#{website.public_token}&frame=1"

    #verify page 1 loaded
    expect(page).not_to have_content("Are you sure you're installing this on the correct website?")

    #fill page 1
    find("input[value='20'] ~ div").click

    #go to page 2
    find("#credit-details").click

    #verify page 2 content is loaded
    expect(find(".total-cost-text")).to be_visible

    #fill page 2
    fill_in 'First Name', with: 'Leeroy'
    fill_in 'Last Name', with: 'Jenkins'
    fill_in 'Email for receipt', with: 'new_donor@email.com'

    sleep 5
    within_frame('braintree-hosted-field-number') do
      fill_in 'Credit card number', with: '4111-1111-1111-1111'
    end

    within_frame('#braintree-hosted-field-expirationDate') do
      fill_in '#expiration', with: '09/19'
    end

    within_frame('#braintree-hosted-field-cvv') do
      fill_in '#cvv', with: '123'
    end
    find('Make payment').click


    # expect to make a new user, new donation, new receipt, emailed receipt
  end
end

rails_helper.rb 修改为仅显示相关部分:

require 'capybara/rails'
require 'capybara/rspec'

Capybara::Webkit.configure do |config|
  config.allow_url("js.braintreegateway.com")
  config.allow_url("fonts.googleapis.com")
  config.allow_unknown_urls
  config.debug = true
end

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = false
4

1 回答 1

0

全面披露:我在布伦特里工作。如果您还有其他问题,请随时联系支持人员

对于为什么会发生这种情况,我没有答案,复制你的设置我就能让它工作。我确实有一些额外的想法可能会有所帮助。

1)查看调试输出(看起来您已经启用了此功能config.debug = true)并确保没有错误。这是我输出的相关部分 -

"Visit(http:/localhost:3000/hostedfields_payment)" started page load 
Started request to "http://localhost:3000/hostedfields_payment" 
Finished "Visit(http:/localhost:3000/hostedfields_payment)" with response "Success()" 
Started request to "https://js.braintreegateway.com/js/braintree-2.17.5.js" 
Started request to "https://api.sandbox.braintreegateway.com/merchants/-/client_api/v1/configuration?-
Received 200 from "https://api.sandbox.braintreegateway.com/merchants/-/client_api/v1/configuration?- 
Received "FrameFocus(braintree-hosted-field-number)" 
Load started 
Started request to "https://assets.braintreegateway.com/hosted-fields/2.17.5/hosted-fields-frame.html#91586a91-c55f-4e51-80e6-7cd750f9c750" 
Started request to "https://assets.braintreegateway.com/hosted-fields/2.17.5/hosted-fields-frame.html#91586a91-c55f-4e51-80e6-7cd750f9c750" 
Started request to "https://assets.braintreegateway.com/hosted-fields/2.17.5/hosted-fields-frame.html#91586a91-c55f-4e51-80e6-7cd750f9c750" 
"TimeoutCommand" waiting for load to finish  
Started request to "https://assets.braintreegateway.com/hosted-fields/2.17.5/braintree-hosted-fields-internal.min.js" 
Received 200 from "https://assets.braintreegateway.com/hosted-fields/2.17.5/hosted-fields-frame.html#91586a91-c55f-4e51-80e6-7cd750f9c750" 
Received 200 from "https://assets.braintreegateway.com/hosted-fields/2.17.5/hosted-fields-frame.html#91586a91-c55f-4e51-80e6-7cd750f9c750" 
Received 200 from "https://assets.braintreegateway.com/hosted-fields/2.17.5/hosted-fields-frame.html#91586a91-c55f-4e51-80e6-7cd750f9c750" 
Received 200 from "https://assets.braintreegateway.com/hosted-fields/2.17.5/braintree-hosted-fields-internal.min.js" 
Page finished with true 
Load finished 
Started "FrameFocus(braintree-hosted-field-number)"
Finished "FrameFocus(braintree-hosted-field-number)" with response "Success()" 
Wrote response true "" 
Received "FindCss(input#credit-card-number)" 
Started "FindCss(input#credit-card-number)" 
Finished "FindCss(input#credit-card-number)" with response "Success()" 

2)你可以检查的一个粗糙的方法是在你的末尾sleep 5,将正文打印到一个文件并打开它。您可以检查 iframe 是否存在。

File.open("looking_for_iframes.html", "w") do |file|
  file.print(page.body)
end

否则,请随时联系 Braintree 支持

于 2016-06-21T15:17:56.643 回答