Imitate network glitches

We have been utilizing the protractor tool for end-to-end testing for quite some time.

Currently, we are exploring various corner cases that involve modifying the responses from API endpoint requests. To achieve this, we are utilizing protractor-http-mock, which offers a convenient method to replace HTTP responses with predefined mocks.

However, what if we need to test a scenario where a sudden loss of connection occurs? What options do we have in such a situation?

In essence, we aim to create a situation where requests to specific endpoints result in a network connection error, allowing us to observe how our application responds.


I am open to suggestions, and I am currently considering the following strategies:

  • Exploring third-party Node.js libraries similar to protractor-http-mock
  • Mocking the $http AngularJS service
  • Utilizing a proxy and finding a way to control it during tests (considering grunt-connect-proxy, which seems mature, but unsure about dynamically changing its behavior per test)
  • Managing it at a browser level - for example, using the Network Throttling feature in Google Chrome (though, it seems Selenium may not have control over this, see Network throttling with Chrome and Selenium) (considering a browser add-on/extension)

Answer №1

It appears that the Comcast tool is well-equipped to fulfill the majority of your functional needs:

Comcast is designed to mimic typical network issues such as latency, bandwidth restrictions, and dropped/reordered/corrupted packets.

The tool operates by utilizing system tools in a portable manner. For BSD-based systems like OSX, it incorporates tools like ipfw and pfctl for inducing failures. On Linux, iptables and tc are employed. Comcast essentially acts as a simplified interface for these controls.

https://github.com/tylertreat/Comcast

Here's an example of its usage on Linux:

comcast --device=eth0 --latency=250 --target-bw=1000 --default-bw=1000000 --packet-loss=10% --target-addr=8.8.8.8,10.0.0.0/24 --target-proto=tcp,udp,icmp --target-port=80,22,1000:2000

You have the flexibility to adjust the settings in real-time and increase packet loss up to 100% as necessary.

Answer №2

If you're looking for guidance on implementing mocks, I hope this can point you in the right direction.

While the project provides a general overview, there may be some semantic and translation issues in the readme.md file, which I plan to address soon. Please bear with me as I work on this. If you notice any errors in my English or spelling, please feel free to let me know.

I recently worked on a demonstration project showcasing how to integrate Protractor + CucumberJS + sugar-step. The project currently features a basic Angular app and three E2E tests.

Although the demo is functional, it is still unfinished and requires additional features that I believe would enhance E2E Testing.

  • The first test compares a service against a default service (mock for Dev environment)
  • The second test verifies that the service request returns an error with a status code of 404
  • The third test confirms that the service request returns an error with a status code of 500

How can different mock responses be set for each scenario?

  • One approach is to utilize Cucumber's Around feature, which can inject a
    angular.module('mock-Service-response-x',fn...)
    before any feature or scenario, removing it once the feature or scenario has run

What can be tested using this method?

  • A wide range of scenarios, including responses with significant delays, any status code responses, and specialized data for testing unique scenarios that would be challenging to simulate using a traditional backend service

Why opt for AngularJS for UI-Mocks instead of a proxy?

  • UI Control (based on specific needs), with Angular enabling actions like disabling ngAnimations or jQuery animations entirely, and simulating local browser time with Date to replicate date-dependent behaviors automatically.

  • Cost (depending on the project), as setting up a local proxy for all web services on every development environment can be resource-intensive (in terms of hardware, effort, or implementation time).

  • Dependency, where parallel working by development teams may lead to interdependence, allowing the UI team to create simple mocks based on known implementation specifics of required web services, facilitating progress even if other layers are delayed in their respective feature development

These considerations vary based on the project at hand and do not signify the definitive solution, but personally, I advocate for maintaining independent layers within a project to facilitate timely feature releases in any one layer, regardless of delays in others.

To all readers, I welcome any comments, corrections, or suggestions you may have.

Answer №3

Is there a specific method you plan to use for this task? Perhaps a programmatically driven approach?

If that is the case, the ideal solution would involve utilizing a proxy, with a recommended tool like browserMobProxy which works seamlessly with selenium/webdriver tools.

If you prefer an external approach, consider utilizing external Traffic shapers or proxies. For example: and

vaurien --protocol http --proxy nonexistingproxy.com:8000 --backend website.com:80

Why avoid using browser capabilities? Firstly, you would need to reload the page to enact them and secondly, you would not be able to redefine the proxy settings in protractor. Regarding plugins, it can be challenging to interact with them programmatically without significant benefits, especially when dealing with multiple browsers.

Answer №4

Facebook has developed a tool called ATC, which stands for Augmented Traffic Control. This tool is used to simulate network conditions.

ATC allows users to manipulate bandwidth, latency, packet loss, and packet corruption rates within their network.

Because ATC is an open-source tool, there is potential to customize it further by creating different "error" profiles or integrating it with tools like Webdriver.

For more information about ATC, visit this link. The ATC GitHub repository can be found here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display only alphabetic characters in the text field

