Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added JsSniffer to check web trends for Https requests

  • Loading branch information...
commit 222e2c93fe8e2405613fb0f758cfb11de584e0d4 1 parent 2396176
@singhalmansi7 singhalmansi7 authored
View
BIN  docs/WAAT Readme.doc
Binary file not shown
View
10 src/com/thoughtworks/webanalyticsautomation/Engine.java
@@ -50,7 +50,7 @@ public void disableWebAnalyticsTesting() {
threadLocal.set(null);
enableDisableCaptureInHttpSnifferPluginInstance(false);
}
-
+
public Result verifyWebAnalyticsData(String testDataFileName, String actionName, ScriptRunner scriptRunner) {
if (isWebAnalyticsTestingEnabled()) {
ArrayList<Section> expectedSectionList = TestData.getSectionsFor(testDataFileName, actionName);
@@ -175,4 +175,12 @@ private void enableDisableCaptureInHttpSnifferPluginInstance(boolean enable) {
}
}
}
+
+ public Result verifyWebAnalyticsData(String inputDataFileName, String actionName, String url) {
+ ArrayList<Section> expectedSectionList = TestData.getSectionsFor(inputDataFileName, actionName);
+ WaatPlugin pluginInstance = PluginFactory.getWebAnalyticsPluginInstance(Config.getWEB_ANALYTIC_TOOL());
+ ArrayList<Section> actualSectionList = pluginInstance.captureSections(url);
+ return verifyWebAnalyticsData(actionName, actualSectionList, expectedSectionList);
+ }
+
}
View
5 src/com/thoughtworks/webanalyticsautomation/plugins/HttpSniffer.java
@@ -43,6 +43,11 @@ public void receivePacket(Packet packet) {
return null;
}
+ public ArrayList<Section> captureSections(String url) {
+ logger.info ("ERROR - INVALID API CALLED ON HttpSniffer Plugin");
+ return null;
+ }
+
public ArrayList<Section> captureSections(String[] urlPatterns, int minimumNumberOfPacketsToCapture) {
return processCapturedPackets(urlPatterns, minimumNumberOfPacketsToCapture);
}
View
33 src/com/thoughtworks/webanalyticsautomation/plugins/JsSniffer.java
@@ -0,0 +1,33 @@
+package com.thoughtworks.webanalyticsautomation.plugins;
+
+import com.thoughtworks.webanalyticsautomation.common.Utils;
+import com.thoughtworks.webanalyticsautomation.inputdata.Section;
+import com.thoughtworks.webanalyticsautomation.scriptrunner.ScriptRunner;
+
+import java.util.ArrayList;
+
+public class JsSniffer implements WaatPlugin {
+ private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(HttpSniffer.class.getName());
+ public ArrayList<Section> captureSections(ScriptRunner scriptRunner) {
+ logger.info("ERROR - INVALID API CALLED ON JsSniffer Plugin");
+ return null;
+ }
+
+ public ArrayList<Section> captureSections(String url) {
+ ArrayList<Section> processedPackets = new ArrayList<Section>();
+ processedPackets.add(convertToSection(url));
+ return processedPackets;
+
+ }
+
+ private Section convertToSection(String url) {
+ url = url.replaceAll("&", Utils.TEST_DATA_DELIMITER);
+ logger.debug ("Converted tag list: " + url);
+ return new Section("", url);
+ }
+
+ public ArrayList<Section> captureSections(String[] urlPatterns, int minimumNumberOfPackets) {
+ logger.info("ERROR - INVALID API CALLED ON HttpSniffer Plugin");
+ return null;
+ }
+}
View
5 src/com/thoughtworks/webanalyticsautomation/plugins/OmnitureDebugger.java
@@ -34,6 +34,11 @@ public OmnitureDebugger() {
return parseOmnitureDebuggerSections (sSource);
}
+ public ArrayList<Section> captureSections(String url) {
+ logger.info ("ERROR - INVALID API CALLED ON OMNITURE DEBUGGER Plugin");
+ return null;
+ }
+
public ArrayList<Section> captureSections(String[] urlPatterns, int minimumNumberOfPackets) {
logger.info ("ERROR - INVALID API CALLED ON OmnitureDebugger Plugin");
return null;
View
3  src/com/thoughtworks/webanalyticsautomation/plugins/PluginFactory.java
@@ -30,6 +30,9 @@ else if (webAnalyticTool.equals(WebAnalyticTool.HTTP_SNIFFER)) {
}
return httpSniffer;
}
+ else if (webAnalyticTool.equals(WebAnalyticTool.JS_SNIFFER)){
+ return new JsSniffer();
+ }
else {
throw new IllegalArgumentException("Invalid type of Web Analytic Tool (" + webAnalyticTool + ") specified");
}
View
3  src/com/thoughtworks/webanalyticsautomation/plugins/WaatPlugin.java
@@ -16,5 +16,8 @@
public interface WaatPlugin {
public ArrayList<Section> captureSections(ScriptRunner scriptRunner);
+
+ public ArrayList<Section> captureSections(String url);
+
public ArrayList<Section> captureSections(String[] urlPatterns, int minimumNumberOfPackets);
}
View
4 src/com/thoughtworks/webanalyticsautomation/plugins/WebAnalyticTool.java
@@ -5,10 +5,10 @@
* Email: abagmar@gmail.com
* Date: Dec 29, 2010
* Time: 9:34:02 AM
- *
+ * <p/>
* Copyright 2010 Anand Bagmar (abagmar@gmail.com). Distributed under the Apache 2.0 License
*/
public enum WebAnalyticTool {
- OMNITURE_DEBUGGER, HTTP_SNIFFER
+ HTTP_SNIFFER, JS_SNIFFER, OMNITURE_DEBUGGER,
}
View
12 test/com/thoughtworks/webanalyticsautomation/samples/HttpSnifferSampleTest.java
@@ -1,6 +1,5 @@
package com.thoughtworks.webanalyticsautomation.samples;
-import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.webanalyticsautomation.Engine;
import com.thoughtworks.webanalyticsautomation.Result;
import com.thoughtworks.webanalyticsautomation.Status;
@@ -9,7 +8,6 @@
import com.thoughtworks.webanalyticsautomation.common.Utils;
import com.thoughtworks.webanalyticsautomation.inputdata.InputFileType;
import com.thoughtworks.webanalyticsautomation.plugins.WebAnalyticTool;
-import com.thoughtworks.webanalyticsautomation.scriptrunner.helper.SeleniumScriptRunnerHelper;
import com.thoughtworks.webanalyticsautomation.scriptrunner.helper.WebDriverScriptRunnerHelper;
import org.apache.log4j.Logger;
import org.openqa.selenium.WebDriver;
@@ -47,7 +45,7 @@
public void captureAndVerifyDataReportedToWebAnalytics_HTTPSniffer_GoogleAnalytics_Selenium_Firefox() throws Exception {
String baseURL = "http://essenceoftesting.blogspot.com";
String navigateToURL = baseURL + "/2011/01/my-article-on-future-of-test-automation.html";
- String[] urlPatterns = new String[] {"GET /ps/ifr?container=friendconnect&mid=0"};
+ String[] urlPatterns = new String[] {"action=backlinks&widgetId"};
int minimumNumberOfPackets = 1;
engine = getInstance(webAnalyticTool, inputFileType, keepLoadedFileInMemory, log4jPropertiesAbsoluteFilePath);
@@ -55,8 +53,10 @@ public void captureAndVerifyDataReportedToWebAnalytics_HTTPSniffer_GoogleAnalyti
startWebDriver(BROWSER.firefox, baseURL);
driverInstance.get(navigateToURL);
-
- Result verificationResult = engine.verifyWebAnalyticsData (inputDataFileName, actionName, urlPatterns, minimumNumberOfPackets);
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) { }
+ Result verificationResult = engine.verifyWebAnalyticsData(inputDataFileName, actionName, urlPatterns, minimumNumberOfPackets);
assertNotNull(verificationResult.getVerificationStatus(), "Verification status should NOT be NULL");
assertNotNull(verificationResult.getListOfErrors(), "Failure details should NOT be NULL");
@@ -75,5 +75,5 @@ private void startWebDriver(BROWSER browser, String baseURL) {
public void tearDown() throws Exception {
engine.disableWebAnalyticsTesting();
webDriverScriptRunnerHelper.stopDriver();
- }
+ }
}
View
75 test/com/thoughtworks/webanalyticsautomation/samples/JsSnifferSampleTest.java
@@ -0,0 +1,75 @@
+package com.thoughtworks.webanalyticsautomation.samples;
+
+import com.thoughtworks.webanalyticsautomation.Engine;
+import com.thoughtworks.webanalyticsautomation.Result;
+import com.thoughtworks.webanalyticsautomation.Status;
+import com.thoughtworks.webanalyticsautomation.common.BROWSER;
+import com.thoughtworks.webanalyticsautomation.common.TestBase;
+import com.thoughtworks.webanalyticsautomation.common.Utils;
+import com.thoughtworks.webanalyticsautomation.inputdata.InputFileType;
+import com.thoughtworks.webanalyticsautomation.plugins.WebAnalyticTool;
+import com.thoughtworks.webanalyticsautomation.scriptrunner.helper.WebDriverScriptRunnerHelper;
+import org.apache.log4j.Logger;
+import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.WebDriver;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+import static com.thoughtworks.webanalyticsautomation.Controller.getInstance;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+public class JsSnifferSampleTest extends TestBase {
+ private Logger logger = Logger.getLogger(getClass());
+ private Engine engine;
+ private WebAnalyticTool webAnalyticTool = WebAnalyticTool.JS_SNIFFER;
+ private InputFileType inputFileType = InputFileType.XML;
+ private boolean keepLoadedFileInMemory = true;
+ private String log4jPropertiesAbsoluteFilePath = Utils.getAbsolutePath(new String[]{"resources", "log4j.properties"});
+ private String inputDataFileName = Utils.getAbsolutePath(new String[]{"test", "sampledata", "TestData.xml"});
+ private String actionName = "OpenAMirenaSecureSite_JsSniffer";
+ private WebDriverScriptRunnerHelper webDriverScriptRunnerHelper;
+ private WebDriver driverInstance;
+ private static final String JS_FOR_MIRENA_SITE = "window.WAAT_URL=\"\";window.WebTrends.prototype.dcsTag=function(){if(document.cookie.indexOf(\"WTLOPTOUT=\")!=-1){return}var WT=this.WT;var DCS=this.DCS;var DCSext=this.DCSext;var i18n=this.i18n;var P=\"http\"+(window.location.protocol.indexOf('https:')==0?'s':'')+\"://\"+this.domain+(this.dcsid==\"\"?'':'/'+this.dcsid)+\"/dcs.gif?\";if(i18n){WT.dep=\"\"}for(var N in DCS){if(DCS[N]&&(typeof DCS[N]!=\"function\")){P+=this.dcsA(N,DCS[N])}}for(N in WT){if(WT[N]&&(typeof WT[N]!=\"function\")){P+=this.dcsA(\"WT.\"+N,WT[N])}}for(N in DCSext){if(DCSext[N]&&(typeof DCSext[N]!=\"function\")){if(i18n){WT.dep=(WT.dep.length==0)?N:(WT.dep+\";\"+N)}P+=this.dcsA(N,DCSext[N])}}if(i18n&&(WT.dep.length>0)){P+=this.dcsA(\"WT.dep\",WT.dep)}if(P.length>2048&&navigator.userAgent.indexOf('MSIE')>=0){P=P.substring(0,2040)+\"&WT.tu=1\"}this.dcsCreateImage(P);window.WAAT_URL=P;this.WT.ad=\"\"};_tag.dcsCustom=function(){}; _tag.DCS.dcscfg=\"1\"; _tag.dcsCollect();return window.WAAT_URL" ;
+
+
+ @Test
+ public void captureAndVerifyDataReportedToWebAnalytics_JsSniffer_Webtrends_Selenium_Firefox() throws Exception {
+ String baseURL = "https://www.mirena.com/en/home/index.php";
+ String navigateToURL = "https://www.mirena.com/en/privacy_statement_user.php";
+
+ engine = getInstance(webAnalyticTool, inputFileType, keepLoadedFileInMemory, log4jPropertiesAbsoluteFilePath);
+
+ startWebDriver(BROWSER.firefox, baseURL);
+ driverInstance.get(navigateToURL);
+
+ String url = extractUrlFromJavascript(JS_FOR_MIRENA_SITE);
+
+ Result verificationResult = engine.verifyWebAnalyticsData(inputDataFileName, actionName, url);
+
+ assertNotNull(verificationResult.getVerificationStatus(), "Verification status should NOT be NULL");
+ assertNotNull(verificationResult.getListOfErrors(), "Failure details should NOT be NULL");
+ logVerificationErrors(verificationResult);
+ Assert.assertEquals(verificationResult.getVerificationStatus(), Status.PASS, "Verification status should be PASS");
+ assertEquals(verificationResult.getListOfErrors().size(), 0, "Failure details should be empty");
+
+ }
+
+ private String extractUrlFromJavascript(String javascript) {
+ String url = (String) ((JavascriptExecutor) driverInstance).executeScript(javascript);
+ return url;
+ }
+
+ private void startWebDriver(BROWSER browser, String baseURL) {
+ webDriverScriptRunnerHelper = new WebDriverScriptRunnerHelper(logger, browser, baseURL);
+ webDriverScriptRunnerHelper.startDriver();
+ driverInstance = (WebDriver) webDriverScriptRunnerHelper.getDriverInstance();
+ }
+
+ @AfterMethod
+ public void tearDown() throws Exception {
+ webDriverScriptRunnerHelper.stopDriver();
+ }
+}
+
View
13 test/sampledata/TestData.xml
@@ -80,7 +80,12 @@
<Section actionName="OpenWAATArticleOnBlog_HttpSniffer"
numberOfEventsTriggered="1"
- tagList="caller=http://essenceoftesting.blogspot.com/2011/01/my-article-on-future-of-test-automation.html||
- container=friendconnect||
- parent=http://essenceoftesting.blogspot.com/||"/>
-</Sections>
+ tagList="action=backlinks||
+ widgetType=Blog||
+ responseType=js||"/>
+
+ <Section actionName="OpenAMirenaSecureSite_JsSniffer"
+ numberOfEventsTriggered="1"
+ tagList="dcssip=www.mirena.com||
+ dcsuri=/en/privacy_statement_user.php||"/>
+</Sections>
Please sign in to comment.
Something went wrong with that request. Please try again.