2010-11-11 7 views
1

Ma page a une jquery ui datepicker sur un champ d'entrée #graph_start_datesélecteur de XPath de jquery ui datepicker

Je suis en train d'écrire les étapes Concombre suivant

When I click the graph start date 
Then I should see a datepicker 

Voici ce que j'ai pour l'étape définitions:

When /I click the graph start date/ do 
    find(".//*[@id='graph_start_date']").click 
end 

Then /^I should see a datepicker$/ do 
    page.should have_xpath(".//div[@id='ui-datepicker-div' and ?????????]") 
end 

le jquery ui datepicker insère d'abord dans le dom

<div class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible" id="ui-datepicker-div"></div> 

Lorsque le son sauté dom contient

<div class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible" id="ui-datepicker-div" style="position: absolute; top: 523px; left: 167.5px; z-index: 1;"> 

Après son rejeté le dom contient

<div class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible" id="ui-datepicker-div" style="position: absolute; top: 523px; left: 167.5px; z-index: 1; display: none;"> 
+2

Il n'y a pas question posée. ??? –

+0

J'ai essayé la page. Je devrais has_xpath ("// div [@ id = 'ui-datepicker-div' et contient (@ style, 'display: block')]") mais page.body ne contient même pas le code généré js, alors comment puis-je écrire l'assertion? – linojon

+0

effectivement cela échoue également (indiquerait que le sélecteur est ou a été surgi) page.tould has_xpath ("// div [contient (@ style, 'position: absolute')]") alors peut-être que le clic ne fonctionne pas vraiment? mais quand je fais une pause dans le débogueur, je peux voir le "datepicker" dans la fenêtre Webdriver Firefox. – linojon

Répondre

3

Il y a l'option :visible => true qui est documentée dans Capybara::Node::Matchers#has_xpath? si:

Then /^I should see a datepicker$/ do 
    page.should have_xpath(".//div[@id='ui-datepicker-div']", :visible => true) 
end 

Cependant, cela peut être un problème différent, mais pour moi le datepicker ne semble pas du tout lorsque le navigateur conduit capybara n'a pas le focus , et donc mon test échoue (parfois)!

EDIT:

tout d'abord, il semble que le datepicker ne veut pas en fait un clic sur le terrain pour déclencher, mais un foyer qui est malheureusement non pris en charge par le pilote de sélénium de capybara et il ne déclenche pas lorsque vous déclenchez un clic mais le navigateur n'a pas de focus.

La bonne façon de déclencher la mise au point serait:

find(".//div[@id='ui-datepicker-div']").trigger('focus') 

mais qui soulève un Capybara::NotSupportedByDriverError :(

Pour contourner, vous pouvez utiliser le hackish:

When /I focus the graph start date/ do 
    page.execute_script("$('#graph_start_date').focus()") 
end 

(merci à: http://groups.google.com/group/ruby-capybara/msg/af6caeef01d978b0)

Il existe diverses discussions et questions pertinentes à ce sujet dans Google Groupes:

0

Je voudrais juste lancer javascript qui #focuses le champ, les clics 1 des ancres .. Puis laissez capybara s'assurer que la bonne valeur est sur le terrain.

0

Je rencontrais le même problème ce matin, et voici comment je l'ai réparé.

Dans mon fichier fonction

@javascript # You need this javascript tag 
Scenario:Adding a date to a job 
    When I go to enter a date 
    Then I should see a date picker appear 

Dans mes définitions étape:

When /^ I go to enter a date$/ do 
    element = find_by_id("you_date_field_id") 
    element.click 
end 

The /^I should see a date picker appear$/ do 
    date = find(:xpath, "//div[@id='ui-datepicker-div']") 
end 

Hope this helps