Abbiamo finito per scrivere uno strato sul selenio che gestiva questo scenario avvolgendo le chiamate in un ciclo opzionale. Quindi, quando si farebbe:
@browser.click "#my_button_id"
sarebbe fare qualcosa di simile a ciò che AutomatedTester suggerito sopra:
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 = <<EOF
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
l'involucro ha fatto anche altre cose, come che permette di cercare per l'etichetta del pulsante/ingresso etc . (quindi il wrapper non esisteva solo per i problemi di temporizzazione, questa era solo una delle cose che abbiamo inserito.)
Sì, funzionerebbe, ma devi specificare cosa stai aspettando in ogni richiesta Ajax . Credo che ci dovrebbe essere un modo migliore. –