API Testing : Check API debug logs

Verify that the API correctly handles API debug logs and returns the correct resources for each API debug log.

Language: Java

Framework: Rest assured

copy
1import io.restassured.RestAssured;2import static io.restassured.RestAssured.*;3import io.restassured.path.json.JsonPath;4import io.restassured.response.Response;56/​/​Assuming:7/​/​Base API URL is "https:/​/​example.com/​api"8/​/​Debug logs URL is "/​debug"9/​/​API returns JSON response1011public class APITest {1213 @Test14 public void debugLogsTest() {15 16 /​/​Connecting to remote client with desired capabilities17 /​/​Assuming client URL is "http:/​/​localhost:4444/​wd/​hub"18 /​/​Assuming desired capabilities are Chrome browser and version 9119 DesiredCapabilities capabilities = DesiredCapabilities.chrome();20 capabilities.setCapability("browserName", "chrome");21 capabilities.setCapability("browserVersion", "91");22 WebDriver driver = new RemoteWebDriver(new URL("http:/​/​localhost:4444/​wd/​hub"), capabilities);23 24 RestAssured.baseURI = "https:/​/​example.com/​api";25 26 /​/​Sending GET request to debug logs URL27 Response response = given().log().all().when().get("/​debug").then().statusCode(200).extract().response();28 29 /​/​Parsing JSON response30 JsonPath jsonPath = response.jsonPath();31 32 /​/​Verify that the API correctly handles API debug logs and returns the correct resources for each API debug log33 /​/​Assuming every debug log contains "resource" field34 List<String> resources = jsonPath.getList("debuglog.resource");35 Assert.assertFalse(resources.isEmpty(), "API debug logs do not contain 'resource' field");36 }37}

Language: Javascript

copy
1/​/​ Mocha and Chai234const expect = require('chai').expect;5const request = require('request');67/​/​Assuming API endpoint and resources to query exist8const apiEndpoint = 'http:/​/​exampleapi.com';9const debugLogs = ['log1', 'log2', 'log3']; 1011describe('API Debug Log Test', function() {12 it('should return correct resources for each API debug log', function(done) {13 debugLogs.forEach(function(log) {14 let options = {15 url: apiEndpoint,16 headers: { 'debug-log': log }17 };18 /​/​Assuming API returns a JSON with resource information on successful log handling19 request(options, function (error, response, body) {20 expect(response.statusCode).to.equal(200);21 expect(body).to.have.property('resource');22 });23 });24 done();25 });26});2728/​/​Uncomment following code to connect to remote client with desired capabilities29/​*30const webdriver = require('selenium-webdriver');31const remote = require('selenium-webdriver/​remote');32const chromeCapabilities = webdriver.Capabilities.chrome();33chromeCapabilities.set('chromeOptions', {args: ['--disable-extensions']});3435const driver = new webdriver.Builder()36 .forBrowser('chrome')37 .withCapabilities(chromeCapabilities)38 .usingServer("http:/​/​localhost:4444/​wd/​hub")39 .build();40*/​

Disclaimer: Following code snippets and related information have been sourced from GitHub and/or generated using AI code generation tools. LambdaTest takes no responsibility in the accuracy of the code and is not liable for any damages.

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Power Your Software Testing with AI and cloud

Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.

Start Free Testing