Verify that the API correctly handles multi-language support and returns the correct resources for each language.
Language: Java
Framework: Rest assured
1//Assumptions: 2//1. API supports multiple languages (English, Spanish, French)3//2. API endpoint for retrieving resources is "/api/resources"4//3. Expected response code for successful retrieval is 20056import io.restassured.RestAssured;7import io.restassured.response.Response;8import org.junit.Assert;9import org.junit.Test;10import org.junit.BeforeClass;1112import java.util.HashMap;13import java.util.Map;1415public class ApiTest {16 17 private static Map<String, String> headers;1819 @BeforeClass20 public static void setup() {21 // if needed, add code to connect to remote client with desired capabilities22 headers = new HashMap<>();23 }24 25 @Test26 public void testMultiLanguageSupport() {27 // Test case: Check multi-language support28 // Description: Verify that the API correctly handles multi-language support and returns the correct resources for each language.29 30 // Assumptions: 31 // 1. API supports multiple languages (English, Spanish, French)32 // 2. API endpoint for retrieving resources is "/api/resources"33 // 3. Expected response code for successful retrieval is 2003435 // Test for English36 Response responseEN = RestAssured.given()37 .headers(headers)38 .param("lang", "en")39 .get("/api/resources");40 Assert.assertEquals("English resources not returned successfully", 200, responseEN.getStatusCode());4142 // Test for Spanish43 Response responseES = RestAssured.given()44 .headers(headers)45 .param("lang", "es")46 .get("/api/resources");47 Assert.assertEquals("Spanish resources not returned successfully", 200, responseES.getStatusCode());4849 // Test for French50 Response responseFR = RestAssured.given()51 .headers(headers)52 .param("lang", "fr")53 .get("/api/resources");54 Assert.assertEquals("French resources not returned successfully", 200, responseFR.getStatusCode());55 }56}
Language: Javascript
1// Mocha with Chai23//Assumption: The API URL is https://example.com/api4//Assumption: The languages supported by the API are English, French, and Spanish5//Assumption: The API returns a JSON object with language-specific resources67const expect = require('chai').expect;8const axios = require('axios');910describe('Multi-Language Support API Testing Suite', () => {11 it('should return the correct resources for English language request', async () => {12 const response = await axios.get('https://example.com/api?lang=en');13 const resources = response.data;14 expect(resources).to.have.property('greeting').that.equals('Hello');15 expect(resources).to.have.property('farewell').that.equals('Goodbye');16 });1718 it('should return the correct resources for French language request', async () => {19 const response = await axios.get('https://example.com/api?lang=fr');20 const resources = response.data;21 expect(resources).to.have.property('greeting').that.equals('Bonjour');22 expect(resources).to.have.property('farewell').that.equals('Au revoir');23 });2425 it('should return the correct resources for Spanish language request', async () => {26 const response = await axios.get('https://example.com/api?lang=es');27 const resources = response.data;28 expect(resources).to.have.property('greeting').that.equals('Hola');29 expect(resources).to.have.property('farewell').that.equals('Adiós');30 });31});3233// Uncomment the following code to connect to remote client with desired capabilities34/*35const webdriver = require('selenium-webdriver');36const capabilities = {37 browserName: 'chrome',38 platform: 'Windows 10',39 version: 'latest',40 screenResolution: '1920x1080'41}4243const driver = new webdriver.Builder()44 .usingServer('http://localhost:4444/wd/hub')45 .withCapabilities(capabilities)46 .build();4748// Run the test suite with remote driver49*/
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