Basic Authentication with Postman

Last Updated On

HOME

In this tutorial, we’ll learn how to use Postman to test an endpoint secured with Basic Authentication.

Table of Contents

What is Basic Authentication?

Basic Authentication is a simple authentication scheme built into the HTTP protocol. The client sends the username and password encoded in Base64 in the Authorization header.

We will use the following URL for this Postman tutorial.

https://postman-echo.com/basic-auth

Implementation Steps

Below are the steps to use Basic Auth in Postman:

Create a Collection

Step 1: Create a Collection, click on Collections, and then click on the “+” plus button.

Step 2:  Provide a name to the collection – “Authentication”.

Add a request to the Collection

Step 3: To create a new request, click on “Add a request”, if it is a new Collection. Otherwise, click on the 3 dots and select “Add request”.

Enter the details – URL, Method, Authorization

Step 4: Enter the “name” in the request. Here, the name is “Basic Auth”.

Step 5: Enter the “URL” in the address bar.

https://postman-echo.com/basic-auth

Step 6: Now, select the “GET” request from the list of request methods.

Step 10: Now, click on the Send button in Postman. The server will respond with the protected resource response message.

Verify the Response

Step 11: Once you press the send button, you will get the response from the server. Make sure you have a proper internet connection; otherwise, you will not get a response.

Status

You can check the status code. Here, we got the status code 200, which means we got a successful response to the request.

Body

In the Body tab of the response box, we have multiple options to see the response in a different format.

Headers

Headers are the extra information that is transferred to the server or the client. In Postman, headers will show like key-value pairs under the headers tab. Click on the Headers link as shown in the below image:

We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

JUnit – Multiple Choice Questions and Answers – MCQ1

HOME

























PyTest Multiple Choice Questions – MCQ2

HOME

























Automate JMeter Testing with GitHub Actions

HOME

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>JMeter_GitHub_Integration</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>JMeter_GitHub_Integration</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.14.0</version>
        <configuration>
          <source>17</source>
          <target>17</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>com.lazerycode.jmeter</groupId>
        <artifactId>jmeter-maven-plugin</artifactId>
        <version>3.8.0</version>
        <executions>
          <!-- Generate JMeter configuration -->
          <execution>
            <id>configuration</id>
            <goals>
              <goal>configure</goal>
            </goals>
          </execution>
          <!-- Run JMeter tests -->
          <execution>
            <id>jmeter-tests</id>
            <goals>
              <goal>jmeter</goal>
            </goals>
          </execution>
          <!-- Fail build on errors in test -->
          <execution>
            <id>jmeter-check-results</id>
            <goals>
              <goal>results</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <generateReports>true</generateReports>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

mvn clean verify

echo "# JMeter_Github_Integration" >> README.md
git init
git add .
git commit -m "Jmeter Tests"
git branch -M main
git remote add origin https://github.com/vibssingh/JMeter_Github_Integration.git
git push -u origin main

name: JMeter Test Run

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - name: Set up JDK 17
      uses: actions/setup-java@v4
      with:
        java-version: '17'
        distribution: 'temurin'
    
    - name: Run JMeter tests
      run: mvn clean verify

    - name: JMeter Test Report Generation
      uses: actions/upload-artifact@v4
      if: success() || failure()
      with:
          name: JMeter Report                                             # Name of the folder
          path: target/jmeter/reports/SOAP_Request           # Path to test results  

Below shows all the steps of the workflow.

How to Use Pytest for REST API Testing

HOME

pip install -U pytest
pip install pytest requests

import pytest
import requests

BASE_URL = "https://reqres.in/api"

def test_get_endpoint():
       response = requests.get(f"{BASE_URL}/users/2")
       assert response.status_code == 200
       assert response.json()["data"]["email"]   == "janet.weaver@reqres.in"
       assert response.json()["data"]["id"] == 2
       assert response.json()["data"]["first_name"] == "Janet"
       assert response.json()["data"]["last_name"] == "Weaver"

def test_post_endpoint():
       payload = {"name": "Vibha", "job": "CTO"}
       headers = {"x-api-key": "reqres-free-v1"}

       response = requests.post(f"{BASE_URL}/users", headers=headers, json=payload)

       print(response.status_code)
       print(response.text) 
       assert response.status_code == 201
       assert response.json()["name"] == "Vibha"

BASE_URL = "https://reqres.in/api"
response = requests.get(f"{BASE_URL}/users/2")
assert response.status_code == 200
assert response.json()["data"]["email"]   == "janet.weaver@reqres.in"
assert response.json()["data"]["id"] == 2
assert response.json()["data"]["first_name"] == "Janet"
assert response.json()["data"]["last_name"] == "Weaver"

payload = {"name": "Vibha", "job": "CTO"}
headers = {"x-api-key": "reqres-free-v1"}
response = requests.post(f"{BASE_URL}/users", headers=headers, json=payload)
print(response.status_code)
print(response.text) 
assert response.status_code == 201
assert response.json()["name"] == "Vibha"
pytest test_api.py

pytest test_api.py --html=report.html

GitHub – Multiple Choice Questions and Answers – MCQ1

HOME

























Robot Framework – Multiple Choice Questions and Answers – MCQ2

HOME

























Pytest Multiple Choice Questions – MCQ1

HOME

















a) @Pytest.xfail
b) @Pytest.mark.xfail
c) @Pytest.expected_failure
d) @Pytest.mark.expected_failure

a) @skip
b) @pytest.mark.skip
c) @pytest.ignore
d) @skipTest

a) @Pytest.skipif
b) @Pytest.mark.skip
c) @Pytest.mark.skipif
d) @Pytest.skip


a) Pytest -m “marker”
b) Pytest -k “expression”
c) Pytest –collect-only
d) Pytest –last-failed

a) pytest --tag=name
b) pytest -k name
c) pytest --only-mark=name
d) pytest -m name



Robot Framework Multiple Choice Questions – MCQ1

HOME

























JMeter Multiple Choice Questions – MCQ2

HOME

























====================================================================