ruby - cucumber capybara testing date picker selects wrong day -
i trying write cucumber test page includes datepicker. swear working yesterday, not today.
then(/^select date (\d+) day(?:s|) prior today$/) |n| day=date.today-(n.to_i) target = date.strptime("#{day}",'%y-%m-%d') target_month_year = target.strftime('%b %y') selected_month_year = (find('.datepicker-switch').native.text) unless target_month_year == selected_month_year find('.prev').click sleep 1 end find('.day', :text => "#{day.day}", match: :prefer_exact).click sleep 2 end then have separate test checks correct date presented after selection. have verified day.day giving me correct result including puts(day.day), other variables. think problem matching issue, today's date 04/24/2015 , selecting 15 days prior. datepicker displays month , year above , allows select previous or next, days shown according how many days in particular month. , few day before , after. days previous month class="old day" , ones month displayed class="day" , next month class="new day". month want april , day ninth. keeps selecting 29th of march. first day listed on page contains "9". class wrong, since want "day" not "old day" , day wrong because want "9" not "29" put in :prefer_exact because has fixed matching wrong element in past me.
not sure try next. advice appreciated.
cucumber 1.3.10
capybara 2.4.1
ruby 1.9.3p551
ideally, don't select text if can avoid it.
but in case try using regex instead of plain text.
find('.day', :text => regexp.new("^#{day.day}$"), match: :prefer_exact).click there's little related reading @ end of (currently unimplemented) issue: https://github.com/jnicklas/capybara/issues/1256
Comments
Post a Comment