use of com.wikia.webdriver.common.core.helpers.User 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 com.wikia.webdriver.common.core.helpers.User in project selenium-tests by Wikia.
the class BrowserAndTestEventListener method afterNavigateTo.
@Override
public void afterNavigateTo(String url, WebDriver driver) {
Method method = TestContext.getCurrentTestMethod();
if (method != null) {
Class<?> declaringClass = method.getDeclaringClass();
String cookieDomain = String.format(".%s", Configuration.getEnvType().getDomain(driver.getCurrentUrl()));
Date cookieDate = new Date(new DateTime().plusYears(10).getMillis());
if (!AlertHandler.isAlertPresent(driver)) {
String command = "Url after navigation";
if (url.equals(driver.getCurrentUrl())) {
Log.ok(command, VelocityWrapper.fillLink(driver.getCurrentUrl(), driver.getCurrentUrl()));
} else {
// A fast lane to stop executing any test on "not a valid community" page
if (driver.getCurrentUrl().contains(URLsContent.NOT_A_VALID_COMMUNITY)) {
throw new SkipException(String.format("Wrong redirect to: %s", driver.getCurrentUrl()));
}
if (driver.getCurrentUrl().contains("data:text/html,chromewebdata ")) {
driver.get(url);
Log.warning(command, driver.getCurrentUrl());
} else {
Log.warning(command, driver.getCurrentUrl());
}
}
} else {
Log.warning("Url after navigation", "Unable to check URL after navigation - alert present");
}
boolean reload = false;
if (driver.getCurrentUrl().contains(cookieDomain)) {
// HACK FOR DISABLING NOTIFICATIONS
try {
new JavascriptActions(driver).execute("$('.wds-banner-notification__close').click()");
new JavascriptActions(driver).execute("$('#WikiaNotifications .sprite.close-notification').click()");
} catch (WebDriverException e) {
Log.info("Hack for disabling notifications", "Failed to execute js action");
}
if (TestContext.isFirstLoad()) {
boolean userOptedIn = true;
boolean userOptedOut = false;
try {
JavascriptExecutor js = DriverProvider.getActiveDriver();
Object mobileWikiVersion = js.executeScript("return requirejs.entries['mobile-wiki/config/environment'].module.exports.default.APP.version");
Configuration.setTestValue("mobileWikiVersion", mobileWikiVersion.toString());
} catch (WebDriverException e) {
Configuration.setTestValue("mobileWikiVersion", null);
}
if (method.isAnnotationPresent(Execute.class) && !method.getAnnotation(Execute.class).trackingOptIn()) {
userOptedIn = false;
}
if (method.isAnnotationPresent(Execute.class) && method.getAnnotation(Execute.class).trackingOptOut()) {
userOptedOut = true;
}
String cmpVersion = "2";
if (userOptedIn) {
driver.manage().addCookie(new Cookie("tracking-opt-in-status", "accepted", cookieDomain, "/", cookieDate));
driver.manage().addCookie(new Cookie("tracking-opt-in-version", cmpVersion, cookieDomain, "/", cookieDate));
reload = true;
} else if (userOptedOut) {
driver.manage().addCookie(new Cookie("tracking-opt-in-status", "rejected", cookieDomain, "/", cookieDate));
driver.manage().addCookie(new Cookie("tracking-opt-in-version", cmpVersion, cookieDomain, "/", cookieDate));
reload = true;
}
}
/**
* 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 (TestContext.isFirstLoad() && "true".equals(Configuration.getDisableCommunityPageSalesPitchDialog())) {
driver.manage().addCookie(new Cookie("cpBenefitsModalShown", "1", cookieDomain, "/", cookieDate));
reload = true;
}
if (TestContext.isFirstLoad() && "true".equals(Configuration.getMockAds())) {
driver.manage().addCookie(new Cookie("mock-ads", XMLReader.getValue("mock.ads_token"), cookieDomain, "/", cookieDate));
reload = true;
Log.info(String.format("Adding moc-ads cookie with value: %s, and domain: %s", XMLReader.getValue("mock.ads_token"), String.format(".%s", Configuration.getEnvType().getDomain(driver.getCurrentUrl()))));
}
}
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);
}
NetworkTrafficInterceptor networkTrafficInterceptor = DriverProvider.getActiveDriver().getProxy();
if (networkTrafficInterceptor != null) {
networkTrafficInterceptor.startIntercepting();
}
}
if (reload) {
driver.navigate().refresh();
}
}
Log.logJSError();
}
use of com.wikia.webdriver.common.core.helpers.User in project selenium-tests by Wikia.
the class UpvotingTests method setUp.
@BeforeSuite
private void setUp() {
User user = User.USER_5;
String siteId = Utils.extractSiteIdFromWikiName("qadiscussions", "de");
existingPost = DiscussionsClient.using(user, driver).createPostWithUniqueData(siteId);
DiscussionsClient.using(user, driver).createReplyToPost(siteId, existingPost);
}
Aggregations