use of org.openqa.selenium.Cookie in project selenium-tests by Wikia.
the class PageObjectLogging method afterNavigateTo.
@Override
public void afterNavigateTo(String url, WebDriver driver) {
StringBuilder builder = new StringBuilder();
if (!AlertHandler.isAlertPresent(driver)) {
if (url.equals(driver.getCurrentUrl())) {
builder.append("<tr class=\"success\"><td>Url after navigation</td><td>" + "<a href='" + driver.getCurrentUrl() + "'>" + driver.getCurrentUrl() + "</a></td><td> <br/> </td></tr>");
CommonUtils.appendTextToFile(logPath, builder.toString());
} else {
if (driver.getCurrentUrl().contains("data:text/html,chromewebdata ")) {
driver.get(url);
}
logWarning("Url after navigation", driver.getCurrentUrl());
}
} else {
logWarning("Url after navigation", "Unable to check URL after navigation - alert present");
}
if (driver.getCurrentUrl().contains(Configuration.getWikiaDomain())) {
// HACK FOR DISABLING NOTIFICATIONS
try {
new JavascriptActions(driver).execute("$(\".sprite.close-notification\")[0].click()");
} catch (WebDriverException e) {
}
/**
* We want to disable sales pitch dialog for new potential contributors to avoid hiding other
* UI elements. see https://wikia-inc.atlassian.net/browse/CE-3768
*/
if ("true".equals(Configuration.getDisableCommunityPageSalesPitchDialog())) {
driver.manage().addCookie(new Cookie("cpBenefitsModalShown", "1", Configuration.getWikiaDomain(), null, null));
}
if (TestContext.isFirstLoad() && "true".equals(Configuration.getMockAds())) {
driver.manage().addCookie(new Cookie("mock-ads", XMLReader.getValue("mock.ads_token"), String.format(".%s", Configuration.getEnvType().getWikiaDomain()), null, null));
}
}
Method method = TestContext.getCurrentTestMethod();
Class<?> declaringClass = method.getDeclaringClass();
if (TestContext.isFirstLoad()) {
User user = null;
TestContext.setFirstLoad(false);
if (declaringClass.isAnnotationPresent(Execute.class)) {
user = declaringClass.getAnnotation(Execute.class).asUser();
}
if (method.isAnnotationPresent(Execute.class)) {
user = method.getAnnotation(Execute.class).asUser();
}
if (user != null && user != User.ANONYMOUS) {
// log in, make sure user is logged in and flow is on the requested url
new WikiBasePageObject().loginAs(user);
}
}
logJSError(driver);
}
use of org.openqa.selenium.Cookie in project selenium-tests by Wikia.
the class WikiBasePageObject method loginAs.
public String loginAs(String userName, String password, String wikiURL) {
String token = Helios.getAccessToken(userName, password);
driver.manage().addCookie(new Cookie("access_token", token, String.format(".%s", Configuration.getEnvType().getWikiaDomain()), null, null));
if (driver.getCurrentUrl().contains("Logout")) {
driver.get(wikiURL);
} else {
refreshPageAddingCacheBuster();
}
this.verifyUserLoggedIn(userName);
PageObjectLogging.log("loginCookie", "user was logged in by by helios using access token: " + token, true);
logMercuryUserId();
return token;
}
use of org.openqa.selenium.Cookie in project ats-framework by Axway.
the class AbstractHtmlEngine method setCookie.
/**
*
* @param cookieName the name of the cookie. May not be null or an empty string.
* @param cookieValue the cookie value. May not be null.
*/
@PublicAtsApi
public void setCookie(String cookieName, String cookieValue) {
Cookie cookie = new Cookie(cookieName, cookieValue);
webDriver.manage().addCookie(cookie);
}
use of org.openqa.selenium.Cookie in project ats-framework by Axway.
the class AbstractHtmlEngine method getCookies.
/**
* Get all the cookies for the current domain. This is the equivalent of calling "document.cookie" and parsing the result
*
* @return {@link com.axway.ats.uiengine.elements.html.Cookie Cookie}s array
*/
@PublicAtsApi
public com.axway.ats.uiengine.elements.html.Cookie[] getCookies() {
Set<Cookie> cookies = webDriver.manage().getCookies();
com.axway.ats.uiengine.elements.html.Cookie[] cookiesArr = new com.axway.ats.uiengine.elements.html.Cookie[cookies.size()];
int i = 0;
for (Cookie c : cookies) {
cookiesArr[i++] = new com.axway.ats.uiengine.elements.html.Cookie(c.getName(), c.getValue(), c.getDomain(), c.getPath(), c.getExpiry(), c.isSecure());
}
return cookiesArr;
}
use of org.openqa.selenium.Cookie in project ats-framework by Axway.
the class AbstractHtmlEngine method setCookie.
/**
*
* @param name the name of the cookie. May not be null or an empty string.
* @param value the cookie value. May not be null.
* @param domain the domain the cookie is visible to.
* @param path the path the cookie is visible to. If left blank or set to null, will be set to
* "/".
* @param expiry the cookie's expiration date; may be null.
* @param isSecure whether this cookie requires a secure connection.
*/
@PublicAtsApi
public void setCookie(String name, String value, String domain, String path, Date expiry, boolean isSecure) {
Cookie cookie = new Cookie(name, value, domain, path, expiry, isSecure);
webDriver.manage().addCookie(cookie);
}
Aggregations