gmparker2000
12 years agoNew Contributor
Trouble JavaScript with GEB Groovy Script
I'm trying to create a load test for my application. The application makes heavy use of JQuery. The site redirects to a login screen where I log in. Then the site redirects the user back to the original page. The original page loads and then uses the JQuery ready event to make asynchronous requests back to the server to get JSON. Once the JSON arrives, sections are added to the page. The script below seems to get to the desired page, but no matter what I do, the page never seems to perform the initialization that happens in the JQuery ready event. I tried settings very large wait times in places, so it isn't related to not waiting long enough. Any ideas? Thanks
@Grab(group='org.codehaus.geb', module='geb-core', version='latest.release')
@Grab(group='org.seleniumhq.selenium', module='selenium-htmlunit-driver', version='latest.release')
import geb.Browser
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
Browser.drive() {
go "http://...";
$("input[name=username]").value("myusername");
$("input[name=password]").value("mypassword");
$("#loginButton").click();
waitFor() {
$("#header").text() == 'My Page'
}
waitFor() {
$(".classThatOnlyAppearsAfterJavaScriptExecutes").present
}
$("#button").click();
}
@Grab(group='org.codehaus.geb', module='geb-core', version='latest.release')
@Grab(group='org.seleniumhq.selenium', module='selenium-htmlunit-driver', version='latest.release')
import geb.Browser
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
Browser.drive() {
go "http://...";
$("input[name=username]").value("myusername");
$("input[name=password]").value("mypassword");
$("#loginButton").click();
waitFor() {
$("#header").text() == 'My Page'
}
waitFor() {
$(".classThatOnlyAppearsAfterJavaScriptExecutes").present
}
$("#button").click();
}