Understanding API Testing: Benefits and Challenges

HOME

How to test HTML5 validation messages with Selenium

HOME

<label for="email">Enter your example.com email:</label>

<input type="email" id="email" pattern=".+@example\.com" size="30" required />

ChromeOptions options = new ChromeOptions();
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
String filePath = "file:///C:/Users/vibha/OneDrive/Desktop/Email.html";
driver.get(filePath);

driver.manage().window().maximize();

WebElement email = driver.findElement(By.id("email"));
email.sendKeys("");
String validationMessage = email.getAttribute("validationMessage");
 String expectedMessage = "Please fill out this field.";
    if (validationMessage.equals(expectedMessage)) {
        System.out.println("Validation test passed. :" + validationMessage);
    } else {
        System.out.println("Validation test failed. Expected: '" + expectedMessage + "' but got: '" + validationMessage + "'");
    }

driver.quit();
package com.example.Sample;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;
import java.util.List;

public class HTML5Validation {

    public static void main(String[] args)  {

        // Setup the webdriver
        ChromeOptions options = new ChromeOptions();
        WebDriver driver = new ChromeDriver(options);

        // Put an Implicit wait and launch URL
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
        String filePath = "file:///C:/Users/vibha/OneDrive/Desktop/Email.html";
        driver.get(filePath);

        //maximize browser
        driver.manage().window().maximize();

        //Blank field
        WebElement email = driver.findElement(By.id("email"));
        email.sendKeys("");
        String validationMessage = email.getAttribute("validationMessage");

        // Expected validation message 
        String expectedMessage = "Please fill out this field.";
        if (validationMessage.equals(expectedMessage)) {
            System.out.println("Validation test passed. :" + validationMessage);
        } else {
            System.out.println("Validation test failed. Expected: '" + expectedMessage + "' but got: '" + validationMessage + "'");
        }

         // Close the browser
         driver.quit();
    }

}

DevOps Multiple Choice Answers – MCQ2

HOME

DevOps Multiple Choice Questions – MCQ2

























DevOps Multiple Choice Questions – MCQ1 
Jenkins Multiple Choice Questions – MCQ1
Rest API Multiple Choice Questions – MCQ1
Git Multiple Choice Questions – MCQ1 
JMeter Multiple Choice Questions – MCQ1

DevOps Multiple Choice Questions – MCQ2

HOME

Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer



Answer


Answer

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

DevOps Multiple Choice Questions – MCQ1 
Jenkins Multiple Choice Questions – MCQ1
Rest API Multiple Choice Questions – MCQ1
Git Multiple Choice Questions – MCQ1 
JMeter Multiple Choice Questions – MCQ1

Interview Questions for API Testing 2025

HOME

https://www.qaautomation.expert
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html
  {
     "username": "exampleuser",
     "password": "examplepassword"
   }
   

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
 x-api-key: YOUR_API_KEY

'or 1=1--
"and 1=1--
echo "malicious" >> /var/www/html/index.html
rm file.txt; cat /etc/passwd

https://api.example.com/items?page=2&limit=50
https://api.example.com/products?category=electronics&price<1000

name: API Tests

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '14'

    - name: Install Newman
      run: npm install -g newman

    - name: Run API tests with Newman
      run: newman run test.json

{
  "token": "eyJhbGciOiJIUzI1NiIsInR..."
}

import io.restassured.http.ContentType;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

public class APITests {

        String BaseURL = "https://reqres.in/api";

    @Test
    public void getUser() {  

        // GIVEN
        given()
                .contentType(ContentType.JSON)

                // WHEN
                .when()
                .get(BaseURL + "/users/2")

                // THEN
                .then()
                .statusCode(200)
                .body("data.first_name", equalTo("Janet"))
                .log().all();

    }

}

Use Case Examples**:
  - Login authentication: The client needs the server's response before proceeding.
  - Fetching data: The client requires the result immediately to display to the user.
**Use Case Examples**:
  - File upload or processing: The server processes the file and sends a notification when done.
  - Notification systems: Sending push notifications to multiple devices.

Advance Selenium Multiple Choice Questions – MCQ1

HOME

Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


a)  driver.waitForElement()

b)  new WebDriverWait().until(ExpectedConditions.elementToBeClickable())

c)  Thread.sleep()

d)  new WebDriverWait().until(ExpectedConditions.visibilityOfElementLocated())

Answer


a)  Actions.doubleClick(element)

b)  WebElement.contextClick()

c)  Actions.moveToElement(element).click()

d)  Actions.contextClick(element)

Answer


a)  driver.takeScreenshot()

b)  ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE)

c)  driver.getScreenshot()

d)  driver.captureScreen()

Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer


Answer



Answer


Answer


Answer

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

Advance Selenium Multiple Choice Answers – MCQ1

HOME







