thoughtbot / capybara-webkit

A Capybara driver for headless WebKit to test JavaScript web apps
https://thoughtbot.com/open-source
MIT License
1.97k stars 428 forks source link

Unable to find css because it redirects to /login #1057

Closed pimentones closed 6 years ago

pimentones commented 6 years ago

Hi! I'm trying to use capybara-webkit on our test suite but all tests fail with error "Unable to find css .... (Capybara::ElementNotFound)".

Using debug info I can see that after Start, Load and Finish the visit command to http://cucumber.fullfabric.dev:37373/campaigns#planned, a new request is triggered to "http://cucumber.fullfabric.dev:37373/login".

If you could point in some direction I'd be appreciated as I'm out of ideas why this is happening.

Scenario: Duplicate an existing planned campaign # features/app/campaigns/manage/duplicate.feature:9 Given a campaign # features/step_definitions/campaigns/campaign_steps.rb:3 Received "Visit(http://cucumber.fullfabric.dev:37373/campaigns#planned)" Started "Visit(http://cucumber.fullfabric.dev:37373/campaigns#planned)" Load started "Visit(http://cucumber.fullfabric.dev:37373/campaigns#planned)" started page load Started request to "http://cucumber.fullfabric.dev:37373/campaigns#planned" Finished "Visit(http://cucumber.fullfabric.dev:37373/campaigns#planned)" with response "Success()" Started request to "http://cucumber.fullfabric.dev:37373/login" Received 302 from "http://cucumber.fullfabric.dev:37373/campaigns#planned"

My driver.version:

      capybara-webkit: 1.15.0
      Qt: 5.5.1
      WebKit: 538.1
      QtWebKit: 5.5.1

set cookie:

Given( /^I am authenticated$/ ) do
     browser = Capybara.current_session.driver
     browser.set_cookie name: "token", value: @profile.token, expires: 30.minutes.from_now.utc
end

Step definitions

Given( /^a campaign$/ ) do
  @campaign = FactoryGirl.create(:campaign)
end

When( /^I duplicate the campaign$/ ) do

  visit "/campaigns#planned"

  within '.filters' do
    page.find('select').select('All')
  end

  within "table tbody" do
    find('a.duplicate').click
  end

  within('.modal') do
    fill_in('name', with: 'Duplicate campaign #1')
    click_button('Duplicate campaign and add more info')
  end

end
jferris commented 6 years ago

I'm going to close this, because it doesn't look like a bug in capybara-webkit, but feel free to keep commenting and asking questions.

That doesn't look like a valid use of set_cookie. You can see an example of setting a cookie in the specs: https://github.com/thoughtbot/capybara-webkit/blob/27ed01a730dec15d00351804123eee6e8a1bbef7/spec/driver_spec.rb#L2148