Verify that the API correctly handles multi-locale support and returns the correct resources for each locale.
Language: Java
Framework: Rest assured
1// Assumptions: 2// 1. The API supports multiple locales (e.g. EN, FR, DE)3// 2. The API returns resources based on the locale specified in the request header4// 3. The locale is specified in the request header as "Accept-Language"56import org.junit.Test;7import io.restassured.RestAssured;8import io.restassured.response.Response;9import static org.hamcrest.MatcherAssert.assertThat;10import static org.hamcrest.Matchers.equalTo;1112public class API_Testing {1314 @Test15 public void testMultiLocaleSupport() {1617 // Define the base API URL18 RestAssured.baseURI = "http://localhost:8080/api";1920 // Define the locales to test21 String[] locales = {"en", "fr", "de"};2223 // Loop through each locale and test the API24 for (String locale : locales) {2526 // Set the request header to the specified locale27 Response response = RestAssured28 .given()29 .header("Accept-Language", locale)30 .get("/resources");3132 // Verify that the API returns a successful response33 assertThat(response.getStatusCode(), equalTo(200));3435 // Verify that the API returns the correct resources for the specified locale36 assertThat(response.getBody().jsonPath().get("locale"), equalTo(locale));37 }38 39 // Uncomment the following code to connect to remote client with desired capabilities40 //DesiredCapabilities desiredCapabilities = new DesiredCapabilities();41 //desiredCapabilities.setBrowserName("chrome");42 //remoteWebDriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), desiredCapabilities);43 //remoteWebDriver.get("http://localhost:8080");44 }45}
Language: Javascript
1// Mocha + Chai23//Assuming we have an API endpoint that takes a locale query parameter and returns corresponding resources4//Assuming we have resources for English (en) and French (fr) locales56const expect = require('chai').expect;7const request = require('request');89describe('Multi-Locale Support API Testing', function() {10 11 const baseUrl = 'http://localhost:8080/api/resources'; //Assuming the API endpoint12 13 it('Should return correct resources for English locale', function(done) {14 const url = baseUrl + '?locale=en';15 request(url, function(error, response, body) {16 const resources = JSON.parse(body);17 expect(resources.name).to.equal('Welcome'); //Assuming the name of the English resource is 'Welcome'18 expect(resources.description).to.equal('This is the English description'); //Assuming the description of the English resource19 //is 'This is the English description'20 done();21 });22 });23 24 it('Should return correct resources for French locale', function(done) {25 const url = baseUrl + '?locale=fr';26 request(url, function(error, response, body) {27 const resources = JSON.parse(body);28 expect(resources.name).to.equal('Bienvenue'); //Assuming the name of the French resource is 'Bienvenue'29 expect(resources.description).to.equal('Ceci est la description en français'); //Assuming the description of the French resource30 //is 'Ceci est la description en français'31 done();32 });33 });34 35});3637//Code to connect to remote client with desired capabilities (Selenium Grid)38// const webdriver = require('selenium-webdriver');3940// const hubUrl = 'http://localhost:4444/wd/hub'; //Assuming the Selenium Grid hub URL41// const capabilities = webdriver.Capabilities.chrome(); //Assuming we want to use Chrome browser4243// const driver = new webdriver.Remote({44// url: hubUrl,45// desiredCapabilities: capabilities46// });
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