Skip to content

Instantly share code, notes, and snippets.

@maplpro
Created October 26, 2010 15:01
Show Gist options
  • Save maplpro/647056 to your computer and use it in GitHub Desktop.
Save maplpro/647056 to your computer and use it in GitHub Desktop.
how to run Google Closure through Selenium
package example;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.selenium.SeleneseTestCase;
public class GoogStringTest extends SeleneseTestCase {
private final String DIRECTORY_PREFIX =
"file:///C:/Users/mbolin/workspace/closure-library/";
@Override
@Before
public void setUp() throws Exception {
final String url = DIRECTORY_PREFIX;
final String browserString = "*firefox";
// This initializes the protected "selenium" field with the base URL for the
// tests and the browser to use when running the tests.
setUp(url, browserString);
}
@Test
public void testGoogString() throws Exception {
// Opens the URL in Firefox.
selenium.open(DIRECTORY_PREFIX + "closure/goog/string/string_test.html");
// Because the test runs automatically when the HTML file is loaded, poll
// for up to 5 seconds to see whether the test is complete.
selenium.waitForCondition(
"window.G_testRunner && window.G_testRunner.isFinished()",
"5000");
// Invoke this snippet of JavaScript in the browser to query whether the
// test succeeded or failed.
String success = selenium.getEval("window.G_testRunner.isSuccess()");
boolean isSuccess = "true".equals(success);
if (!isSuccess) {
// If the test failed, report the reason why.
String report = selenium.getEval("window.G_testRunner.getReport()");
fail(report);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment