GithubHelp home page GithubHelp logo

network-request-counter's Introduction

Network Requests Counter Python 3.6

This is a utility written in python 3. Here this script can be used to Validate/View/count the Desired HTTP Requests and Responses sent between the Web browser and the Web server. So this can be used to check whether a web-application is firing all the necessary requests or not.

Motivation:

Testing is hard, but it pays back if done properly. Selenium gives you many tools to automatically test your web application on real browsers. One thing it doesn’t provide is the access to the browser’s network activity log. That leaves us with the mere ability to look at the HTML elements and trust that the network activity in the background is working as we’d expected. Earlier the process of counting the necessary network requests was implemented by using browsermobproxy utility. The browsermobproxy provides a HAR file which then has to be converted to JSON format inorder to view the network requests.This is another dependency for the project.

Built With:

Javascript-Resource Timing API

After some research, I found another way to implement this is by using javascript-Resource Timing API.So the main reason behind using this API is to eliminate the unnecessary code which was required to obtain a result from the browsermobproxy utility.This API provides a way to retrieve and analyze detailed network timing data regarding the loading of an application's resource(s). An application can use the timing metrics to determine, for example, the length of time it takes to fetch a specific resource such as an XMLHttpRequest, , image, script, etc.

Usage:

var resources = performance.getEntriesByType("resource");
var resources = window.performance.getEntriesByType("resource");

The resources is an array of PerformanceResourceTiming objects. The PerformanceResourceTiming object contains the URL of the requested resource, timing metrics and resource size data. The browser has a resource timing buffer to hold PerformanceResourceTiming objects. Whenever the browser starts to fetch a resource, it will create a new PerformanceResourceTiming object and store into the buffer until the buffer is full.

Steps performed by the script are as follows:

  1. Open a web-application /Webpage (here I have used Wikipedia webpage) mentioned in config file
  2. Use Selenium to perform operations like click on HTML elements, query the DOM structure,modify values,submitting a form,uploading a file etc.
  3. Fetch the network requests/url (conditions) from config file which you want to validate/count.
  4. Execute custom Javascript Resource Timing API using JavascriptExecutor, which will return all the network requests.
  5. Compare the network requests from step4 with the pre-defined network requests from step3.
  6. Mark the pre-defined request as PASS if it matches with any of the actual page requests.
  7. Mark the pre-defined Request as FAIL if it doesn't match with any of the actual page requests.
  8. Send an email report. Email Report

Getting Started:

Prerequisites:

  1. Python 3
  2. This project already has pipfile so go ahead and install all the dependencies from it . Use the below command:Install from Pipfile, if there is one: Please refer to link.
pipenv install

Customizations:

Config File: Please add the below configurations in Config.ini file
  1. Mention the URL where you want to validate the network requests:

    • Edit: website
  2. Add single or multiple expected network requests in Expected_network_requests section

    • Edit: Expected_network_requests
  3. Add the sender for email:

    • Edit: sender
  4. Add single or multiple receivers for email:

    • Edit: receiver
  5. Add email subject

    • Edit: receiver
Note:

we have two options for the sending the email

  1. Email module
  2. Boto3

How to run the script:

Here we have two options for setup.

  1. Set up a cron job daily (recommended).
  2. Run the script manually when it's needed.

network-request-counter's People

Contributors

rohit-medpalli123 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.