Skip to content

WAAT Ruby HttpSniffer

anandbagmar edited this page Nov 5, 2012 · 7 revisions

Approach

This is a *generic approach to Web Analytics Test Automation. Regardless of the end-product doing Web Analytics reporting and analysis (example: Omniture, Google Analytics, etc.), you can use this approach to test, in an automated way, if correct name/value properties are being reported by the product / system under test.

This approach captures TCP packets on the network layer, from all the network devices available. Based on the criteria specified in your tests, only those relevant packets are filtered out, and used for analysis and verifications.

Limitation

Because of the limitation listed in the FAQs about doing Web Analytic validation in a pure https environment, the HttpSniffer approach will not work in such a (pure-https) environment. An alternative is to use WAAT's JsSniffer plugin approach.

Setup 3rd-party libraries

In order to enable packet capturing, the WAAT framework needs helps of some 3-rd party open-source libraries. These libraries are available for various different operating systems in the download section of the WAAT project. If you have not yet setup Jpcap on your test execution machine, refer to the Jpcap Setup section for platform specific install instructions.

Define Test data

Provide the test data to be validated for each action in an xml file. See the Sample TestData XML file for reference.

Install WAAT-Ruby

WAAT-Ruby gem is available from www.rubygems.org. Add the following line in your Gemfile:

source "http://rubygems.org"
gem 'WAAT', '>= 1.4.0'

Use WAAT-Ruby in your framework

Install the latest version of WAAT from WAAT-Ruby pkg directory.

In your Test project's env.rb, or some such file, add this line:

require 'WAAT'

Test Changes

You can enable / disable WAAT in each test, or better way is to create custom hooks for this purpose.

The below example demonstrates the use of WAAT via custom hooks in a Cucumber-based Test Automation Framework.

Custom hook (using Cucumber project's example)

In your Test framework, create a file /features/support/hook.rb Add the following code in that file:

Before ('@waat') do
  puts "waat before hook"
  initialize_waat()
  enable_web_analytics_testing
 end

After ('@waat') do
  disable_web_analytics_testing
  puts "waat after hook"
end

Feature file changes

In your feature file, for tests that should also be doing Web Analytics testing, add a @waat annotation to them as shown below.

@waat
Scenario: Content is seen on home page - success test
  Given WAAT success test

Validating Web Analytics tags

For each location (you need to test) where test-actions trigger Web Analytics requests, do the following:

url_patterns = ["GET /ps/ifr?container=friendconnect&mid=0"]
test_data_file_name = File.join(File.dirname(__FILE__), "..", "..", "sampleData", "TestData.    
action_name = "WAAT_Success_Test"
minimum_number_of_packets = 1

#  Unless specified in hook.rb:
#  initialize_waat()
#  enable_web_analytics_testing

# Some test action triggering a Web Analytic request
# Example:

url = "http://essenceoftesting.blogspot.com"
@driver = Selenium::WebDriver.for :firefox
@driver.get url

# Verify Web Analytics Data sent to the Web Analytic tool
params = [:test_data_file_name=> test_data_file_name, 
          :action_name => action_name, 
          :url_patterns => url_patterns, 
          :minimum_number_of_packets => 1]
result = verify_web_analytics_data(params)

# Sample validations
assert (result.status=="FAIL"), "Incorrect Verification Status. Expected: 'FAIL', Actual: #{result.status}"
assert (result.list_of_errors.size==14), "Incorrect number of errors. Expected: '14', Actual: #{result.list_of_errors.size}"
result.list_of_errors.each do |err|
  puts "->\t#{err}"
end

#  Unless specified in hook.rb:
#  disable_web_analytics_testing

Opportunities for optimization

  • If the URL patterns (url_patterns) is going to be the same for all tests, then move its definition to a common place instead of defining it in each and every test.
  • If all test data is specified in the same XML file, then the input_data_file_name can also be specified once in some common place instead of defining it in each and every test.