Selenium cannot handle security testing on its own. However, it can assist in certain aspects of security testing when integrated with specialized security tools.



















How to decode JWT Token with Auth0 in Java

HOME

 {
    "typ":"JWT",
    "alg":"HS256"
 }
{
  "sub":"test",
  "roles":"ROLE_ADMIN",
  "iss":"myself",
  "exp":1471086381
}
HASHINGALGO( base64UrlEncode(header) + “.” + base64UrlEncode(payload),secret)
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0Iiwicm9sZXMiOiJST0xFX0FETUlOIiwiaXNzIjoibXlzZWxmIiwiZXhwIjoxNDcxMDg2MzgxfQ.1EI2haSz9aMsHjFUXNVz2Z4mtC0nMdZo6bo3-x-aRpw
 <dependency>
      <groupId>com.auth0</groupId>
      <artifactId>java-jwt</artifactId>
      <version>4.4.0</version>
 </dependency>

DecodedJWT decodedJWT = JWT.decode(jwtToken);
String header = decodedJWT.getHeader();
String payload = decodedJWT.getPayload();
String signature = decodedJWT.getSignature();
String subject = decodedJWT.getSubject();
String issuer = decodedJWT.getIssuer();
String decodedHeader = new String(java.util.Base64.getUrlDecoder().decode(header));
String decodedPayload = new String(java.util.Base64.getUrlDecoder().decode(payload));
package com.example.JWT;
import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.DecodedJWT;

public class JWTAuth0Decoder {

    public static void main(String[] args) {

        String jwtToken = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0Iiwicm9sZXMiOiJST0xFX0FETUlOIiwiaXNzIjoibXlzZWxmIiwiZXhwIjoxNDcxMDg2MzgxfQ.1EI2haSz9aMsHjFUXNVz2Z4mtC0nMdZo6bo3-x-aRpw";
        DecodedJWT decodedJWT = JWT.decode(jwtToken);

        // Retrieve header, payload, and signature
        String header = decodedJWT.getHeader();
        String payload = decodedJWT.getPayload();
        String signature = decodedJWT.getSignature();
        String subject = decodedJWT.getSubject();
        String issuer = decodedJWT.getIssuer();

        // Print each component
        System.out.println("Header (Base64): " + header);
        System.out.println("Payload (Base64): " + payload);
        System.out.println("Signature: " + signature);
        System.out.println("Subject: " + subject);
        System.out.println("Issuer: " + issuer);

        String decodedHeader = new String(java.util.Base64.getUrlDecoder().decode(header));
        String decodedPayload = new String(java.util.Base64.getUrlDecoder().decode(payload));

        System.out.println(" ****************** Decoded Values ******************* ");
        System.out.println("Decoded Header: " + decodedHeader);
        System.out.println("Decoded Payload: " + decodedPayload);

    }
}

Creating JWT with Auth0 in Java

HOME

 {
    "typ":"JWT",
    "alg":"HS256"
 }
{
  "iss": "QA_Automation",
  "sub": "QA_Automation Details",
  "userId": "9821",
  "roles": "ROLE_ADMIN",
  "scope": "read write",
  "iat": 1680000000,
  "exp": 1680000100,
  "jti": "uuid-guid",
  "nbf": 1680000001
}
HASHINGALGO( base64UrlEncode(header) + “.” + base64UrlEncode(payload),secret)
 <dependency>
      <groupId>com.auth0</groupId>
      <artifactId>java-jwt</artifactId>
      <version>4.4.0</version>
 </dependency>

Algorithm algorithm = Algorithm.HMAC256("qa-automation-expert-details");
.withIssuer("QA_Automation")
.withSubject("QA_Automation Details")
.withClaim("userId", "9821")
.withClaim("roles", "ROLE_ADMIN")
.withClaim("scope", "read write")
 .withIssuedAt(new Date())
 .withExpiresAt(new Date(System.currentTimeMillis() + 10000L))
.withJWTId(UUID.randomUUID().toString())
.withNotBefore(new Date(System.currentTimeMillis() + 100L))
.sign(algorithm);

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;
import java.util.Date;
import java.util.UUID;

public class JWTTokenGenerator {

    public static void main(String[] args) {

        Algorithm algorithm = Algorithm.HMAC256("qa-automation-expert-details");

        String jwtToken = JWT.create()
                .withIssuer("QA_Automation")
                .withSubject("QA_Automation Details")
                .withClaim("userId", "9821")
                .withClaim("roles", "ROLE_ADMIN")
                .withClaim("scope", "read write")
                .withIssuedAt(new Date())
                .withExpiresAt(new Date(System.currentTimeMillis() + 10000L))
                .withJWTId(UUID.randomUUID()
                        .toString())
                .withNotBefore(new Date(System.currentTimeMillis() + 100L))
                .sign(algorithm);

        System.out.println("jwtToken :" + jwtToken);
    }

}

