1

我有这种情况:

Scenario: If coming from savsale.com directly then the submenu items should open the right items.
  Given the 'sales' page
  When the user chooses 'women/accessories' from the navigation menu

而这一步:

When /^the user chooses '(.*?)\/(.*?)' from the navigation menu$/ do |menu,submenu|
  begin
    evaluate_script(%Q{console.debug('trying to show the menu:');})
    command1 = "$('##{menu} ul').attr('style','display:block;visibility:visible');"
    evaluate_script(%Q{console.debug("#{command1}");})
    evaluate_script(command1)
    evaluate_script(%Q{console.debug('first command done.');})
    command2 = "$('##{menu}').addClass('sfHover');"

我也在使用 selenium 网络驱动程序:

Capybara::Selenium::Driver.new(app, :browser => :firefox) 

javascript的执行没有达到这个代码:

evaluate_script(%Q{console.debug('first command done.');})

在 Firefox 控制台中显示如下:

$('#women ul').attr('style','display:block;visibility:visible');

但这不是:

first command done.

我认为它在execute_script(command1)处停止,然后它因超时异常而失败......:

When the user chooses 'women/accessories' from the navigation menu # features/step_definitions/steps.rb:193

  Timeout::Error (Timeout::Error)

有人有好主意吗?

4

1 回答 1

2

OMG,过了一会儿,我意识到我尝试过的页面返回的对象上有一个 execute_script 并且它可以工作...... OMG......所以现在所有的javascript都被执行了......

When /^the user chooses '(.*?)\/(.*?)' from the navigation menu$/ do |menu,submenu|
  begin
    sleep 10.seconds #wait for the js to load the menus
    page.execute_script(%Q{console.debug('trying to show the menu:');})
    command2 = "$('##{menu}').addClass('sfHover');"
    page.execute_script(command2)
    command1 = "$('##{menu} ul').attr('style','display:block;visibility:visible');"
    page.execute_script(command1)
    command3 = "$('a[filter-category=#{menu}][filter-sub-category1=#{submenu}]')[0].click();"
    page.execute_script(command3)
    rescue Capybara::NotSupportedByDriverError
  end
end
于 2012-08-14T07:42:49.340 回答