Capybara 및 기능 테스트를 처음 사용했습니다. 레일즈 애플리케이션에서 게시물에 대한 주석을 보이지 않게하는 토글 (toggles) 기능을 테스트 해 보았습니다. 주석을보기로 전환하는 첫 번째 테스트는 통과되지만,보기를 벗어나는 두 번째 테스트는 통과하지 않습니다. (나는 headless-chrome webdriver를 사용하고있다).Rails/Capybara 기능 테스트에서 부트 스트랩 접이식 토글 링이 실패했습니다
context 'viewing comments', js: true do
scenario 'toggling comments into view' do
@post.comments.create(body: 'This is a comment.', user_id: @commenter.id)
visit authenticated_root_path
click_button 'Toggle comments'
expect(page).to have_content('This is a comment')
end
scenario 'toggling comments out of view' do
@post.comments.create(body: 'This is a comment.', user_id: @commenter.id)
visit authenticated_root_path
click_button 'Toggle comments'
expect(page).to have_content('This is a comment')
click_button 'Toggle comments'
expect(page).to_not have_content('This is a comment')
end
end
처음에, 나는 두 번 click_button 'Toggle comments'
있었다 백투백. 테스트 작업을 반복하지 않아도됩니다. 나는 또한 두 가지 동작 사이에 sleep n
을 사용해 보았지만 아무 소용이 없었다.
Failures:
1) Comment management viewing comments toggling comments out of view
Failure/Error: expect(page).to_not have_content('This is a comment')
expected not to find text "This is a comment" in "OdinFB PROFILE REQUESTS 0 LOG OUT The Feed Create post Luna Lovegood said... Body of post 0 Likes 1 Comments Like Comment Share Toggle comments This is a comment. Morfin Gaunt on Sep 18 2017 at 4:22PM"
버튼 자체는 앱이 로컬에서 실행될 때 작동합니다. 테스트에서 처음 활성화되면 비활성 상태가됩니다.
어떤 통찰력도 감사 할 것이며, 읽어 주셔서 감사합니다.
헤드리스 모드를 해제하여 페이지에서 어떤 현상이 발생했는지 확인할 수 있었습니까? 또한 첫 번째 테스트에서는 버튼을 클릭하기 전에 내용을 볼 수 있는지 실제로 확인하지 않으므로 버튼을 눌러 내용을 전환하는 것이 실제로 테스트되지는 않습니다. –
@ThomasWalpole 입력에 감사드립니다. 나는 실제로 그것을 헤드리스로 돌렸고, 버튼이 주석을보기 위해 전환하는 것을 보았습니다. 그리고 두 번째 요점에 대해 감사드립니다. 나는 필요한 기대감을 추가했고, 시험은 고맙게도 통과되었다. –
나는 당신이 머리를 쓰지 않고 단추를 보았다고 말하기 때문에 거기에 오타가 있다고 생각한다. 명확히하기 위해 헤드리스 모드가 아닌 모드에서 테스트를 통과했지만 헤드리스 모드에서 테스트를 통과한다고 말하는 것입니까? –