セレンwebdriverをのRails BDD(カピバラ:: ElementNotFound)
私はこの主張に失敗統合テストを行うにしようとすると:
@user = FactoryBot.create(:user)
@client = FactoryBot.create(:client, user: @user)
@event = FactoryBot.create(:event, client: @client)
visit client_path(@client)
click_link "Bill"
をし、これを取得しますエラー
And an invoice is created to the client # features/step_definitions/new_invoice_steps.rb:9
Unable to find visible xpath "/html" (Capybara::ElementNotFound)
./features/step_definitions/new_invoice_steps.rb:12:in `"an invoice is created to the client"'
features/new_invoice.feature:15:in `And an invoice is created to the client'
ここでは、リンクコード
<%= link_to "Bill", bill_client_path(@client), method: :post%>
です
これは私がちょうどbyebugとタイプcurrent_urlとのリンクをクリックした後に停止すると、それは私にはありません。この
"http://www.example.com/clients/1/bill"
を与えたクライアントコントローラに
def bill
#some code here
respond_to do |format|
if invoice.save
flash[:success] = 'Invoice was successfully created.'
format.html { redirect_to invoice}
format.json { render :show, status: :created, location: invoice }
else
format.html { render :new }
format.json { render json: invoice.errors, status: :unprocessable_entity }
end
end
end
である私が呼ぶ方法であり、請求方法が請求書ビューにリダイレクトされるためです。カピバラはそのページにこだわっていて、もちろん私に空白のページをくれました。 なぜCapybaraが2番目のリダイレクトを取得しないのですか? どうすればこの問題を解決できますか?トランザクションの備品がセレンでは動作しませんので、
テストログ
Started POST "/clients/1/bill" for 127.0.0.1 at 2017-12-18 15:54:55 +0100
Processing by ClientsController#bill as HTML
Parameters: {"id"=>"1"}
[1m[36mUser Load (0.7ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?[0m [["id", 1], ["LIMIT", 1]]
[1m[36mClient Load (0.9ms)[0m [1m[34mSELECT "clients".* FROM "clients" WHERE "clients"."user_id" = ? AND "clients"."id" = ? LIMIT ?[0m [["user_id", 1], ["id", 1], ["LIMIT", 1]]
[1m[36mEvent Exists (0.4ms)[0m [1m[34mSELECT 1 AS one FROM "events" WHERE "events"."client_id" = ? AND "events"."billed" IS NULL LIMIT ?[0m [["client_id", 1], ["LIMIT", 1]]
No template found for ClientsController#bill, rendering head :no_content
Completed 204 No Content in 210ms (ActiveRecord: 2.0ms)
カピバラではどのようなドライバを使用していますか?どのCapybaraの設定を使用していますか?リンクをクリックする前に何をしていますか?また、エラーが発生したスタックトレースを表示します。 - https://stackoverflow.com/help/how-to-askを参照してください。あなたのPOSTリンクが 'capybara/rails'を必要としないためにGETと解釈されているか、またはJSがUJSコードの初期化を妨げているというエラーが原因です。しかし、それ以上の情報なしで伝えることは不可能です。 –
追加された情報 – power96
このテストで 'selenium-webdriver'を実際に使用している場合(firefox/chromeブラウザウィンドウを開いていますなど)、JS内にレールujsが正しく初期化されないようにするエラーが発生している可能性が最も高いですclick_linkはPOSTではなくGETを生成しています。 test.logをチェックして、要求のタイプを確認します。 –