{"id":15770,"library":"protractor-http-client","title":"Protractor HTTP Client","description":"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.","status":"abandoned","version":"1.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/marcodave/protractor-http-client","tags":["javascript","protractor","http","rest","client","test","selenium","webdriver"],"install":[{"cmd":"npm install protractor-http-client","lang":"bash","label":"npm"},{"cmd":"yarn add protractor-http-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add protractor-http-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for integrating HTTP calls into Protractor's control flow and utilizing its global `browser` object.","package":"protractor","optional":false},{"reason":"Underlying HTTP client library used for all network requests. This dependency is deprecated.","package":"request","optional":false}],"imports":[{"note":"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.","wrong":"import HttpClient from 'protractor-http-client'","symbol":"HttpClient","correct":"import { HttpClient } from 'protractor-http-client'"},{"note":"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.","wrong":"import { ResponsePromise, JsonPromise } from 'protractor-http-client'","symbol":"ResponsePromise, JsonPromise","correct":"import type { ResponsePromise, JsonPromise } from 'protractor-http-client'"}],"quickstart":{"code":"import { HttpClient, ResponsePromise } from \"protractor-http-client\";\nimport { browser, by, element, expect } from \"protractor\"; // Assuming these are globally available or imported from 'protractor'\n\n// Instantiate the HTTP client with a base URL\nconst http = new HttpClient(\"https://api.example.com/\");\nhttp.failOnError = true; // Recommend setting this to ensure API errors throw exceptions\n\ndescribe(\"the login page\", () => {\n    // Setup a user via API before each test\n    beforeEach(async () => {\n        const postResponse: ResponsePromise = http.post(\"/users\", {\n            username: \"testuser\",\n            password: \"securepassword\"\n        });\n        // protractor-http-client automatically waits for the promise to resolve\n        expect(postResponse.statusCode).toEqual(200); // Verify creation was successful\n    });\n\n    // Cleanup the user via API after each test\n    afterEach(async () => {\n        const deleteResponse: ResponsePromise = http.delete(\"/users/testuser\");\n        expect(deleteResponse.statusCode).toEqual(200); // Verify deletion was successful\n    });\n\n    it(\"will allow login with new user\", async () => {\n        // Now you can use the browser to login with the new user\n        await browser.get(\"/login\");\n        await element(by.id(\"username\")).sendKeys(\"testuser\");\n        await element(by.id(\"password\")).sendKeys(\"securepassword\");\n        await element(by.id(\"loginButton\")).click(); // Assuming a login button\n        \n        // Assert successful login, e.g., URL change or element presence\n        expect(await browser.getCurrentUrl()).toContain(\"/dashboard\");\n        expect(await element(by.id(\"welcomeMessage\")).getText()).toContain(\"Welcome, testuser\");\n    });\n});","lang":"typescript","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":">=0.1"},{"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.","message":"This 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.","severity":"breaking","affected_versions":">=0.1"},{"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.","message":"Requests 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.","severity":"gotcha","affected_versions":">=0.1"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=0.1"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"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+).","cause":"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.","error":"TypeError: browser.wait is not a function or is deprecated"},{"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.","cause":"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.","error":"Error: connect ECONNREFUSED <your_api_host>:<port>"},{"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.","cause":"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.","error":"ResponsePromise is not defined"},{"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.","cause":"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.","error":"HttpError: Request failed with status code 401 (Unauthorized)"}],"ecosystem":"npm"}