Capybara Failed из-за перекрывающегося элемента [решено] - PullRequest
0 голосов
/ 16 января 2019

У меня "конфликт" между загрузчиком изображений и вложенными полями в моей спецификации.

Работало хорошо, пока я не добавил в свой продукт вложенные атрибуты :sizes.

тест зеленый если я уберу:

attach_file "product[attachments][]",
   Rails.root.join("spec/fixtures/products/pull_noir_1.jpg")

тест зеленый если я уберу:

 click_on("Ajouter une taille")
 find('.nested-fields:nth-child(1)').fill_in "Taille", with: "M"
 find('.nested-fields:nth-child(1)').fill_in "Quantité dans cette taille", with: 9

тест не пройден если я оставлю их обоих ...

  require 'rails_helper'

   RSpec.describe "Creating Product", js: true do 

    fixtures :users, :categories

    context "As an admin I can"  do 

        before(:each) do 
            nelly = users(:nelly)
            login_as(nelly)
        end

        scenario "Create a product" do 

            visit new_admin_product_path

            fill_in "product[title]", with: "Pull en laine"
            fill_in "product[price]", with: 50
            fill_in "product[description]", with: "Une description pour ce pull"
            fill_in "product[color]", with: "Noir"
            select 'Pull', from: "product[category_id]"

            attach_file "product[attachments][]", Rails.root.join("spec/fixtures/products/pull_noir_1.jpg")

            click_on("Ajouter une taille")
            find('.nested-fields:nth-child(1)').fill_in "Taille", with: "M"
            find('.nested-fields:nth-child(1)').fill_in "Quantité dans cette taille", with: 9


            click_on "Valider le produit"

            expect(page).to have_content("Créé avec succès")
        end
    end
  end

Вот ошибка:

Failures:

  1) Creating Product As an admin I can Create a product
     Failure/Error: attach_file "product[attachments][]", Rails.root.join("spec/fixtures/products/pull_noir_1.jpg")

     Capybara::Webkit::ClickFailed:
       Failed to click element /html/body/div[2]/form[@id='new_product']/div[2]/div[2]/div/input[@id='files'] because of overlapping element /html/body/div[2]/form[@id='new_product']/div[4]/div/input at position 507, 848;
       A screenshot of the page at the time of the failure has been written to /var/folders/11/mdddnw8d0zd961bsfkq1cjy00000gn/T/click_failed_I24249.png
     # ./spec/features/admin/products/creating_product_spec.rb:24:in `block (3 levels) in <top (required)>'

UPDATE

_form.html.erb

<%= simple_form_for(@product, url: admin_products_path)do |f| %>        
    <div class="row">
        <div class="col-xs-12 col-md-3">
            <%= f.input :category_id, collection: Category.all, value_method: :id,label: "Categorie" ,include_blank: false, label: false %>
        </div>
        <div class="col-xs-12 col-md-3">
            <%= f.input :title, placeholder: "Titre", label: false %>
        </div>
        <div class="col-xs-12 col-md-3">
            <%= f.input :color, placeholder: "Couleur", label: false %>
        </div>
        <div class="col-xs-12 col-md-3">
            <%= f.input :price, placeholder: "Prix", label: false, input_html: {min: 1, value: "Prix"} %>
        </div>
    </div>

    <div class="row">
        <div class="col-xs-12 col-md-7">
            <%= f.input :description, placeholder: "Description", input_html: {rows: 5}, label: false %>
        </div>
        <div class="col-xs-12 col-md-5">
            <div class="image-upload-wrap">
              <%= f.file_field :attachments, multiple: true, class: "file-upload-input", id: "files" %>
              <h3>Glisser Déposer images</h3>
              <div id="result"></div> 
            </div>   
        </div>
    </div>


    <div class="row">
        <div class="col-12">
            <div id="sizes">
              <%= f.simple_fields_for :sizes do |size| %>
              <%= render "size_fields", f: size %>
            <% end %>
            <div class="links">
                <%= link_to_add_association "Ajouter une taille", f, :sizes, partial: "size_fields", class:"btn btn-primary btn-lg" , id: "add_size" %>
            </div>
            </div>
        </div>
    </div>
     <div class="row">
          <div class="col-12">
                <%= f.submit "Valider le produit", class: "btn btn-success btn-lg btn-block" %>
          </div>
     </div>
<% end %>

и вложенный size_fields.html.erb

<div class="nested-fields">
    <div class="row">
        <div class="col-12 col-md-4">
        <%= f.input :size_name, label: false, placeholder: "Taille", autofocus: true %>
        </div>
        <div class="col-12 col-md-4">
        <%= f.input :quantity, label: false, placeholder: "Quantité dans cette taille" %>
        </div>
        <div class="col-12 col-md-4">
            <%= link_to_remove_association "supprimer cette taille", f, class: "btn btn-danger delete_size" %>
            <hr>
        </div>
    </div>
</div>

screenshot of the product form

1 Ответ

0 голосов
/ 16 января 2019

Не могли бы вы предоставить отображаемый вид?Возможно, вы можете попробовать использовать атрибут HTML name или Xpath здесь:

 click_on("Ajouter une taille")

В зависимости от представления вы можете использовать:

find("[id='add_size']").click
...