I have a jQuery function that I am working on: $('#contact_name').on('input', function() { var input=$(this); var re =/^[A-Za-z]+$/; var is_email=re.test(input.val()); if(is_email) { } else { } }); This function is targeted at the fol ...

Is there a way to utilize a POST request to pass a React component from server.js to App.js for rendering?

I am new to React and JavaScript and still in the learning process :) I'm working on a magic 8 ball application where, upon clicking the button using the post method, I aim to retrieve a random answer (one of the 20 in my server.js) back to the same ...

When referencing a particular React commit in package.json, it may result in the installation of react-tools instead of react itself

After including the following line in my package.json: "react": "git://github.com/facebook/react.git#08e4420019f74b7c93e64f59c443970359102530" When I execute npm install, I notice that node_modules/react-tools has been installed instead of node_modules/r ...

The child division was not dynamically included

My HTML code currently looks like this: <div class="horizontal-double-large pink" data-title="health" data-legend-one="medical" data-legend-two="natural"> <div class="horizontal-double-element" data-name="India" data-one="40" data- ...

What is the best approach to dealing with "Cannot <METHOD> <ROUTE>" errors in Express?

Here is a simple example to illustrate the issue: var express = require('express'); var bodyparser = require('body-parser'); var app = express(); app.use(bodyparser.json()); app.use(errorhandler); function errorhandler(err, req, res, ...

Displaying iterative content using Vue.js from an array of items

Looking to style questions and answers differently when rendering them. The data structure is as follows: dialogTut:{ mainTab:{ q:"data with 42 people?", a:"hehe", q:"Are awesome people?", a:"sometimes", ...

The navigation underline stays in place even after being clicked, and also appears below

Take a look at this js fiddle I've managed to create the underline effect on the navigation links when the user hovers over them. However, the underline only stays visible until the user clicks elsewhere on the screen. How can I make it persist as l ...

Arrange the JSONB data type with sequelize literal in your order

My current approach involves querying for all items using the following structure: const filteredItems = await allItems.findAll({ where: conditions, include: associations, order: sortingCriteria, limit: limit, o ...

"Timed out connection following the upload of a file in Laravel and subsequent

In a custom order management system built with Laravel, users have the ability to upload files related to their orders. These files are submitted via an ajax call and handled by a Laravel controller before the page is refreshed. The issue I'm facing ...

typescript - transforming text into numerical values

newbalance = (Number(this.balance)) + (Number(this.pastAmount)); The result for my newbalance calculation is coming back as undefined, even though this.balance is 34 and this.pastAmount is 23. I've set this up in the controller and I'm trying t ...

Receiving partial data through the API

My PHP API seems to be experiencing issues when I send data to it using either a post or get request. The strange thing is that the API receives only half of the data. This API functions perfectly fine on localhost, but encounters errors when used on the p ...

AngularJS textbox validation for numbers and required in repeating mode ensures that the user input is a

For more information, please visit the following link: https://plnkr.co/edit/9HbLMBUw0Q6mj7oyCahP?p=preview var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.NDCarray = [{val: '' ...

Oops! Looks like there's a type error in module "*.mdx" - it seems that it doesn't have the exported member "metadata". Maybe try using "import metadata from "*.mdx"" instead?

I am attempting to extract metadata from an mdx file. I have followed the guidelines outlined in NextJS Markdown Frontmatter, but encountered build errors. It is important to note that I am unable to utilize fs. Code Section Page.tsx File import Conte ...

Tips for adding elements to an angular $scope.array?

Currently, I am facing an issue that I cannot seem to pinpoint (most likely due to my limited expertise in AngularJS). In my HTML file, I have a basic ng-repeat set up like this: <ul> <li ng-repeat="fot in fotografia"><img src="{{fot.path ...

Modify Knockout applyBindings to interpret select choices as numeric values

Utilizing Knockout alongside html select / option (check out Fiddle): <select data-bind="value: Width"> <option>10</option> <option>100</option> </select> Upon invoking applyBindings, the options are interprete ...

Issue: In Firefox, resizing elements using position:absolute does not work as expected

My resizable div code looks like this: #box { height: 10rem; width: 10rem; resize: both; overflow: hidden; border: solid black 0.5rem; position: absolute; pointer-events: none; } <div id="item"></div> While it works perfectly ...

Tips for finding and selecting the "speed test" link on Netflix with the help of Selenium in Python

I'm new to using selenium and may have a basic question (it happens):) I am trying to locate the Speed test link on and then click on it. I have attempted different search methods like text searching, but nothing seems to be working for me, and I&ap ...

What could be causing this issue of the Angular Material table not displaying properly?

I have been developing a Contacts application using Angular 9 and Angular Material. The goal is to display contact information and an image for each contact in a table row within the list component. Within my app.module.ts, I have imported various modules ...

Setting up Access-Control-Allow-Origin in WildFly 8.1.0 configuration

I am attempting to configure Access-Control-Allow-Origin on a Wildfly 8.1.0 server using the standalone.xml file provided below: <?xml version='1.0' encoding='UTF-8'?> <server xmlns="urn:jboss:domain:2.1"> <extensio ...