我有这种情况:
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 webdriver:
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)
有人有个好主意吗?
答案 0 :(得分:2)
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