2016-06-13 3 views
0

TL; DR- BraintreeのHosted Fieldsのiframe内のフィールドにアクセスするにはどうすればよいですか?Rails + Capybara + Braintree - BTのHosted Fieldsをテストする方法を教えてください。

Braintreeを通じて寄付を支払うUXの流れをテストしたいと思います。これは、これまでの私のコードです:

現在
require "rails_helper" 

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

    scenario "Public visitor creates a new donation" do 
    #load page 
    website = create(:website) 
    Capybara.current_session.driver.header 'Referer', website.website 
    visit "/donate?t=#{website.public_token}&frame=1" 
    #verify page 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']").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: '[email protected]' 

    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, email receipt 
    end 
end 

、それは私がBTののiframe内のフィールドにアクセスするにはどうすればよいCapybara::NotSupportedByDriverError: Capybara::Driver::Base#within_frame

を言って最初within_frameで壊すのか?

答えて

1

あなたはrack_testドライバを使用しているようですか?それはJSやフレームをサポートしていないので、ブレーントリはそれで動作しません。セレン、カピバラウェブキット、ポルターガイストなどの実際のブラウザドライバに切り替える必要があります。

+0

「シナリオ」パブリックビジターが新しい寄付を作成します。 '、js:true、driver::webkit do'は私が必要としているラインです。 – Mirror318

+0

@ Mirror318 Capybaraでのデフォルトのrspec設定では、js:trueとdriver::webkitの両方を必要としません。どちらか一方です。 'js:true'はCapybara.javascript_driverが設定されているドライバを使用し、' driver:xxx'はxxxドライバを使用します。 –

1

まあ、私はこの質問にはここではない正確な答えを書いていますが、むしろ修正を質問には、私は似たような状況にあったように、そのようなSelenium::WebDriver::Error::NoSuchFrameError: Unable to locate frame: #braintree-hosted-field-numberTest::Unit::Capybara::ElementNotFound: Unable to find field "#credit-card-number"と同様のエラーに直面していました。

within_frameは、次の形式(IDは、#-signの両方から除去されるべきである)を有するべきである:

within_frame('braintree-hosted-field-number') do 
    fill_in 'credit-card-number', :with => number 
end 

および試験にセレンドライバを使用するためには::ユニット、私は次のように使用ヘルパー:

def js 
    Capybara.current_driver = Capybara.javascript_driver 
    yield 
    Capybara.current_driver = Capybara.use_default_driver 
end 

そしてその中に私のテストラップ:

class SomeTest < ActionDispatch::IntegrationTest 
    test "should ..." do 
    js do 
     within_frame('braintree-hosted-field-number') do 
     fill_in 'credit-card-number', :with => number 
     end 
     # ... 
    end 
    end 

うまくいけば、Sをユニットテストを使用している間、オメオネは便利です。