2017-03-29 14 views
0

私はcucumber/capybara/site_prismのさまざまなログイン資格情報で多くのテストを行っていますが、これはかなり面倒です。私は可能な限り統一したい。このソリューションは、https://blog.jayway.com/2012/04/03/cucumber-data-driven-testing-tips/キュウリ/カピバラを使ったハッシュデータの保存と抽出

素敵なように見えた。しかし、私は、私はハッシュがどのように処理すべきか誤解し、どうやらステップ定義

Your block takes 1 argument, but the Regexp matched 2 arguments. 

の非常に最初の行のためにこれに実行例を以下のとき。誰かが助けてくれますか?少ないテストデータと私のコードが一致している2番目のパラメータがdata_tableあるので、あなたはそのエラーを取得している キュウリの下

Given I login as "ad" with the following data: 
    |role|usern  |userpass  | 
    |ad |adcccount |adpassword | 
    |ml |mlaccount |mlpassword | 

ステップ定義

Given /^I login as "(ad|ml)" with the following data:/ do |user| 
temp_hash = {} 
    if (user == "ad") 
     temp_hash = $ad 
    elsif (user == "ml") 
     temp_hash = $ml 
    end 

    usern = temp_hash["usern"] 
    userpass = temp_hash["userpass"] 

@app = App.new 
    @app.login.load 
    @app.login.username.set usern 
    @app.login.password.set userpass 
    @app.login.btn_login.click 
end 

答えて

0

です。私は100じゃないので、それはdata_tableに複数のエントリを使用していませんが、あなたのステップの定義は、あなたはあなたが同じことを見ることができるリンク先の記事でGiven /I create new user named "(user_1|user_2|user_3)" with the following data:/ do |user, data_table|ステップを見れば

Given /^I login as "(ad|ml)" with the following data:/ do |user, data_table| 
    ... 

をする必要がありますあなたの例で何をしようとしているのか確かめてください。

0

ありがとう、トーマス;あなたのヒントは、期待どおりに機能した次のコードにつながります。

Given /^I login as "(ad|ml)" with the following data:/ do |login_role, data| 

    temp_hash = {} 
    data.hashes.each do |hash| 
    if hash[:role] == login_role 
     temp_hash[:role] = hash[:role] 
     temp_hash[:usern] = hash[:usern] 
     temp_hash[:userpass] = hash[:userpass] 
    end 
    end 

    usern = temp_hash[:usern] 
    userpass = temp_hash[:userpass] 

    @app = App.new 
    @app.login.load 
    @app.login.username.set usern 
    @app.login.password.set userpass 
    @app.login.btn_login.click 
    expect(@app.dashboard).to be_displayed 
end 
関連する問題