Protractor HTTP Client

1.0.4 · abandoned · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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");
    });
});

view raw JSON →