Skip to content

Instantly share code, notes, and snippets.

@lurodrig
Last active November 13, 2018 17:23
Show Gist options
  • Save lurodrig/3788130cb16265faf0b6ff2d7bd87e5a to your computer and use it in GitHub Desktop.
Save lurodrig/3788130cb16265faf0b6ff2d7bd87e5a to your computer and use it in GitHub Desktop.
import org.openqa.selenium.WebDriver;
static WebDriver browser;
@Before
public void initBrowser() {
HtmlUnitTestDriver d = new HtmlUnitTestDriver();
d.getWebClient().getOptions().setJavaScriptEnabled(true);
d.getWebClient().getOptions().setCssEnabled(false);
d.getWebClient().getOptions().setTimeout(1000000);
browser = d;
}
@Test
public void testRedirectToIdPLoginAuthenticateServeAndRequestDifferentContext() throws InterruptedException {
browser.get("http://localhost:8082/web-module-3/");
assertAtLoginPagePostBinding();
LoginPage loginPage = PageFactory.initElements(browser, LoginPage.class);
loginPage.login("bburke", "password");
assertAtModuleContext("/web-module-3");
// Make a request from the same browser another context
// Invokes a servlet that displays user's principal name
JavascriptExecutor je = (JavascriptExecutor) browser;
Object response = ((JavascriptExecutor) browser).executeAsyncScript(
"var callback = arguments[arguments.length - 1];"
+ "var xhr = new XMLHttpRequest();"
+ "xhr.open('GET', 'http://localhost:8082/web-module-4/saml-session-info', true);"
+ "xhr.onreadystatechange = function() {"
+ " if (xhr.readyState == 4) {"
+ " callback(xhr.responseText);"
+ " }"
+ "};"
+ "xhr.send();");
Assert.assertTrue(((String)response).contains("bburke"));
browser.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment