Last active
November 13, 2018 17:23
-
-
Save lurodrig/3788130cb16265faf0b6ff2d7bd87e5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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