Registry / testing / protractor-http-client

protractor-http-client

JSON →
library1.0.4jsnpmunverified

Protractor HTTP Client (npm package `protractor-http-client`) is a utility library designed to simplify making HTTP requests within Protractor end-to-end tests. It is currently at version 1.0.4, indicating a stable release, though the package has not seen updates since 2017. The library acts as a wrapper around the now-deprecated `request` package, allowing testers to perform GET, POST, PUT, DELETE, and other HTTP operations. Its primary differentiation lies in its tight integration with Protractor's control flow, ensuring that HTTP calls automatically resolve before subsequent Protractor `browser` or `element` commands are executed. This is particularly useful for setting up test data via REST APIs before a test runs, or for cleaning up resources after a test completes, avoiding manual promise handling common with plain `http` or `request` modules in a Protractor context.

npm install protractor-http-client
INSTALL
IMPORT
SIG · PROTRACTOR-HTTP-CL
P
protractor-http-client
testingjavascriptv1.0.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HttpClient
import { HttpClient } from 'protractor-http-client'
import HttpClient from 'protractor-http-client'
For ES Modules and TypeScript, `HttpClient` is a named export. For CommonJS, `const { HttpClient } = require('protractor-http-client');` is the idiomatic pattern, although `const HttpClient = require('protractor-http-client').HttpClient;` as shown in the README is also valid.
ResponsePromise, JsonPromise
import type { ResponsePromise, JsonPromise } from 'protractor-http-client'
import { ResponsePromise, JsonPromise } from 'protractor-http-client'
These are TypeScript interfaces/types for advanced type-checking of response objects. They should typically be imported using `import type` for clarity and to ensure they are not bundled as runtime values, especially if `isolatedModules` is enabled.

Demonstrates setting up and tearing down test data using HTTP requests before and after Protractor tests, and then interacting with the browser, leveraging the library's Protractor control flow integration to automatically await API calls.

import { HttpClient, ResponsePromise } from "protractor-http-client"; import { browser, by, element, expect } from "protractor"; // Assuming these are globally available or imported from 'protractor' // Instantiate the HTTP client with a base URL const http = new HttpClient("https://api.example.com/"); http.failOnError = true; // Recommend setting this to ensure API errors throw exceptions describe("the login page", () => { // Setup a user via API before each test beforeEach(async () => { const postResponse: ResponsePromise = http.post("/users", { username: "testuser", password: "securepassword" }); // protractor-http-client automatically waits for the promise to resolve expect(postResponse.statusCode).toEqual(200); // Verify creation was successful }); // Cleanup the user via API after each test afterEach(async () => { const deleteResponse: ResponsePromise = http.delete("/users/testuser"); expect(deleteResponse.statusCode).toEqual(200); // Verify deletion was successful }); it("will allow login with new user", async () => { // Now you can use the browser to login with the new user await browser.get("/login"); await element(by.id("username")).sendKeys("testuser"); await element(by.id("password")).sendKeys("securepassword"); await element(by.id("loginButton")).click(); // Assuming a login button // Assert successful login, e.g., URL change or element presence expect(await browser.getCurrentUrl()).toContain("/dashboard"); expect(await element(by.id("welcomeMessage")).getText()).toContain("Welcome, testuser"); }); });
Debug
Known issues
breakingThe underlying Protractor framework, which this library tightly integrates with, has been officially deprecated. While `protractor-http-client` itself is functional, its primary use case is no longer supported by the broader ecosystem, making it unsuitable for new projects.
fix
Consider migrating tests to modern frameworks like Playwright or Cypress, and use their built-in or native HTTP client capabilities. For existing Protractor tests, acknowledge the end-of-life status and plan for migration.
affects: >=0.1
breakingThis library's core functionality relies on the `request` package, which has been deprecated and is no longer maintained. This presents potential security risks (CVEs will not be patched), compatibility issues with newer Node.js versions, and lack of modern HTTP/2 or Fetch API support.
fix
If continuing to use this library, be aware of the `request` dependency's end-of-life status. For new development or migration, prefer libraries using `node-fetch`, `axios`, or native browser `fetch` API for HTTP requests.
affects: >=0.1
gotchaRequests do not automatically fail on non-2xx HTTP status codes by default. A 404 or 500 response will still resolve the promise without an error, requiring explicit status code checks in tests.
fix
Set `http.failOnError = true` immediately after instantiating `HttpClient` to ensure that non-2xx responses throw an error, simplifying error handling. Alternatively, always add `expect(response.statusCode).toEqual(2xx)` checks in your tests.
affects: >=0.1
gotchaThe `protractor-http-client` library appears to be abandoned, with no commits since 2017. This implies no support for newer Node.js versions, security vulnerability patching, or feature enhancements, making it potentially unstable or insecure in modern environments.
fix
Exercise caution when using in new projects. For existing projects, understand that no further updates will be provided. Consider migrating to actively maintained alternatives if possible.
affects: >=0.1
Errors
Common errors & fixes
TypeError: browser.wait is not a function or is deprecated
The library's core functionality depends on Protractor's `browser.wait` and control flow. This error occurs if Protractor's global `browser` object is not correctly configured or available, or if an incompatible version is used.
fix
Ensure Protractor is correctly set up and running, and that `browser` is available in your test scope. Verify that `protractor-http-client` is used exclusively within a Protractor test environment and with a compatible Protractor version (e.g., Protractor 3+).
Error: connect ECONNREFUSED <your_api_host>:<port>
The HTTP client could not establish a connection to the specified API endpoint. This typically indicates the target API server is not running, is unreachable due to network issues, or the URL/port is incorrect.
fix
Verify that the API server is running and accessible from where the tests are executed. Check the base URL and endpoint paths passed to `HttpClient` and its methods for typos or incorrect ports. Ensure no firewall or proxy is blocking the connection.
ResponsePromise is not defined
This error occurs in a TypeScript environment if `ResponsePromise` (or `JsonPromise`) is used as a runtime value or is not correctly imported for type annotations.
fix
Ensure that `ResponsePromise` and `JsonPromise` are only used for type annotations in TypeScript and are imported using `import type { ResponsePromise, JsonPromise } from 'protractor-http-client';`. They are not constructible classes or runtime objects.
HttpError: Request failed with status code 401 (Unauthorized)
The API endpoint returned an HTTP error status code (e.g., 401, 403, 404, 500) and `http.failOnError` was set to `true`, causing the request to throw an error.
fix
Examine the API endpoint, request headers, and body to determine why the server returned the error. This is often due to incorrect authentication tokens, missing data, or an invalid endpoint configuration. The error correctly indicates an API issue that needs to be addressed.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
protractorrequiredCore dependency for integrating HTTP calls into Protractor's control flow and utilizing its global `browser` object.
requestrequiredUnderlying HTTP client library used for all network requests. This dependency is deprecated.
Agent activity
4 hits · last 30 days
node
4
Resources
protractor-http-client — npm install protractor-http-client · libregistry