use of com.wikia.webdriver.common.core.networktrafficinterceptor.NetworkTrafficInterceptor 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.networktrafficinterceptor.NetworkTrafficInterceptor in project selenium-tests by Wikia.
the class BrowserAbstract method setProxy.
/**
* Set Proxy instance for a Browser instance
*/
protected void setProxy() {
if (Configuration.useProxy()) {
Proxy proxyServer = new Proxy();
if ("true".equals(Configuration.useZap())) {
String zapProxyAddress = String.format("%s:%s", XMLReader.getValue("zap_proxy.address"), Integer.parseInt(XMLReader.getValue("zap_proxy.port")));
proxyServer.setHttpProxy(zapProxyAddress);
proxyServer.setSslProxy(zapProxyAddress);
} else {
server = new NetworkTrafficInterceptor();
server.setTrustAllServers(true);
server.setConnectTimeout(90, TimeUnit.SECONDS);
server.setMitmDisabled(!Boolean.parseBoolean(Configuration.useMITM()));
server.setRequestTimeout(90, TimeUnit.SECONDS);
server.enableHarCaptureTypes(CaptureType.REQUEST_HEADERS, CaptureType.RESPONSE_HEADERS);
server.setUseEcc(true);
proxyServer = server.startBrowserMobProxyServer();
}
caps.setCapability(CapabilityType.PROXY, proxyServer);
}
}
Aggregations