Hello.

There is the following test fragment:

require 'rails_helper' describe 'A contract' do before do @project = create(:project) @client = @project.user @contractor = create(:contractor) @contractor.contractor_info = create(:contractor_info) @contractor.contractor_info.source_languages << @project.source_languages @contractor.contractor_info.target_languages << @project.target_languages sign_in_contractor(@contractor) visit project_url(id: @project) page.find("#newProposal").click #click_link("Post Proposal") expect(current_path).to eq(new_project_proposal_path(project_id: @project.slug)) fill_in 'Amount', with: 50 fill_in I18n.t('proposals.new.description_placeholder'), with: 'X' * 60 click_button 'Post Proposal' expect(current_path).to eq(project_path(id: @project)) @proposal = @project.proposals.last log_out(@contractor) end ................................................................................ 

on the line page.find("#newProposal").click shows the error ElementNotFound: Unable to find css "#newProposal"

On the projects / show view there is this link with the given id:

 <% if contractor_signed_in? %> <% if policy(Proposal).create? && @project.available? %> <div class="col-md-4"> <%= link_to new_project_proposal_path(@project), class: "btn btn-lg btn-primary btn-block", id: "newProposal" do %> <span class="icon icon-plus pull-left mb"></span><%= t('proposals.new_proposal') %> <% end %> </div> <% end %> <div class="col-md-4 pull-right"> <div class="panel panel-default mb"> <div class="panel-body"> <h4><%= t('sidebar.about_client') %></h4> <p><strong><%= t('user.name') %>:</strong> <%= @project.user.fullname %></p> <p><strong>First_name:</strong></p> <p><strong><%= t('projects.projects_posted') %>:</strong> <%= @project.user.projects.size %></p> </div> </div> </div> <% end %> 

I put brekpoint in the test before clicking the link. Checking current_path is "/ projects / translation1-048fc3". We are on the project page, as it should be.

Why doesn’t the capybara see this link? Thanks in advance for your reply.

  • 1. It is advisable to show the html code that is obtained when rendering the template. For example, a little higher is if because of which the link may not be shown at all. 2. If it, nevertheless, is in html, is it not hidden by such styles? - anoam
  • and how to look at the test which template is rendered? In a real project, rendered as expected. - dev85
  • if i remember correctly, html method. If it is more convenient, you can use save_page or save_and_open_page . Just in case, here is the link to the documentation - anoam
  • thank. I try - dev85
  • @ dev85 Capybara allows you to even take screenshots of pages (save_screenshot method). - cheops

0