jquery-ui
  • cucumber
  • capybara
  • 2010-11-11 118 views 1 likes 
    1

    我的页面上输入字段#graph_start_dateXPath的选择

    我想写以下步骤黄瓜一个jQuery UI的日期选择器

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

    下面是我对步骤定义:

    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 
    

    的jQuery UI的日期选择器最初插入到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> 
    

    当它弹出的DOM包含

    <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;"> 
    

    其驳回DOM包含

    <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

    毫无疑问问。 ??? – 2010-11-11 20:39:02

    +0

    我试过page.should have_xpath(“// div [@ id ='ui-datepicker-div'并包含(@ style,'display:block')]”),但page.body甚至不包含js生成的代码,所以我如何写断言? – linojon 2010-11-11 21:10:09

    +0

    实际上这也失败了(将表明选择器是或弹出过)page.should have_xpath(“// div [contains(@ style,'position:absolute')]”) 所以也许点击没有真正的工作?但是当我在调试器中暂停时,我可以在Webdriver Firefox窗口中看到日期选择器。 – linojon 2010-11-11 21:24:54

    回答

    3

    有它在Capybara::Node::Matchers#has_xpath?这样记录的:visible => true选项:

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

    然而,这可能是一个不同的问题,但对我来说,当水豚驱动器没有焦点的日期选择器不会出现在所有,所以我的测试失败(有时)

    编辑:

    首先,它似乎日期选择器实际上并不希望在球场上点击触发,但重点不幸的是水豚的硒驱动程序不支持的,并没有当你触发触发点击但浏览器没有焦点。

    触发焦点的正确的方法是:

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

    这又引出一个Capybara::NotSupportedByDriverError :(

    要解决,你可以使用的hackish

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

    (感谢:http://groups.google.com/group/ruby-capybara/msg/af6caeef01d978b0

    有各种各样的讨论和相关的问题,对这个在谷歌网上论坛:

    0

    我会运行一些JavaScript这#focuses现场后,点击锚1 ..然后让水豚确保正确的价值在田间。

    0

    今天早上我遇到了同样的问题,这里是我如何修复它。

    在我的特征文件

    @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 
    

    在我的步骤定义:

    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 
    

    希望这有助于

    相关问题