我们最终在selenium上编写了一个层,通过在可选循环中包装调用来处理这种情况.所以,当你这样做时:
@browser.click "#my_button_id"
它会做类似于AutomatedTester建议的内容:
class Browser
def click(locator)
wait_for_element(locator,:timeout => PAGE_EVENT_TIMEOUT)
@selenium.click(locator)
end
def wait_for_element(locator,options)
timeout = options[:timeout] || PAGE_LOAD_TIMEOUT
selenium_locator = locator.clone
expression = <
var element;
try {
element = selenium.browserbot.findElement('#{selenium_locator}');
} catch(e) {
element = null;
};
element != null;
EOF
begin
selenium.wait_for_condition(expression,timeout)
rescue ::Selenium::SeleniumException
raise "Couldn't find element with locator '#{locator}' on the page: #{$!}.\nThe locator passed to selenium was '#{selenium_locator}'"
end
end
end
包装器也做了其他的事情,比如允许通过按钮/输入标签等进行搜索(因此包装器不仅存在时间问题,这只是我们放在那里的东西之一.)