Verify that the API correctly handles multi-region support and returns the correct resources for each region.
Language: Java
Framework: Rest assured
1import org.junit.Test;2import io.restassured.RestAssured;3import static io.restassured.RestAssured.*;4import static org.hamcrest.Matchers.*;56public class MultiRegionTest {7 @Test8 public void verifyMultiRegionSupport() {9 10 //Assuming API endpoint to be "https://example-api.com"11 12 //Connecting to local RestAssured client13 RestAssured.baseURI = "https://example-api.com";14 15 given()16 .header("region", "region1")17 .when()18 .get("/resource")19 .then()20 .statusCode(200)21 .body("region", equalTo("region1"));22 23 given()24 .header("region", "region2")25 .when()26 .get("/resource")27 .then()28 .statusCode(200)29 .body("region", equalTo("region2"));30 31 // Uncomment below code to connect to remote client with desired capabilities32 /*33 DesiredCapabilities capabilities = new DesiredCapabilities();34 capabilities.setCapability("platform", "WINDOWS");35 capabilities.setCapability("version", "10");36 RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);37 */38 }39}
Language: Javascript
1//Mocha and Chai.23//Assuming the API endpoint is already available and the regions are known4//Assuming an array of regions to be tested is already known56const { expect } = require('chai');7const { describe, it } = require('mocha');8const request = require('request');910//Local driver setup11const baseURL = 'http://localhost:3000'; //replace with actual endpoint12const options = {13 url: baseURL + '/multi-region-support',14 method: 'GET',15 headers: {16 'Content-Type': 'application/json'17 }18};1920describe('API Testing - Check Multi-Region Support', () => {21 it('should return the correct resources for each region', (done) => {22 const regions = ['US', 'EU']; //replace with actual regions to be tested23 regions.forEach(region => {24 options.qs = { 'region': region };25 request(options, (error, response, body) => {26 if (error) done(error);27 expect(response.statusCode).to.equal(200); //assuming 200 is the expected status code28 expect(body.region).to.equal(region); //assuming a 'region' field is returned in the response body29 //add more assertions here based on the expected response for each region30 done();31 });32 });33 });34});
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