Mam formularz z ukrytym polem zawierającym bieżącą datę.Wartość testowania kapibara ukrytego pola
Próbuję dowiedzieć się, jak napisać Finder capybara do:
- Sprawdź, czy pole jest tam
- sprawdzić wartość pola
Czy to możliwe Kapibara?
Mam formularz z ukrytym polem zawierającym bieżącą datę.Wartość testowania kapibara ukrytego pola
Próbuję dowiedzieć się, jak napisać Finder capybara do:
Czy to możliwe Kapibara?
jego prosty można to zrobić za pomocą find_by_css
lub za pomocą XPath jak postępować
page.find_by_css('#foo .bar a') #foo is the id the foo has .bar class
page.find('/table/tbody/tr[3]') #path of the element we want to find
po prostu to zrobić:
find("#id_of_hidden_input", :visible => false).value
'visible: false' to kluczowa część tutaj. Dzięki! – LouieGeetoo
To tylko po to, aby znaleźć element, ten post mówi o tym, jak go przetestować: http://stackoverflow.com/questions/15066884/how-to-get-the-hidden-element-value-in-capybara – Dean
Można także nakazać Capybara aby nie ignorować ukryte elementy globalnie w swojej spec_helper.rb
lub odpowiednik. Domyślne zachowanie może być zmienione:
# default behavior for hidden elements
# Capybara.ignore_hidden_elements = false
# find all elements (hidden or visible)
page.all(".articles .article[id='foo']")
# find visible elements only (overwrite the standard behavior just for this query)
page.all(".articles .article[id='foo']", :visible => true)
# changing the default behavior (e.g. in your features/support/env.rb file)
Capybara.ignore_hidden_elements = true
# now the query just finds visible nodes by default
page.all(".articles .article[id='foo']")
# but you can change the default behaviour by passing the :visible option again
page.all(".articles .article[id='foo']", :visible => false)
Przykłady zaczerpnięte z this article.
Dzięki, skończyłem z następującym 'elem = page.find_by_id ('my_element_id'); elem.value.should eq Date.today.to_s' –
Użyłem również ['find_by_id'] (http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders:find_by_id):' assert_equal photo .updated_at.to_datetime.to_s, page.find_by_id ('hidden_field_photo_updated_at'). value.to_datetime.to_s' – user664833