How can I switch the network profile to offline in automation test using Java?

How can I switch the network profile to offline in automation test using Java?

Hi Miro,

You can use the below code snippet for “Offline” mode in automation using Java:

OkHttpClient client = new OkHttpClient().newBuilder().build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(mediaType, "{\n    \"mode\": \"offline\"\n}");
            String A = "https://mobile-api.lambdatest.com/mobile-automation/api/v1/sessions/"+driver.getSessionId().toString()+"/update_network";
            System.out.println(A);
            Request request = new Request.Builder()
                    .url(A)
                    .method("POST", body)
                    .addHeader("Authorization", "Basic ZGVlcGFuc2h1bGFtYmRhdGVzdDpyc29IVFR4dlJHUU9WN2p2UUpKd1B6S1lRU3lYWUhLcUMzU09nSVdnS0o5RzlzV1piaw==")
                    .addHeader("Content-Type", "application/json")
                    .build();
            Response response = client.newCall(request).execute();
            System.out.println(response.code());
            gridURL = "https://mobile-api.lambdatest.com/mobile-automation/api/v1/sessions/" + driver.getSessionId() + "/update_network";
//            driver.findElement(By.id("android:id/button1")).click();
            Thread.sleep(20000);