Change Font Style in Excel with Apache POI

HOME

<!-- POI -->
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>5.3.0</version>
    </dependency>

    <!-- POI XML -->
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-ooxml</artifactId>
      <version>5.3.0</version>
    </dependency>
Font font = workbook.createFont();
XSSFWorkbook workbook = newXSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Example_Sheet");
 Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Happy Days");
Font font = workbook.createFont();
font.setFontHeightInPoints((short) 24);
font.setFontName("Arial");
font.setBold(true);
font.setItalic(true);
font.setColor(IndexedColors.DARK_RED.getIndex());
font.setUnderline(Font.U_SINGLE);
CellStyle style = workbook.createCellStyle();
style.setFont(font);
cell.setCellStyle(style);
 try {
            FileOutputStream outputStream = new FileOutputStream("src/test/StyledCell.xlsx");
            workbook.write(outputStream);
            outputStream.close();
            System.out.println("StyledCell.xlsx Workbook is successfully created");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            workbook.close();
        }

package com.example.Excel;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;
import java.io.IOException;

public class ApplyFont_Excel {

    public static void main(String[] args) throws IOException {

        // create blank workbook
        XSSFWorkbook workbook = new XSSFWorkbook();

        // Create a blank sheet
        XSSFSheet sheet = workbook.createSheet("Example_Sheet");

        //Create a row
        Row row = sheet.createRow(0);

        //Create a cell
        Cell cell = row.createCell(0);

        //Set the value of the cell
        cell.setCellValue("Happy Days");

        //Create a new font
        Font font = workbook.createFont();
        font.setFontHeightInPoints((short) 24);
        font.setFontName("Arial");
        font.setBold(true);
        font.setItalic(true);
        font.setColor(IndexedColors.DARK_RED.getIndex());
        font.setUnderline(Font.U_SINGLE);

        //Create a cell style and set the font
        CellStyle style = workbook.createCellStyle();
        style.setFont(font);

        //Apply the style to the cell
        cell.setCellStyle(style);

        //Write the output to the file
        try {
            FileOutputStream outputStream = new FileOutputStream("src/test/StyledCell.xlsx");
            workbook.write(outputStream);
            outputStream.close();
            System.out.println("StyledCell.xlsx Workbook is successfully created");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            workbook.close();
        }

    }
}

package com.example.Excel;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;
import java.io.IOException;

public class ApplyFontMultipleRows_Excel {

    public static void main(String[] args) throws IOException {

        // create blank workbook
        XSSFWorkbook workbook = new XSSFWorkbook();

        // Create a blank sheet
        XSSFSheet sheet = workbook.createSheet("Example_Sheet");

        //Create a new font1
        Font font1 = workbook.createFont();
        font1.setFontHeightInPoints((short) 12);
        font1.setFontName("Arial");
        font1.setBold(true);
        font1.setItalic(true);
        font1.setColor(IndexedColors.DARK_RED.getIndex());
        font1.setUnderline(Font.U_SINGLE);

        //Create a new font2
        Font font2 = workbook.createFont();
        font2.setFontHeightInPoints((short) 14);
        font2.setFontName("Times New Roman");
        font2.setBold(true);
        font2.setItalic(true);
        font2.setColor(IndexedColors.BLUE.getIndex());

        //Create a new font3
        Font font3 = workbook.createFont();
        font3.setFontHeightInPoints((short) 16);
        font3.setFontName("Courier New");
        font3.setBold(true);
        font3.setColor(IndexedColors.GREEN.getIndex());

        //Create a cell style and set the font
        CellStyle style1 = workbook.createCellStyle();
        style1.setFont(font1);

        CellStyle style2 = workbook.createCellStyle();
        style2.setFont(font2);

        CellStyle style3 = workbook.createCellStyle();
        style3.setFont(font3);

        // Apply styles to rows
        Row row1 = sheet.createRow(0);
        Cell cell1 = row1.createCell(0);
        cell1.setCellValue("Underlined Italic Bold Arial");
        cell1.setCellStyle(style1);

        Row row2 = sheet.createRow(1);
        Cell cell2 = row2.createCell(0);
        cell2.setCellValue("Bold Italic Times New Roman");
        cell2.setCellStyle(style2);

        Row row3 = sheet.createRow(2);
        Cell cell3 = row3.createCell(0);
        cell3.setCellValue("Courier New");
        cell3.setCellStyle(style3);

        //Write the output to the file
        try {
            FileOutputStream outputStream = new FileOutputStream("src/test/FontStyle.xlsx");
            workbook.write(outputStream);
            outputStream.close();
            System.out.println("Workbook FontStyle.xlsx is created");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            workbook.close();
        }

    }
}