나는 며칠 전 Capybara를 사용하기 시작했고 전에는 셀레늄을 사용하지 않았습니다. 나는 내 테스트가 어떻게 beowser에서 수행되는지보고 싶어하고 그것을 위해 사용한다. selenium-webdriver
. 내가 카피 바라의 다음 시험이 있습니다Capybara with : js => true로 설정하면 테스트가 실패합니다.
scenario
에
:js => true
추가
RSpec.feature 'Authentication', :type => :feature do
def register_with_form
visit '/'
click_on 'Account'
click_on 'Register'
fill_in 'Email', :with => '[email protected]'
fill_in 'Name', :with => 'John'
fill_in 'Last name', :with => 'Smith'
fill_in 'Password', :with => '1234567890'
fill_in 'Password confirmation', :with => '1234567890'
find('.testing-sign-up-class')
click_button 'Sign up'
expect(page).to have_css '.hd-title', 'Get Started'
end
scenario 'User registers' do
register_with_form
expect(page).to have_css '.hd-title', 'Get Started'
expect(page).to have_css '.alert-success', 'Welcome! You have signed up successfully.'
expect(page).to have_css '.panel-title', 'What would you like to use GridHub for?'
end
scenario 'User sign out', :js => true do
register_with_form
click_on 'Account'
click_on 'Logout'
expect(page).to have_css '.alert-success', 'Signed out successfully.'
end
end
테스트를 끊었다. 콘솔을 보여줍니다
나는 보석 database_cleaner을 추가 한1) Authentication When not registered User sign out
Failure/Error: click_button 'Sign up'
Selenium::WebDriver::Error::UnknownError:
Element is not clickable at point (606, 23.73333740234375). Other element would receive the click: <input autocomplete="off" name="term" id="term" class="form-control nav-search-field main-ac autocomplete ui-autocomplete-input" placeholder="search items" data-url="/search" type="text">
, 내 spec_helper.rb
다음 코드가 있습니다
config.before(:each, type: :feature) do
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
if !driver_shares_db_connection_with_specs
DatabaseCleaner.strategy = :truncation
end
end
config.before(:each) do
DatabaseCleaner.start
end
config.append_after(:each) do
DatabaseCleaner.clean
end
을 그리고 내 bin/rspec
파일에 다음 줄이 있습니다
config.use_transactional_fixtures = false
감사합니다.
UPDATE는
나는 뭔가 다른 브라우저에서 문제가 될 수 있다는 것을 가정한다. 왜냐하면 어떤 상황에서는 테스트가 브라우저 (나는 파이어 폭스와 크롬을 썼다)를 열었고 일부 요소는 브라우저 창 아래에있을 수 있기 때문에 상황 테스트에 실패했기 때문에 필요한 버튼을 찾을 수 없습니다. 브라우저 창을 스크롤 할 시간이 있으면 일부 테스트가 성공적 일 수 있습니다.
이것은 도움이 될 수 있습니다. http://stackoverflow.com/questions/11335303/cant-find-element-to-click-on-using-capybara-rails3 –