3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[RSpec] (feature) Capybaraでfill_in使って失敗するとき

Posted at

こんなコードがありました

<%= provide(:title, "Create New List") %>
<div class="listsnewPage">
  <div class="container">
    <%= form_with model: @list, url: lists_path, class: "new_list" do |f| %>
      <%= f.label :title, "List Title" %> <span>(1〜20 characters)</span>
      <%= f.text_field :title, autofocus: true, autocomplete: "off", class: "form-control listName" %>
      <div class="text-center">
        <%= f.submit "Create", class: "submitBtn" %>
      </div>
    <% end %>
  </div>
</div>

こんなテストを書きました(feature spec, js: true)

fill_in "List Title", with: "created_now"

→ダメ

fill_in ".form-control", with: "created_now"

→ダメ!!!!

fill_in使ってるのにformに入力できない問題発生

#いきなりですが
参考:Rspec Capybaraで実際テストを書いて困ったシチュエーションの解消法
https://qiita.com/kon_yu/items/52a0f5f0016564486061

fill_in

form(input)にidまたはnameが指定されていないと使えない

class指定の場合は???

こうする

find(".form-control").set("created")

通ったーーーーー!!!!!!!

けど

なんでf.labelに"List Title"って設定してるのに通らないんだろ?
わからん。。

#とりあえず
fill_inでダメなときはfind使ってみるといいことあるかも
(根本的な解決には至っていない可能性)


おわり
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?