Verify that the API response contains the correct resource representation based on the specified language (e.g. English, Spanish, French).
Language: Java
Framework: Rest assured
1//Assuming the API endpoint is already known and functioning properly23import org.junit.Test;4import static io.restassured.RestAssured.given;5import static org.hamcrest.Matchers.containsString;67public class LanguageRepresentationAPITest {89 @Test10 public void verifyEnglishRepresentation() {11 given().12 queryParam("language", "English").13 when().14 get("https://api.example.com/resources").15 then().16 assertThat().17 body(containsString("English representation"));18 }1920 @Test21 public void verifyFrenchRepresentation() {22 given().23 queryParam("language", "French").24 when().25 get("https://api.example.com/resources").26 then().27 assertThat().28 body(containsString("French representation"));29 }3031 @Test32 public void verifySpanishRepresentation() {33 given().34 queryParam("language", "Spanish").35 when().36 get("https://api.example.com/resources").37 then().38 assertThat().39 body(containsString("Spanish representation"));40 }4142 //Code to use local driver for API testing43 //RestAssured provides an easy-to-use framework for connecting to remote clients with desired capabilities4445 /* 46 public void connectToRemoteClient() {47 DesiredCapabilities capabilities = new DesiredCapabilities();48 capabilities.setCapability("browserName", "chrome");49 capabilities.setCapability("browserVersion", "91.0");50 capabilities.setCapability("platformName", "Mac");51 RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);52 Response response = RestAssured.given().53 baseUri("https://api.example.com").54 port(8080).55 when().56 get("/resources").57 then().58 statusCode(200).59 extract().60 response();61 String jsonString = response.asString();62 }63 */6465}
Language: Javascript
1// Mocha and Chai.234const request = require('request');5const expect = require('chai').expect;67const baseUrl = 'https://example.api.com';89describe('API language-based representation testing', function() {10 it('should return the correct resource representation based on the language specified', function(done) {11 const language = 'en'; // Assumption: 'en' is the language code for English12 const endpoint = '/resource';13 const url = `${baseUrl}${endpoint}?language=${language}`;1415 request.get(url, function(error, response, body) {16 // Verify status code17 expect(response.statusCode).to.equal(200);1819 // Verify response body20 const responseBody = JSON.parse(body);21 expect(responseBody.language).to.equal(language); // Assumption: The API returns the language code in the response body22 // Add additional assertions here for the correct representation of the resource based on the language2324 done();25 });26 });27});2829// Uncomment code below to use remote client with desired capabilities30/*31const webdriver = require('selenium-webdriver');32const capabilities = {33 browserName: 'chrome',34 platform: 'Windows 10',35 version: 'latest'36};37const remoteUrl = 'http://localhost:4444/wd/hub';3839const driver = new webdriver.Builder()40 .withCapabilities(capabilities)41 .usingServer(remoteUrl)42 .build();43*/
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