运行一个JavaScript黄瓜水豚它停止了

running a javascript cucumber capybara it halts

本文关键字:黄瓜水 JavaScript 一个 运行      更新时间:2023-09-26

我有这种情况:

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

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

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

javascript 的执行没有达到以下代码:

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

在火狐控制台中,显示如下:

$('#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)

有人有好主意吗?

天哪,过了一会儿,我意识到我尝试的页面返回的对象上有一个execute_script并且它可以工作......天哪......所以所有的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