2017-04-04 17 views
0

이것은 Rspec 기능입니다.Capybara/Rspec이 Sweet Alert 모달에서 버튼을 찾을 수 없지만 have_selector가 true를 반환하는 이유는 무엇입니까?

given (:send_selector){ 'button.confirm'} 

feature "when talent has not applied." do 
    given (:apply_button) { find('button[data-selector="offer-apply-button"]') } 
    before(:each)   { visit offer_path(offer.id)       } 

    scenario "Talent applies to offer with default cv", js: true do 
    apply_button.click 
    expect(page).to have_selector(send_selector) 
    find_button(send_selector).click 
    wait_for_ajax 
    # other expectations 
    end 
end 

그것은 선택을 할 수있는 기대를 전달하지만 여전히 find_button(send_selector).click

나는 또한 page.find_button(send_selector).clickfind_button(send_selector).trigger('click')를 사용하여 시도

하지만 첫 번째로 선을 가리키는 오류

Capybara::ElementNotFound: 
     Unable to find button "button.confirm" 

에게 던졌습니다 오류를 던지고 두 번째는 아무 것도하지 않는 것 같습니다. 왜냐하면 다음 li에서 스크린 샷을 찍을 때 액션을 담당하는 컨트롤러가 호출되지 않고 모달이 그대로 남아 있기 때문입니다. 네.

폴터 검사기 디버거를 실행하고 html이 페이지에 있습니다.

html code from the poltergeist debugger

은 잘 모달 후 작은 슬립을 추가 작동 케이스 누군가

enter image description here

답변

0

같은 문제를 갖는다 (save_screenshot() 방법을 사용) 카피 바라 볼 같이 모달 나타나다. 이 동작은 셀렉터가 알레시라고 말하기 때문에 여전히 이상합니다. 심지어 have_selector(send_selector, visible: true).present?이 참을 반환합니다. http://www.rubydoc.info/gems/capybara/Capybara/Node/Finders#find_button-instance_method - -

scenario "Talent applies to offer with default cv", js: true do 
    apply_button.click 
    expect(page).to have_selector(send_selector) 
    sleep 1          <<-- THIS SOLVED THE PROBLEM 
    find(send_selector).click 
    wait_for_ajax 
    ... 
end 
1

문제는 find_button는 CSS 선택을하지 않는다는 것입니다 그것은합니다 (click_button과 동일하고 'have_button'소요) 버튼의 이름, ID, 제목, 또는 텍스트 컨텐츠를합니다. 당신의 응답 전 sleep 1에서

는 sweetalert2를 사용하는 경우

+0

안녕하세요, 당신 말이 맞습니다. find_button은 CSS 선택기를 사용하지 않습니다. 그럼에도 불구하고, 나는 이번에 답안에 "sleep 1"없이 게시 한 테스트를 실행하고 실패합니다. – juliangonzalez

+0

@juliangonzalez 같은 오류라면 Capybara.default_max_wait_time을 2 초 정도 늘려야한다는 뜻입니다. 그러나 다른 오류 (마우스 클릭에 대한 무언가가 다른 요소를 치는 경우)는 모달이 여전히 애니메이션을 적용하고 있기 때문에 잠자기를 필요로하거나 테스트 모드에서 애니메이션을 사용하지 않도록 설정하여 테스트 속도를 높이고 잠재적 인 박편 방지 –

0

가 나는 또한 그 문제를 직면 CSS 선택기를 걸립니까 findfind_button에서 교환하기 때문에, 그것은 고정 된 문제를 해결 무관했다 나는 그것을 해결 다음과 같이 기능 사양에 포함됩니다. (작동 했음)

scenario 'destroy a company', js: true do 
    within('.shadow.company-info') do 
     find('a[data-behavior="delete"]').click 
     wait_for_ajax 
     within(page.document.find(:css, '.swal2-buttonswrapper')) do 
      find(:css, '.swal2-confirm').click 
      wait_for_ajax 
      expect(page.document).to have_content I18n.t('delete.success') 
     end 
    end 
end