Showing posts with label AI in Testing. Show all posts
Showing posts with label AI in Testing. Show all posts

Wednesday, July 2, 2025

Postman with Newman – Run API Tests from the Command Line Like a Pro

Postman with Newman – A Complete Guide for API Test Automation

Postman is a popular tool for testing RESTful APIs. While it's great for manual testing, running tests as part of automation or CI/CD pipelines requires a command-line interface. That’s where Newman comes in!

๐Ÿš€ What is Newman?

Newman is Postman’s command-line tool that lets you run Postman collections directly from your terminal. It allows automated API testing and is perfect for continuous integration workflows.

๐Ÿ› ️ How to Set Up Postman with Newman

Step 1: Install Node.js

Download and install Node.js from https://nodejs.org/.

Step 2: Install Newman

Open your terminal and run:

npm install -g newman

Step 3: Export Postman Collection

  • Open Postman app
  • Select your collection → click "..." → Export
  • Choose "Collection v2.1 (recommended)" format

Step 4: Run Collection Using Newman

newman run your_collection.json

๐Ÿงช Run with Environment File

newman run your_collection.json -e your_environment.json

๐Ÿ“Š Generate HTML Report


npm install -g newman-reporter-html
newman run your_collection.json -r html

๐Ÿ” Run with Data File (CSV or JSON)

newman run your_collection.json -d data.csv

⚙️ CI/CD Integration Ideas

  • Jenkins: Add as a shell step
  • GitHub Actions: Add in your YAML workflow
  • GitLab CI: Include in your .gitlab-ci.yml

✅ Summary

Newman helps you automate Postman collections via CLI, making your API tests easily repeatable, CI/CD-friendly, and reportable. This approach saves time, improves accuracy, and helps detect issues earlier in the development cycle.

๐Ÿ“Ž Helpful Links

Written by Anup Khobragade | Published on SoftwareTesting-Guideline

Friday, May 23, 2025

Integrating Selenium with Java and OpenAI API – Intelligent Automation for QA Engineers

๐Ÿง  Integrate Selenium with Java and OpenAI API – Full Guide

This guide shows how to use Selenium for web automation with OpenAI’s Java SDK. Learn how to retrieve your API key, manage it securely, and write a test script that interacts with OpenAI and a web page.

๐Ÿ”‘ How to Get Your OpenAI API Key

  1. Go to https://platform.openai.com/signup and sign up or log in.
  2. Once logged in, click on your profile (top-right) > API keys.
  3. Click Create new secret key and copy the key securely.
⚠️ Do not share your API key publicly. Store it safely using a .env file as explained below.

๐Ÿ“ฆ Maven Project Setup

In your Java Maven project’s pom.xml, add these dependencies:

<dependencies>
  <!-- Selenium WebDriver -->
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.8.0</version>
  </dependency>

  <!-- OpenAI Java Client (Theo Kanning's library) -->
  <dependency>
    <groupId>com.theokanning.openai-gpt3-java</groupId>
    <artifactId>client</artifactId>
    <version>0.18.2</version>
  </dependency>

  <!-- dotenv-java to manage environment variables -->
  <dependency>
    <groupId>io.github.cdimascio</groupId>
    <artifactId>dotenv-java</artifactId>
    <version>5.2.2</version>
  </dependency>
</dependencies>

๐Ÿ” Step: Setup .env File

Create a file named .env in your project’s root folder with this content:

OPENAI_API_KEY=your_openai_api_key_here

Also add .env to your .gitignore file to keep your API key private.

๐Ÿ’ป Real-World Java Example with OpenAI + Selenium

This example uses Selenium to open a flight search website and OpenAI to generate a user tip for filling out the form.

import io.github.cdimascio.dotenv.Dotenv;
import com.theokanning.openai.service.OpenAiService;
import com.theokanning.openai.completion.CompletionRequest;
import com.theokanning.openai.completion.CompletionChoice;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class FlightAutomationExample {
    public static void main(String[] args) {
        // Load environment variables
        Dotenv dotenv = Dotenv.load();
        String apiKey = dotenv.get("OPENAI_API_KEY");

        // Initialize OpenAI
        OpenAiService service = new OpenAiService(apiKey);

        // Use OpenAI to generate a flight booking tip
        CompletionRequest request = CompletionRequest.builder()
            .prompt("Give one important tip for booking flights online.")
            .model("text-davinci-003")
            .maxTokens(100)
            .build();

        CompletionChoice choice = service.createCompletion(request).getChoices().get(0);
        System.out.println("OpenAI Tip: " + choice.getText());

        // Launch browser with Selenium
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.example.com/flights");

        // You can automate actions here, e.g., filling a form, clicking search, etc.

        driver.quit();
    }
}

✅ Summary

  • ๐Ÿ’ก Use OpenAI to generate smart content or logic in your automation tests.
  • ๐Ÿงช Use Selenium for browser testing or automation steps.
  • ๐Ÿ” Secure API keys using dotenv-java in your Maven project.

By combining these technologies, you can bring intelligence to your automation framework, such as generating test data, writing user prompts, or analyzing UI interactions.


If you found this helpful, share it with fellow QA engineers or developers!