use of org.openqa.selenium.Cookie in project oxAuth by GluuFederation.
the class BaseTest method authenticateResourceOwnerAndDenyAccess.
public AuthorizationResponse authenticateResourceOwnerAndDenyAccess(String authorizeUrl, AuthorizationRequest authorizationRequest, String userId, String userSecret) {
String authorizationRequestUrl = authorizeUrl + "?" + authorizationRequest.getQueryString();
AuthorizeClient authorizeClient = new AuthorizeClient(authorizeUrl);
authorizeClient.setRequest(authorizationRequest);
System.out.println("authenticateResourceOwnerAndDenyAccess: authorizationRequestUrl:" + authorizationRequestUrl);
startSelenium();
driver.navigate().to(authorizationRequestUrl);
WebElement usernameElement = driver.findElement(By.name(loginFormUsername));
WebElement passwordElement = driver.findElement(By.name(loginFormPassword));
WebElement loginButton = driver.findElement(By.name(loginFormLoginButton));
if (userId != null) {
usernameElement.sendKeys(userId);
}
passwordElement.sendKeys(userSecret);
loginButton.click();
String authorizationResponseStr = driver.getCurrentUrl();
WebElement doNotAllowButton = driver.findElement(By.name(authorizeFormDoNotAllowButton));
final String previousURL = driver.getCurrentUrl();
doNotAllowButton.click();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return (d.getCurrentUrl() != previousURL);
}
});
authorizationResponseStr = driver.getCurrentUrl();
Cookie sessionStateCookie = driver.manage().getCookieNamed("session_state");
String sessionState = null;
if (sessionStateCookie != null) {
sessionState = sessionStateCookie.getValue();
}
System.out.println("authenticateResourceOwnerAndDenyAccess: sessionState:" + sessionState);
stopSelenium();
AuthorizationResponse authorizationResponse = new AuthorizationResponse(authorizationResponseStr);
if (authorizationRequest.getRedirectUri() != null && authorizationRequest.getRedirectUri().equals(authorizationResponseStr)) {
authorizationResponse.setResponseMode(ResponseMode.FORM_POST);
}
authorizationResponse.setSessionState(sessionState);
authorizeClient.setResponse(authorizationResponse);
showClientUserAgent(authorizeClient);
return authorizationResponse;
}
use of org.openqa.selenium.Cookie in project oxAuth by GluuFederation.
the class BaseTest method authorizationRequestAndDenyAccess.
public AuthorizationResponse authorizationRequestAndDenyAccess(String authorizeUrl, AuthorizationRequest authorizationRequest) {
String authorizationRequestUrl = authorizeUrl + "?" + authorizationRequest.getQueryString();
AuthorizeClient authorizeClient = new AuthorizeClient(authorizeUrl);
authorizeClient.setRequest(authorizationRequest);
System.out.println("authorizationRequestAndDenyAccess: authorizationRequestUrl:" + authorizationRequestUrl);
startSelenium();
driver.navigate().to(authorizationRequestUrl);
WebElement doNotAllowButton = driver.findElement(By.name(authorizeFormDoNotAllowButton));
final String previousURL = driver.getCurrentUrl();
doNotAllowButton.click();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return (d.getCurrentUrl() != previousURL);
}
});
String authorizationResponseStr = driver.getCurrentUrl();
Cookie sessionStateCookie = driver.manage().getCookieNamed("session_state");
String sessionState = null;
if (sessionStateCookie != null) {
sessionState = sessionStateCookie.getValue();
}
System.out.println("authorizationRequestAndDenyAccess: sessionState:" + sessionState);
stopSelenium();
AuthorizationResponse authorizationResponse = new AuthorizationResponse(authorizationResponseStr);
if (authorizationRequest.getRedirectUri() != null && authorizationRequest.getRedirectUri().equals(authorizationResponseStr)) {
authorizationResponse.setResponseMode(ResponseMode.FORM_POST);
}
authorizeClient.setResponse(authorizationResponse);
showClientUserAgent(authorizeClient);
return authorizationResponse;
}
use of org.openqa.selenium.Cookie in project oxAuth by GluuFederation.
the class BaseTest method authorizationRequestAndGrantAccess.
public AuthorizationResponse authorizationRequestAndGrantAccess(String authorizeUrl, AuthorizationRequest authorizationRequest) {
String authorizationRequestUrl = authorizeUrl + "?" + authorizationRequest.getQueryString();
AuthorizeClient authorizeClient = new AuthorizeClient(authorizeUrl);
authorizeClient.setRequest(authorizationRequest);
System.out.println("authorizationRequestAndGrantAccess: authorizationRequestUrl:" + authorizationRequestUrl);
startSelenium();
driver.navigate().to(authorizationRequestUrl);
String authorizationResponseStr = driver.getCurrentUrl();
WebElement allowButton = driver.findElement(By.name(authorizeFormAllowButton));
final String previousURL = driver.getCurrentUrl();
allowButton.click();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return (d.getCurrentUrl() != previousURL);
}
});
authorizationResponseStr = driver.getCurrentUrl();
Cookie sessionStateCookie = driver.manage().getCookieNamed("session_state");
String sessionState = null;
if (sessionStateCookie != null) {
sessionState = sessionStateCookie.getValue();
}
System.out.println("authorizationRequestAndGrantAccess: sessionState:" + sessionState);
stopSelenium();
AuthorizationResponse authorizationResponse = new AuthorizationResponse(authorizationResponseStr);
if (authorizationRequest.getRedirectUri() != null && authorizationRequest.getRedirectUri().equals(authorizationResponseStr)) {
authorizationResponse.setResponseMode(ResponseMode.FORM_POST);
}
authorizeClient.setResponse(authorizationResponse);
showClientUserAgent(authorizeClient);
return authorizationResponse;
}
use of org.openqa.selenium.Cookie in project ghostdriver by detro.
the class CookieTest method modifyingACookie.
@Test
public void modifyingACookie() {
server.setHttpHandler("GET", COOKIE_SETTING_CALLBACK);
goToPage();
driver.manage().addCookie(new Cookie("test", "newValue", ".localhost", "/", null, false));
assertEquals(2, getCookies().length);
Cookie cookie = driver.manage().getCookieNamed("test");
assertEquals("test", cookie.getName());
assertEquals("newValue", cookie.getValue());
assertEquals(".localhost", cookie.getDomain());
assertEquals("/", cookie.getPath());
assertEquals(false, cookie.isSecure());
cookie = driver.manage().getCookieNamed("test2");
assertEquals("test2", cookie.getName());
assertEquals("test2", cookie.getValue());
assertEquals(".localhost", cookie.getDomain());
assertEquals("/", cookie.getPath());
assertEquals(false, cookie.isSecure());
}
use of org.openqa.selenium.Cookie in project ghostdriver by detro.
the class CookieTest method shouldBeAbleToCreateCookieViaJavascriptOnGoogle.
@Test
public void shouldBeAbleToCreateCookieViaJavascriptOnGoogle() {
String ckey = "cookiekey";
String cval = "cookieval";
WebDriver d = getDriver();
d.get("http://www.google.com");
JavascriptExecutor js = (JavascriptExecutor) d;
// Of course, no cookie yet(!)
Cookie c = d.manage().getCookieNamed(ckey);
assertNull(c);
// Attempt to create cookie on multiple Google domains
js.executeScript("javascript:(" + "function() {" + " cook = document.cookie;" + " begin = cook.indexOf('" + ckey + "=');" + " var val;" + " if (begin !== -1) {" + " var end = cook.indexOf(\";\",begin);" + " if (end === -1)" + " end=cook.length;" + " val=cook.substring(begin+11,end);" + " }" + " val = ['" + cval + "'];" + " if (val) {" + " var d=Array('com','co.jp','ca','fr','de','co.uk','it','es','com.br');" + " for (var i = 0; i < d.length; i++) {" + " document.cookie = '" + ckey + "='+val+';path=/;domain=.google.'+d[i]+'; ';" + " }" + " }" + "})();");
c = d.manage().getCookieNamed(ckey);
assertNotNull(c);
assertEquals(cval, c.getValue());
// Set cookie as empty
js.executeScript("javascript:(" + "function() {" + " var d = Array('com','co.jp','ca','fr','de','co.uk','it','cn','es','com.br');" + " for(var i = 0; i < d.length; i++) {" + " document.cookie='" + ckey + "=;path=/;domain=.google.'+d[i]+'; ';" + " }" + "})();");
c = d.manage().getCookieNamed(ckey);
assertNotNull(c);
assertEquals("", c.getValue());
}
Aggregations