Verify that the API returns the correct results when searching for a string with non-ASCII characters.
Language: Java
Framework: Rest assured
1// Assuming the API endpoint is http://api.example.com/search23import org.junit.jupiter.api.Test;4import static io.restassured.RestAssured.*;5import static org.hamcrest.Matchers.*;67public class NonASCIIAPITest {89 @Test10 public void testNonASCIISearch() {11 // Set up the API endpoint for the search request12 String endpoint = "http://api.example.com/search";13 // Set up the search string for non-ASCII characters14 String searchString = "김민지";15 16 // Send the search request and verify the response17 given().queryParam("q", searchString)18 .when().get(endpoint)19 .then().statusCode(200)20 .body("result", equalTo("김민지"));21 }22 23 // Uncomment the following code to use remote client with desired capabilities24 /*@BeforeClass25 public void setup() {26 DesiredCapabilities capabilities = new DesiredCapabilities();27 capabilities.setBrowserName("chrome");28 capabilities.setVersion("90");29 capabilities.setPlatform(Platform.LINUX);30 RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);31 driver.manage().window().maximize();32 RestAssured.config = RestAssuredConfig.config()33 .httpClient(HttpClientConfig.httpClientConfig().httpClientFactory(() -> {34 return new HttpClientBuilder().client(new OkHttpClient.Builder()35 .sslSocketFactory(new SSLSocketFactoryBuilder().build() .overrideSSLSocketFactory(SSLSocketFactory.getDefault()).build())36 .build());37 }).build());38 RestAssured.baseURI = "http://api.example.com";39 RestAssured.basePath = "/search";40 RestAssured.port = 80;41 RestAssured.authentication = preemptive().basic("username", "password");42 //logger configuration43 RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();44 }*/45}
Language: Javascript
1// Mocha + Chai23//Assuming that the API endpoint is already defined and available4//Assuming that the API returns results in JSON format5//Assuming that non-ASCII characters are encoded in UTF-867const { expect } = require('chai');8const fetch = require('node-fetch');910describe('API Testing', () => {11 it('should return correct results for non-ASCII search', async () => {12 //Assuming the search string "Café" encoded in UTF-8 is passed as query parameter 'q' to the API endpoint13 const response = await fetch('https://api.example.com/search?q=Caf%C3%A9'); 14 const data = await response.json();15 16 //Assuming the expected response contains an array of objects with 'name' attribute17 const expectedResults = [{ name: 'Café Rouge' }, { name: 'Cafeteria El Sótano' }];18 19 //Asserting that the returned data matches the expected results20 expect(data).to.deep.equal(expectedResults);21 });22});2324//Assuming that we want to connect to a remote client with desired capabilities25//const { Builder, By, Capabilities } = require('selenium-webdriver');26//const chromeCapabilities = Capabilities.chrome();27//chromeCapabilities.set('chromeOptions', { 'args': ['--headless'] });28//const driver = await new Builder().withCapabilities(chromeCapabilities).usingServer('http://remote.client:4444/wd/hub').build();
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