Skip to content

Instantly share code, notes, and snippets.

@mir4a
Created September 11, 2015 16:14
Show Gist options
  • Save mir4a/f231759730114c86a6d4 to your computer and use it in GitHub Desktop.
Save mir4a/f231759730114c86a6d4 to your computer and use it in GitHub Desktop.
Setter/getter for some particular global var and increment on each Ajax request for Capybara tests
def set_ajax_counter(global_var)
page.execute_script <<-SCRIPT
window["#{global_var}"] = 0;
$(document).on("ajaxSend", function(){
window["#{global_var}"]++;
console.log('increment ajax counter window["#{global_var}"] = ' + window["#{global_var}"]);
});
SCRIPT
end
def get_js_global_var(global_var)
page.evaluate_script <<-SCRIPT
window["#{global_var}"]
SCRIPT
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment