Verify that the API returns the correct results when searching for a case- insensitive string.
Language: Java
Framework: Rest assured
1// Assumptions: 2// - The API endpoint for searching is '/search'3// - The API returns a JSON response with a 'results' key4// - The 'results' key contains an array of search results, each with a 'name' key56import static io.restassured.RestAssured.*;7import static org.hamcrest.Matchers.*;89// Local driver10RestAssured.baseURI = "http://localhost:8080";1112// Remote client with desired capabilities - not required for local testing13// DesiredCapabilities capabilities = new DesiredCapabilities();14// capabilities.setCapability("platformName", "Android");1516public class APITest {17 @Test18 public void testCaseInsensitiveSearch() {19 given()20 .param("query", "APPLE")21 .when()22 .get("/search")23 .then()24 .statusCode(200)25 .body("results.name", everyItem(equalToIgnoringCase("apple")));26 }27}
Language: Javascript
1// Mocha, Chai, Supertest, Node.js.23//Assumptions: 4// The API endpoint for the search function is already defined and can be accessed using an HTTP request.5// The API returns a JSON object containing a list of search results.6// The API supports case-insensitive search queries.78//Code:910// Import necessary modules11const request = require('supertest');12const { expect } = require('chai');1314// Define API endpoint15const apiUrl = 'https://example.com/api/search';1617// Describe test suite18describe('API Testing - Case-insensitive search', () => {1920 // Define test case21 it('should return correct results for case-insensitive search', async () => {22 23 // Define search query24 const searchQuery = 'Example';2526 // Define HTTP request with query parameter27 const res = await request(apiUrl)28 .get('/')29 .query({ q: searchQuery });3031 // Assert response status code32 expect(res.statusCode).to.equal(200);3334 // Assert response JSON object35 expect(res.body).to.be.an('object');36 expect(res.body.results).to.be.an('array');3738 // Assert search results contain the search query (case-insensitive)39 const searchResult = res.body.results.find(result => result.toLowerCase() === searchQuery.toLowerCase());40 expect(searchResult).to.exist;41 });42});4344// Commented code to connect to remote client with desired capabilities:45/*46const { Builder } = require('selenium-webdriver');47const chromeCapabilities = {48 browserName: 'chrome',49 "goog:chromeOptions": {50 args: [51 "--headless",52 "--disable-gpu",53 "--window-size=800,600"54 ],55 },56};5758const driver = new Builder()59 .usingServer('http://localhost:4444/wd/hub')60 .withCapabilities(chromeCapabilities)61 .build();62*/
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.
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.
Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.
Start Free Testing