Verify that the API returns the correct results when searching for a string with mixed character types (e.g. letters, numbers, symbols).
Language: Java
Framework: Rest assured
1import static io.restassured.RestAssured.*;2import static org.hamcrest.Matchers.*;34public class MixedCharacterSearchTest {56 @Test7 public void mixedCharacterSearch() {89 //Assuming base URL of the API10 String baseURI = "https://exampleapi.com";1112 //Connecting to remote client with desired capabilities13 DesiredCapabilities capabilities = new DesiredCapabilities();14 capabilities.setBrowserName("chrome"); //Example values, use required values15 WebDriver remoteDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);1617 //Setting base URI18 given().baseUri(baseURI)1920 //Adding query parameter with mixed characters21 .queryParam("searchTerm", "A7@bC*1")2223 //Sending GET request to the API24 .when().get("/search")2526 //Verifying the response of the API27 .then().statusCode(200)28 .body("results", hasItem("A7@bC*1_Test_Result"));29 }30}
Language: Javascript
1// MochaJS with ChaiJS assertion library.23//Assumption: The API endpoint for mixed character search is available and accessible.45//Connecting to remote client with desired capabilities6const webdriver = require('selenium-webdriver');7const { Builder } = require('selenium-webdriver');8const remote = require('selenium-webdriver/remote');910const capabilities = {11 browserName: 'chrome',12 platform: 'Windows 10',13};1415//Set up local driver16const driver = new Builder()17 .withCapabilities(capabilities)18 .build();1920describe('API Testing', function() {21 it('Check mixed character search', async function() {22 const mixedChars = 'A!B@C#1234';23 const apiUrl = 'https://example.com/api/mixedSearch?query=';24 const queryUrl = apiUrl.concat(mixedChars);2526 //Navigate to query url and retrieve API response27 await driver.get(queryUrl);28 const response = await driver.executeScript('return document.body.textContent');2930 //Verify response includes expected result31 expect(response).to.include('expected result');32 });3334 //Add additional test cases as needed35});3637//Close local driver and end remote client connection38driver.quit().then(function() {39 webdriver.WebDriver.endAllSessions();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.
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