How to use Cookie class of org.openqa.selenium package

Best Selenium code snippet using org.openqa.selenium.Cookie

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package configFiles;
2import org.openqa.selenium.*;
3import org.openqa.selenium.logging.Logs;
4
5import java.net.URL;
6import java.util.List;
7import java.util.Set;
8import java.util.concurrent.TimeUnit;
9
10
11import java.net.URL;
12import java.util.List;
13import java.util.Set;
14import java.util.concurrent.TimeUnit;
15import org.openqa.selenium.logging.Logs;
16
17public interface WebdriverTest{
18
19
20    public interface WebDriver extends SearchContext {
21        void get(String var1);
22
23        String getCurrentUrl();
24
25        String getTitle();
26
27        List<WebElement> findElements(By var1);
28
29        WebElement findElement(By var1);
30
31        String getPageSource();
32
33        void close();
34
35        void quit();
36
37        Set<String> getWindowHandles();
38
39        String getWindowHandle();
40
41        org.openqa.selenium.WebDriver.TargetLocator switchTo();
42
43        org.openqa.selenium.WebDriver.Navigation navigate();
44
45        org.openqa.selenium.WebDriver.Options manage();
46
47        @Beta
48        public interface Window {
49            void setSize(Dimension var1);
50
51            void setPosition(Point var1);
52
53            Dimension getSize();
54
55            Point getPosition();
56
57            void maximize();
58        }
59
60        public interface ImeHandler {
61            List<String> getAvailableEngines();
62
63            String getActiveEngine();
64
65            boolean isActivated();
66
67            void deactivate();
68
69            void activateEngine(String var1);
70        }
71
72        public interface Navigation {
73            void back();
74
75            void forward();
76
77            void to(String var1);
78
79            void to(URL var1);
80
81            void refresh();
82        }
83
84        public interface TargetLocator {
85            org.openqa.selenium.WebDriver frame(int var1);
86
87            org.openqa.selenium.WebDriver frame(String var1);
88
89            org.openqa.selenium.WebDriver frame(WebElement var1);
90
91            org.openqa.selenium.WebDriver window(String var1);
92
93            org.openqa.selenium.WebDriver defaultContent();
94
95            WebElement activeElement();
96
97            Alert alert();
98        }
99
100        public interface Timeouts {
101            org.openqa.selenium.WebDriver.Timeouts implicitlyWait(long var1, TimeUnit var3);
102
103            org.openqa.selenium.WebDriver.Timeouts setScriptTimeout(long var1, TimeUnit var3);
104        }
105
106        public interface Options {
107            void addCookie(Cookie var1);
108
109            void deleteCookieNamed(String var1);
110
111            void deleteCookie(Cookie var1);
112
113            void deleteAllCookies();
114
115            Set<Cookie> getCookies();
116
117            Cookie getCookieNamed(String var1);
118
119            org.openqa.selenium.WebDriver.Timeouts timeouts();
120
121            org.openqa.selenium.WebDriver.ImeHandler ime();
122
123            @Beta
124            org.openqa.selenium.WebDriver.Window window();
125
126            @Beta
127            Logs logs();
128        }
129    }
130}
131
Full Screen
copy
1import org.junit.*;
2import java.util.*;
3import org.openqa.selenium.*;
4import io.github.bonigarcia.wdm.WebDriverManager;
5import org.openqa.selenium.JavascriptExecutor;
6import org.openqa.selenium.WebDriver;
7import org.openqa.selenium.WebElement;
8import org.openqa.selenium.chrome.ChromeDriver;
9import org.openqa.selenium.chrome.ChromeOptions;
10import org.openqa.selenium.support.ui.WebDriverWait;
11import org.openqa.selenium.support.ui.ExpectedConditions;
12
13import org.openqa.selenium.By;
14import org.openqa.selenium.NoSuchElementException;
15
16class CookieUse extends Base{
17
18    public CookieUse(WebDriver driver){
19        super(driver);
20        //this.driver.get("https://www.amazon.com/?language=en_US");
21    }
22
23    public Set<Cookie> getCookies(){
24        Login loginpage = new Login(this.driver);
25        ResultPage result = loginpage.doLogin("[email protected]","xxmff14");
26        Set<Cookie> cookies = result.driver.manage().getCookies();
27        //Logout. After open webpage and use cookies login
28        Logout logout = new Logout(result.getDriver());
29        ResultPage result2 = logout.doLogout();
30        result2.waitAndReturnElement(By.className("a-link-nav-icon")).click();
31        return cookies;
32    }
33
34    public ResultPage useCookies(Set<Cookie> cookies){
35        for(Cookie cookie : cookies){
36            this.driver.manage().addCookie(cookie);
37        }
38
39        this.driver.get("https://www.amazon.com/?language=en_US");
40        return new ResultPage(this.driver);
41    }
42
43}
Full Screen
copy
1package TestCases;
2import java.util.List;
3import org.openqa.selenium.WebDriver;
4import org.openqa.selenium.By;
5import org.openqa.selenium.WebElement;
6import org.openqa.selenium.support.ui.Select;
7import java.util.*;
8import org.openqa.selenium.By;
9import org.openqa.selenium.WebElement;
10import org.openqa.selenium.support.ui.Select;
11import java.util.Set;
12import java.util.concurrent.TimeUnit;
13
14import org.openqa.selenium.Cookie;
15
16import org.openqa.selenium.*;
17
18public class DropDown_Multiple
19{
20static WebDriver driver;
21
22public static void ddmethod(WebElement ele,String value)
23{
24	Select sel=new Select(ele);
25	
26	List<WebElement>ddlist=sel.getOptions();	
27	for(WebElement e:ddlist)
28	{
29	     if(e.getText().equals(value))
30	     {
31	    	 e.click();
32	    	 break;
33	     }
34	}
35			
36}
37
38	public static void main(String[] args) {
39		driver=BrowserFactory.startApplication(driver,"Chrome","https://www.orangehrm.com/orangehrm-30-day-trial/");
40		
41		driver.manage().window().maximize();
42		driver.get("https://www.orangehrm.com/orangehrm-30-day-trial/");
43		//driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
44		Set<Cookie>cookies=driver.manage().getCookies();
45		System.out.println(" Total cookies "+cookies.size());
46		
47		for(Cookie cookie:cookies)
48		{			
49			System.out.println(cookie.getClass()+" " +cookie.getValue());
50			System.out.println(cookie.getPath());
51		}
52		
53		//driver.findElement(By.xpath("//div[@class='optanon-alert-box-button optanon-button-allow']//a[@class='optanon-allow-all accept-cookies-button']")).click();
54		//driver.findElement(By.name("//div[@class='optanon-alert-box-button-middle accept-cookie-container']")).click();;
55		WebElement DD_Employees=driver.findElement(By.name("NoOfEmployees"));
56		ddmethod(DD_Employees,"16 - 20");
57		WebElement DD_Country=driver.findElement(By.name("Country"));
58		ddmethod(DD_Country,"Ghana");
59		WebElement DD_Industry=driver.findElement(By.name("'Industry"));
60		ddmethod(DD_Industry,"Healthcare");
61		
62		
63		
64		
65		
66		
67		
68	}
69
70}
71
Full Screen
copy
1var uri = URI.create("https://httpbin.org/get?age=26&isHappy=true");
2var client = HttpClient.newHttpClient();
3var request = HttpRequest
4        .newBuilder()
5        .uri(uri)
6        .header("accept", "application/json")
7        .GET()
8        .build();
9var response = client.send(request, HttpResponse.BodyHandlers.ofString());
10System.out.println(response.statusCode());
11System.out.println(response.body());
12
Full Screen
copy
1var responseAsync = client
2        .sendAsync(request, HttpResponse.BodyHandlers.ofString())
3        .thenApply(HttpResponse::body)
4        .thenAccept(System.out::println);
5// responseAsync.join(); // Wait for completion
6
Full Screen
copy
1var request = HttpRequest
2        .newBuilder()
3        .uri(uri)
4        .version(HttpClient.Version.HTTP_2)
5        .timeout(Duration.ofMinutes(1))
6        .header("Content-Type", "application/json")
7        .header("Authorization", "Bearer fake")
8        .POST(BodyPublishers.ofString("{ title: 'This is cool' }"))
9        .build();
10var response = client.send(request, HttpResponse.BodyHandlers.ofString());
11
Full Screen
copy
1String html = new JdkRequest("http://www.google.com").fetch().body();
2
Full Screen
copy
1OkHttpClient client = new OkHttpClient();
2
Full Screen
copy
1Request request = new Request.Builder()
2      .url(url)
3      .build();
4
Full Screen
copy
1Response response = client.newCall(request).execute();
2
Full Screen
copy
1package org.boon.utils;
2
3import java.io.IOException;
4import java.io.InputStream;
5import java.net.HttpURLConnection;
6import java.net.URL;
7import java.net.URLConnection;
8import java.util.Map;
9
10import static org.boon.utils.IO.read;
11
12public class HTTP {
13
Full Screen
copy
1public static String get(
2        final String url) {
3
4    Exceptions.tryIt(() -> {
5        URLConnection connection;
6        connection = doGet(url, null, null, null);
7        return extractResponseString(connection);
8    });
9    return null;
10}
11
12public static String getWithHeaders(
13        final String url,
14        final Map<String, ? extends Object> headers) {
15    URLConnection connection;
16    try {
17        connection = doGet(url, headers, null, null);
18        return extractResponseString(connection);
19    } catch (Exception ex) {
20        Exceptions.handle(ex);
21        return null;
22    }
23}
24
25public static String getWithContentType(
26        final String url,
27        final Map<String, ? extends Object> headers,
28        String contentType) {
29    URLConnection connection;
30    try {
31        connection = doGet(url, headers, contentType, null);
32        return extractResponseString(connection);
33    } catch (Exception ex) {
34        Exceptions.handle(ex);
35        return null;
36    }
37}
38public static String getWithCharSet(
39        final String url,
40        final Map<String, ? extends Object> headers,
41        String contentType,
42        String charSet) {
43    URLConnection connection;
44    try {
45        connection = doGet(url, headers, contentType, charSet);
46        return extractResponseString(connection);
47    } catch (Exception ex) {
48        Exceptions.handle(ex);
49        return null;
50    }
51}
52
Full Screen
copy
1public static String postBody(
2        final String url,
3        final String body) {
4    URLConnection connection;
5    try {
6        connection = doPost(url, null, "text/plain", null, body);
7        return extractResponseString(connection);
8    } catch (Exception ex) {
9        Exceptions.handle(ex);
10        return null;
11    }
12}
13
14public static String postBodyWithHeaders(
15        final String url,
16        final Map<String, ? extends Object> headers,
17        final String body) {
18    URLConnection connection;
19    try {
20        connection = doPost(url, headers, "text/plain", null, body);
21        return extractResponseString(connection);
22    } catch (Exception ex) {
23        Exceptions.handle(ex);
24        return null;
25    }
26}
27
28
29public static String postBodyWithContentType(
30        final String url,
31        final Map<String, ? extends Object> headers,
32        final String contentType,
33        final String body) {
34
35    URLConnection connection;
36    try {
37        connection = doPost(url, headers, contentType, null, body);
38
39        return extractResponseString(connection);
40
41    } catch (Exception ex) {
42        Exceptions.handle(ex);
43        return null;
44    }
45
46}
47
48
49public static String postBodyWithCharset(
50        final String url,
51        final Map<String, ? extends Object> headers,
52        final String contentType,
53        final String charSet,
54        final String body) {
55
56    URLConnection connection;
57    try {
58        connection = doPost(url, headers, contentType, charSet, body);
59
60        return extractResponseString(connection);
61
62    } catch (Exception ex) {
63        Exceptions.handle(ex);
64        return null;
65    }
66}
67
68private static URLConnection doPost(String url, Map<String, ? extends Object> headers,
69                                    String contentType, String charset, String body
70                                    ) throws IOException {
71    URLConnection connection;/* Handle output. */
72    connection = new URL(url).openConnection();
73    connection.setDoOutput(true);
74    manageContentTypeHeaders(contentType, charset, connection);
75
76    manageHeaders(headers, connection);
77
78    IO.write(connection.getOutputStream(), body, IO.CHARSET);
79    return connection;
80}
81
82private static void manageHeaders(Map<String, ? extends Object> headers, URLConnection connection) {
83    if (headers != null) {
84        for (Map.Entry<String, ? extends Object> entry : headers.entrySet()) {
85            connection.setRequestProperty(entry.getKey(), entry.getValue().toString());
86        }
87    }
88}
89
90private static void manageContentTypeHeaders(String contentType, String charset, URLConnection connection) {
91    connection.setRequestProperty("Accept-Charset", charset == null ? IO.CHARSET : charset);
92    if (contentType!=null && !contentType.isEmpty()) {
93        connection.setRequestProperty("Content-Type", contentType);
94    }
95}
96
97private static URLConnection doGet(String url, Map<String, ? extends Object> headers,
98                                    String contentType, String charset) throws IOException {
99    URLConnection connection;/* Handle output. */
100    connection = new URL(url).openConnection();
101    manageContentTypeHeaders(contentType, charset, connection);
102
103    manageHeaders(headers, connection);
104
105    return connection;
106}
107
108private static String extractResponseString(URLConnection connection) throws IOException {
109/* Handle input. */
110    HttpURLConnection http = (HttpURLConnection)connection;
111    int status = http.getResponseCode();
112    String charset = getCharset(connection.getHeaderField("Content-Type"));
113
114    if (status==200) {
115        return readResponseBody(http, charset);
116    } else {
117        return readErrorResponseBody(http, status, charset);
118    }
119}
120
121private static String readErrorResponseBody(HttpURLConnection http, int status, String charset) {
122    InputStream errorStream = http.getErrorStream();
123    if ( errorStream!=null ) {
124        String error = charset== null ? read( errorStream ) :
125            read( errorStream, charset );
126        throw new RuntimeException("STATUS CODE =" + status + "\n\n" + error);
127    } else {
128        throw new RuntimeException("STATUS CODE =" + status);
129    }
130}
131
132private static String readResponseBody(HttpURLConnection http, String charset) throws IOException {
133    if (charset != null) {
134        return read(http.getInputStream(), charset);
135    } else {
136        return read(http.getInputStream());
137    }
138}
139
140private static String getCharset(String contentType) {
141    if (contentType==null)  {
142        return null;
143    }
144    String charset = null;
145    for (String param : contentType.replace(" ", "").split(";")) {
146        if (param.startsWith("charset=")) {
147            charset = param.split("=", 2)[1];
148            break;
149        }
150    }
151    charset = charset == null ? IO.CHARSET : charset;
152
153    return charset;
154}
155
Full Screen
copy
1static class MyHandler implements HttpHandler {
2    public void handle(HttpExchange t) throws IOException {
3
4        InputStream requestBody = t.getRequestBody();
5        String body = IO.read(requestBody);
6        Headers requestHeaders = t.getRequestHeaders();
7        body = body + "\n" + copy(requestHeaders).toString();
8        t.sendResponseHeaders(200, body.length());
9        OutputStream os = t.getResponseBody();
10        os.write(body.getBytes());
11        os.close();
12    }
13}
14
15
16@Test
17public void testHappy() throws Exception {
18
19    HttpServer server = HttpServer.create(new InetSocketAddress(9212), 0);
20    server.createContext("/test", new MyHandler());
21    server.setExecutor(null); // creates a default executor
22    server.start();
23
24    Thread.sleep(10);
25
26    Map<String,String> headers = map("foo", "bar", "fun", "sun");
27
28    String response = HTTP.postBodyWithContentType("http://localhost:9212/test", headers, "text/plain", "hi mom");
29
30    System.out.println(response);
31
32    assertTrue(response.contains("hi mom"));
33    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
34
35    response = HTTP.postBodyWithCharset("http://localhost:9212/test", headers, "text/plain", "UTF-8", "hi mom");
36
37    System.out.println(response);
38
39    assertTrue(response.contains("hi mom"));
40    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
41
42    response = HTTP.postBodyWithHeaders("http://localhost:9212/test", headers, "hi mom");
43
44    System.out.println(response);
45
46    assertTrue(response.contains("hi mom"));
47    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
48
49    response = HTTP.get("http://localhost:9212/test");
50
51    System.out.println(response);
52
53    response = HTTP.getWithHeaders("http://localhost:9212/test", headers);
54
55    System.out.println(response);
56
57    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
58
59    response = HTTP.getWithContentType("http://localhost:9212/test", headers, "text/plain");
60
61    System.out.println(response);
62
63    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
64
65    response = HTTP.getWithCharSet("http://localhost:9212/test", headers, "text/plain", "UTF-8");
66
67    System.out.println(response);
68
69    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
70
71    Thread.sleep(10);
72
73    server.stop(0);
74}
75
76@Test
77public void testPostBody() throws Exception {
78
79    HttpServer server = HttpServer.create(new InetSocketAddress(9220), 0);
80    server.createContext("/test", new MyHandler());
81    server.setExecutor(null); // creates a default executor
82    server.start();
83
84    Thread.sleep(10);
85
86    Map<String,String> headers = map("foo", "bar", "fun", "sun");
87
88    String response = HTTP.postBody("http://localhost:9220/test", "hi mom");
89
90    assertTrue(response.contains("hi mom"));
91
92    Thread.sleep(10);
93
94    server.stop(0);
95}
96
97@Test(expected = RuntimeException.class)
98public void testSad() throws Exception {
99
100    HttpServer server = HttpServer.create(new InetSocketAddress(9213), 0);
101    server.createContext("/test", new MyHandler());
102    server.setExecutor(null); // creates a default executor
103    server.start();
104
105    Thread.sleep(10);
106
107    Map<String,String> headers = map("foo", "bar", "fun", "sun");
108
109    String response = HTTP.postBodyWithContentType("http://localhost:9213/foo", headers, "text/plain", "hi mom");
110
111    System.out.println(response);
112
113    assertTrue(response.contains("hi mom"));
114    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
115
116    Thread.sleep(10);
117
118    server.stop(0);
119}
120
Full Screen
copy
1HttpURLConnection.setFollowRedirects(true); // Defaults to true
2
3String url = "https://name_of_the_url";
4URL request_url = new URL(url);
5HttpURLConnection http_conn = (HttpURLConnection)request_url.openConnection();
6http_conn.setConnectTimeout(100000);
7http_conn.setReadTimeout(100000);
8http_conn.setInstanceFollowRedirects(true);
9System.out.println(String.valueOf(http_conn.getResponseCode()));
10
Full Screen
copy
1HttpURLConnection.setFollowRedirects(true); // Defaults to true
2
3String url = "https://name_of_the_url"
4URL request_url = new URL(url);
5HttpURLConnection http_conn = (HttpURLConnection)request_url.openConnection();
6http_conn.setConnectTimeout(100000);
7http_conn.setReadTimeout(100000);
8http_conn.setInstanceFollowRedirects(true);
9http_conn.setDoOutput(true);
10PrintWriter out = new PrintWriter(http_conn.getOutputStream());
11if (urlparameter != null) {
12   out.println(urlparameter);
13}
14out.close();
15out = null;
16System.out.println(String.valueOf(http_conn.getResponseCode()));
17
Full Screen
copy
1// GET
2HttpResponse response = HttpRequest
3    .create(new URI("http://www.stackoverflow.com"))
4    .headers("Foo", "foovalue", "Bar", "barvalue")
5    .GET()
6    .response();
7
Full Screen
copy
1int statusCode = response.statusCode();
2String responseBody = response.body(HttpResponse.asString());
3
Full Screen
copy
1module com.foo.bar {
2    requires jdk.incubator.httpclient;
3}
4
Full Screen
copy
1// GET http://google.com?q=baseball%20gloves&size=100
2String response = HttpRequest.get("http://google.com", true, "q", "baseball gloves", "size", 100)
3        .accept("application/json")
4        .body();
5System.out.println("Response was: " + response);
6
Full Screen
copy
1int responseCode = httpURLConnection.getResponseCode();
2
3if (responseCode == HttpURLConnection.HTTP_OK) {
4
Full Screen
copy
1String url = "http://example.com";
2String charset = "UTF-8";  // Or in Java 7 and later, use the constant: java.nio.charset.StandardCharsets.UTF_8.name()
3String param1 = "value1";
4String param2 = "value2";
5// ...
6
7String query = String.format("param1=%s&param2=%s",
8    URLEncoder.encode(param1, charset),
9    URLEncoder.encode(param2, charset));
10
Full Screen
copy
1URLConnection connection = new URL(url + "?" + query).openConnection();
2connection.setRequestProperty("Accept-Charset", charset);
3InputStream response = connection.getInputStream();
4// ...
5
Full Screen
copy
1InputStream response = new URL(url).openStream();
2// ...
3
Full Screen
copy
1try (Scanner scanner = new Scanner(response)) {
2    String responseBody = scanner.useDelimiter("\\A").next();
3    System.out.println(responseBody);
4}
5
Full Screen
copy
1URLConnection connection = new URL(url).openConnection();
2connection.setDoOutput(true); // Triggers POST.
3connection.setRequestProperty("Accept-Charset", charset);
4connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
5
6try (OutputStream output = connection.getOutputStream()) {
7    output.write(query.getBytes(charset));
8}
9
10InputStream response = connection.getInputStream();
11// ...
12
Full Screen
copy
1HttpURLConnection httpConnection = (HttpURLConnection) new URL(url).openConnection();
2httpConnection.setRequestMethod("POST");
3// ...
4
Full Screen
copy
1    int status = httpConnection.getResponseCode();
2
Full Screen
copy
1    String contentType = connection.getHeaderField("Content-Type");
2    String charset = null;
3
4    for (String param : contentType.replace(" ", "").split(";")) {
5        if (param.startsWith("charset=")) {
6            charset = param.split("=", 2)[1];
7            break;
8        }
9    }
10
11    if (charset != null) {
12        try (BufferedReader reader = new BufferedReader(new InputStreamReader(response, charset))) {
13            for (String line; (line = reader.readLine()) != null;) {
14                // ... System.out.println(line)?
15            }
16        }
17    } else {
18        // It's likely binary content, use InputStream/OutputStream.
19    }
20
Full Screen
copy
1// First set the default cookie manager.
2CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
3
4// All the following subsequent URLConnections will use the same cookie manager.
5URLConnection connection = new URL(url).openConnection();
6// ...
7
8connection = new URL(url).openConnection();
9// ...
10
11connection = new URL(url).openConnection();
12// ...
13
Full Screen
copy
1// Gather all cookies on the first request.
2URLConnection connection = new URL(url).openConnection();
3List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
4// ...
5
6// Then use the same cookies on all subsequent requests.
7connection = new URL(url).openConnection();
8for (String cookie : cookies) {
9    connection.addRequestProperty("Cookie", cookie.split(";", 2)[0]);
10}
11// ...
12
Full Screen
copy
1httpConnection.setFixedLengthStreamingMode(contentLength);
2
Full Screen
copy
1httpConnection.setChunkedStreamingMode(1024);
2
Full Screen
copy
1connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); // Do as if you're using Chrome 41 on Windows 7.
2
Full Screen
copy
1InputStream error = ((HttpURLConnection) connection).getErrorStream();
2
Full Screen
copy
1System.setProperty("http.keepAlive", "false");
2
Full Screen
copy
1String param = "value";
2File textFile = new File("/path/to/file.txt");
3File binaryFile = new File("/path/to/file.bin");
4String boundary = Long.toHexString(System.currentTimeMillis()); // Just generate some unique random value.
5String CRLF = "\r\n"; // Line separator required by multipart/form-data.
6URLConnection connection = new URL(url).openConnection();
7connection.setDoOutput(true);
8connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
9
10try (
11    OutputStream output = connection.getOutputStream();
12    PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true);
13) {
14    // Send normal param.
15    writer.append("--" + boundary).append(CRLF);
16    writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);
17    writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF);
18    writer.append(CRLF).append(param).append(CRLF).flush();
19
20    // Send text file.
21    writer.append("--" + boundary).append(CRLF);
22    writer.append("Content-Disposition: form-data; name=\"textFile\"; filename=\"" + textFile.getName() + "\"").append(CRLF);
23    writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF); // Text file itself must be saved in this charset!
24    writer.append(CRLF).flush();
25    Files.copy(textFile.toPath(), output);
26    output.flush(); // Important before continuing with writer!
27    writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary.
28
29    // Send binary file.
30    writer.append("--" + boundary).append(CRLF);
31    writer.append("Content-Disposition: form-data; name=\"binaryFile\"; filename=\"" + binaryFile.getName() + "\"").append(CRLF);
32    writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(binaryFile.getName())).append(CRLF);
33    writer.append("Content-Transfer-Encoding: binary").append(CRLF);
34    writer.append(CRLF).flush();
35    Files.copy(binaryFile.toPath(), output);
36    output.flush(); // Important before continuing with writer!
37    writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary.
38
39    // End of multipart/form-data.
40    writer.append("--" + boundary + "--").append(CRLF).flush();
41}
42
Full Screen
copy
1static {
2    TrustManager[] trustAllCertificates = new TrustManager[] {
3        new X509TrustManager() {
4            @Override
5            public X509Certificate[] getAcceptedIssuers() {
6                return null; // Not relevant.
7            }
8            @Override
9            public void checkClientTrusted(X509Certificate[] certs, String authType) {
10                // Do nothing. Just allow them all.
11            }
12            @Override
13            public void checkServerTrusted(X509Certificate[] certs, String authType) {
14                // Do nothing. Just allow them all.
15            }
16        }
17    };
18
19    HostnameVerifier trustAllHostnames = new HostnameVerifier() {
20        @Override
21        public boolean verify(String hostname, SSLSession session) {
22            return true; // Just allow them all.
23        }
24    };
25
26    try {
27        System.setProperty("jsse.enableSNIExtension", "false");
28        SSLContext sc = SSLContext.getInstance("SSL");
29        sc.init(null, trustAllCertificates, new SecureRandom());
30        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
31        HttpsURLConnection.setDefaultHostnameVerifier(trustAllHostnames);
32    }
33    catch (GeneralSecurityException e) {
34        throw new ExceptionInInitializerError(e);
35    }
36}
37
Full Screen
copy
1var uri = URI.create("https://httpbin.org/get?age=26&isHappy=true");
2var client = HttpClient.newHttpClient();
3var request = HttpRequest
4        .newBuilder()
5        .uri(uri)
6        .header("accept", "application/json")
7        .GET()
8        .build();
9var response = client.send(request, HttpResponse.BodyHandlers.ofString());
10System.out.println(response.statusCode());
11System.out.println(response.body());
12
Full Screen
copy
1var responseAsync = client
2        .sendAsync(request, HttpResponse.BodyHandlers.ofString())
3        .thenApply(HttpResponse::body)
4        .thenAccept(System.out::println);
5// responseAsync.join(); // Wait for completion
6
Full Screen
copy
1var request = HttpRequest
2        .newBuilder()
3        .uri(uri)
4        .version(HttpClient.Version.HTTP_2)
5        .timeout(Duration.ofMinutes(1))
6        .header("Content-Type", "application/json")
7        .header("Authorization", "Bearer fake")
8        .POST(BodyPublishers.ofString("{ title: 'This is cool' }"))
9        .build();
10var response = client.send(request, HttpResponse.BodyHandlers.ofString());
11
Full Screen
copy
1String html = new JdkRequest("http://www.google.com").fetch().body();
2
Full Screen
copy
1OkHttpClient client = new OkHttpClient();
2
Full Screen
copy
1Request request = new Request.Builder()
2      .url(url)
3      .build();
4
Full Screen
copy
1Response response = client.newCall(request).execute();
2
Full Screen
copy
1package org.boon.utils;
2
3import java.io.IOException;
4import java.io.InputStream;
5import java.net.HttpURLConnection;
6import java.net.URL;
7import java.net.URLConnection;
8import java.util.Map;
9
10import static org.boon.utils.IO.read;
11
12public class HTTP {
13
Full Screen
copy
1public static String get(
2        final String url) {
3
4    Exceptions.tryIt(() -> {
5        URLConnection connection;
6        connection = doGet(url, null, null, null);
7        return extractResponseString(connection);
8    });
9    return null;
10}
11
12public static String getWithHeaders(
13        final String url,
14        final Map<String, ? extends Object> headers) {
15    URLConnection connection;
16    try {
17        connection = doGet(url, headers, null, null);
18        return extractResponseString(connection);
19    } catch (Exception ex) {
20        Exceptions.handle(ex);
21        return null;
22    }
23}
24
25public static String getWithContentType(
26        final String url,
27        final Map<String, ? extends Object> headers,
28        String contentType) {
29    URLConnection connection;
30    try {
31        connection = doGet(url, headers, contentType, null);
32        return extractResponseString(connection);
33    } catch (Exception ex) {
34        Exceptions.handle(ex);
35        return null;
36    }
37}
38public static String getWithCharSet(
39        final String url,
40        final Map<String, ? extends Object> headers,
41        String contentType,
42        String charSet) {
43    URLConnection connection;
44    try {
45        connection = doGet(url, headers, contentType, charSet);
46        return extractResponseString(connection);
47    } catch (Exception ex) {
48        Exceptions.handle(ex);
49        return null;
50    }
51}
52
Full Screen
copy
1public static String postBody(
2        final String url,
3        final String body) {
4    URLConnection connection;
5    try {
6        connection = doPost(url, null, "text/plain", null, body);
7        return extractResponseString(connection);
8    } catch (Exception ex) {
9        Exceptions.handle(ex);
10        return null;
11    }
12}
13
14public static String postBodyWithHeaders(
15        final String url,
16        final Map<String, ? extends Object> headers,
17        final String body) {
18    URLConnection connection;
19    try {
20        connection = doPost(url, headers, "text/plain", null, body);
21        return extractResponseString(connection);
22    } catch (Exception ex) {
23        Exceptions.handle(ex);
24        return null;
25    }
26}
27
28
29public static String postBodyWithContentType(
30        final String url,
31        final Map<String, ? extends Object> headers,
32        final String contentType,
33        final String body) {
34
35    URLConnection connection;
36    try {
37        connection = doPost(url, headers, contentType, null, body);
38
39        return extractResponseString(connection);
40
41    } catch (Exception ex) {
42        Exceptions.handle(ex);
43        return null;
44    }
45
46}
47
48
49public static String postBodyWithCharset(
50        final String url,
51        final Map<String, ? extends Object> headers,
52        final String contentType,
53        final String charSet,
54        final String body) {
55
56    URLConnection connection;
57    try {
58        connection = doPost(url, headers, contentType, charSet, body);
59
60        return extractResponseString(connection);
61
62    } catch (Exception ex) {
63        Exceptions.handle(ex);
64        return null;
65    }
66}
67
68private static URLConnection doPost(String url, Map<String, ? extends Object> headers,
69                                    String contentType, String charset, String body
70                                    ) throws IOException {
71    URLConnection connection;/* Handle output. */
72    connection = new URL(url).openConnection();
73    connection.setDoOutput(true);
74    manageContentTypeHeaders(contentType, charset, connection);
75
76    manageHeaders(headers, connection);
77
78    IO.write(connection.getOutputStream(), body, IO.CHARSET);
79    return connection;
80}
81
82private static void manageHeaders(Map<String, ? extends Object> headers, URLConnection connection) {
83    if (headers != null) {
84        for (Map.Entry<String, ? extends Object> entry : headers.entrySet()) {
85            connection.setRequestProperty(entry.getKey(), entry.getValue().toString());
86        }
87    }
88}
89
90private static void manageContentTypeHeaders(String contentType, String charset, URLConnection connection) {
91    connection.setRequestProperty("Accept-Charset", charset == null ? IO.CHARSET : charset);
92    if (contentType!=null && !contentType.isEmpty()) {
93        connection.setRequestProperty("Content-Type", contentType);
94    }
95}
96
97private static URLConnection doGet(String url, Map<String, ? extends Object> headers,
98                                    String contentType, String charset) throws IOException {
99    URLConnection connection;/* Handle output. */
100    connection = new URL(url).openConnection();
101    manageContentTypeHeaders(contentType, charset, connection);
102
103    manageHeaders(headers, connection);
104
105    return connection;
106}
107
108private static String extractResponseString(URLConnection connection) throws IOException {
109/* Handle input. */
110    HttpURLConnection http = (HttpURLConnection)connection;
111    int status = http.getResponseCode();
112    String charset = getCharset(connection.getHeaderField("Content-Type"));
113
114    if (status==200) {
115        return readResponseBody(http, charset);
116    } else {
117        return readErrorResponseBody(http, status, charset);
118    }
119}
120
121private static String readErrorResponseBody(HttpURLConnection http, int status, String charset) {
122    InputStream errorStream = http.getErrorStream();
123    if ( errorStream!=null ) {
124        String error = charset== null ? read( errorStream ) :
125            read( errorStream, charset );
126        throw new RuntimeException("STATUS CODE =" + status + "\n\n" + error);
127    } else {
128        throw new RuntimeException("STATUS CODE =" + status);
129    }
130}
131
132private static String readResponseBody(HttpURLConnection http, String charset) throws IOException {
133    if (charset != null) {
134        return read(http.getInputStream(), charset);
135    } else {
136        return read(http.getInputStream());
137    }
138}
139
140private static String getCharset(String contentType) {
141    if (contentType==null)  {
142        return null;
143    }
144    String charset = null;
145    for (String param : contentType.replace(" ", "").split(";")) {
146        if (param.startsWith("charset=")) {
147            charset = param.split("=", 2)[1];
148            break;
149        }
150    }
151    charset = charset == null ? IO.CHARSET : charset;
152
153    return charset;
154}
155
Full Screen
copy
1static class MyHandler implements HttpHandler {
2    public void handle(HttpExchange t) throws IOException {
3
4        InputStream requestBody = t.getRequestBody();
5        String body = IO.read(requestBody);
6        Headers requestHeaders = t.getRequestHeaders();
7        body = body + "\n" + copy(requestHeaders).toString();
8        t.sendResponseHeaders(200, body.length());
9        OutputStream os = t.getResponseBody();
10        os.write(body.getBytes());
11        os.close();
12    }
13}
14
15
16@Test
17public void testHappy() throws Exception {
18
19    HttpServer server = HttpServer.create(new InetSocketAddress(9212), 0);
20    server.createContext("/test", new MyHandler());
21    server.setExecutor(null); // creates a default executor
22    server.start();
23
24    Thread.sleep(10);
25
26    Map<String,String> headers = map("foo", "bar", "fun", "sun");
27
28    String response = HTTP.postBodyWithContentType("http://localhost:9212/test", headers, "text/plain", "hi mom");
29
30    System.out.println(response);
31
32    assertTrue(response.contains("hi mom"));
33    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
34
35    response = HTTP.postBodyWithCharset("http://localhost:9212/test", headers, "text/plain", "UTF-8", "hi mom");
36
37    System.out.println(response);
38
39    assertTrue(response.contains("hi mom"));
40    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
41
42    response = HTTP.postBodyWithHeaders("http://localhost:9212/test", headers, "hi mom");
43
44    System.out.println(response);
45
46    assertTrue(response.contains("hi mom"));
47    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
48
49    response = HTTP.get("http://localhost:9212/test");
50
51    System.out.println(response);
52
53    response = HTTP.getWithHeaders("http://localhost:9212/test", headers);
54
55    System.out.println(response);
56
57    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
58
59    response = HTTP.getWithContentType("http://localhost:9212/test", headers, "text/plain");
60
61    System.out.println(response);
62
63    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
64
65    response = HTTP.getWithCharSet("http://localhost:9212/test", headers, "text/plain", "UTF-8");
66
67    System.out.println(response);
68
69    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
70
71    Thread.sleep(10);
72
73    server.stop(0);
74}
75
76@Test
77public void testPostBody() throws Exception {
78
79    HttpServer server = HttpServer.create(new InetSocketAddress(9220), 0);
80    server.createContext("/test", new MyHandler());
81    server.setExecutor(null); // creates a default executor
82    server.start();
83
84    Thread.sleep(10);
85
86    Map<String,String> headers = map("foo", "bar", "fun", "sun");
87
88    String response = HTTP.postBody("http://localhost:9220/test", "hi mom");
89
90    assertTrue(response.contains("hi mom"));
91
92    Thread.sleep(10);
93
94    server.stop(0);
95}
96
97@Test(expected = RuntimeException.class)
98public void testSad() throws Exception {
99
100    HttpServer server = HttpServer.create(new InetSocketAddress(9213), 0);
101    server.createContext("/test", new MyHandler());
102    server.setExecutor(null); // creates a default executor
103    server.start();
104
105    Thread.sleep(10);
106
107    Map<String,String> headers = map("foo", "bar", "fun", "sun");
108
109    String response = HTTP.postBodyWithContentType("http://localhost:9213/foo", headers, "text/plain", "hi mom");
110
111    System.out.println(response);
112
113    assertTrue(response.contains("hi mom"));
114    assertTrue(response.contains("Fun=[sun], Foo=[bar]"));
115
116    Thread.sleep(10);
117
118    server.stop(0);
119}
120
Full Screen
copy
1HttpURLConnection.setFollowRedirects(true); // Defaults to true
2
3String url = "https://name_of_the_url";
4URL request_url = new URL(url);
5HttpURLConnection http_conn = (HttpURLConnection)request_url.openConnection();
6http_conn.setConnectTimeout(100000);
7http_conn.setReadTimeout(100000);
8http_conn.setInstanceFollowRedirects(true);
9System.out.println(String.valueOf(http_conn.getResponseCode()));
10
Full Screen
copy
1HttpURLConnection.setFollowRedirects(true); // Defaults to true
2
3String url = "https://name_of_the_url"
4URL request_url = new URL(url);
5HttpURLConnection http_conn = (HttpURLConnection)request_url.openConnection();
6http_conn.setConnectTimeout(100000);
7http_conn.setReadTimeout(100000);
8http_conn.setInstanceFollowRedirects(true);
9http_conn.setDoOutput(true);
10PrintWriter out = new PrintWriter(http_conn.getOutputStream());
11if (urlparameter != null) {
12   out.println(urlparameter);
13}
14out.close();
15out = null;
16System.out.println(String.valueOf(http_conn.getResponseCode()));
17
Full Screen
copy
1// GET
2HttpResponse response = HttpRequest
3    .create(new URI("http://www.stackoverflow.com"))
4    .headers("Foo", "foovalue", "Bar", "barvalue")
5    .GET()
6    .response();
7
Full Screen
copy
1int statusCode = response.statusCode();
2String responseBody = response.body(HttpResponse.asString());
3
Full Screen
copy
1module com.foo.bar {
2    requires jdk.incubator.httpclient;
3}
4
Full Screen
copy
1// GET http://google.com?q=baseball%20gloves&size=100
2String response = HttpRequest.get("http://google.com", true, "q", "baseball gloves", "size", 100)
3        .accept("application/json")
4        .body();
5System.out.println("Response was: " + response);
6
Full Screen
copy
1int responseCode = httpURLConnection.getResponseCode();
2
3if (responseCode == HttpURLConnection.HTTP_OK) {
4
Full Screen
copy
1String url = "http://example.com";
2String charset = "UTF-8";  // Or in Java 7 and later, use the constant: java.nio.charset.StandardCharsets.UTF_8.name()
3String param1 = "value1";
4String param2 = "value2";
5// ...
6
7String query = String.format("param1=%s&param2=%s",
8    URLEncoder.encode(param1, charset),
9    URLEncoder.encode(param2, charset));
10
Full Screen
copy
1URLConnection connection = new URL(url + "?" + query).openConnection();
2connection.setRequestProperty("Accept-Charset", charset);
3InputStream response = connection.getInputStream();
4// ...
5
Full Screen
copy
1InputStream response = new URL(url).openStream();
2// ...
3
Full Screen
copy
1try (Scanner scanner = new Scanner(response)) {
2    String responseBody = scanner.useDelimiter("\\A").next();
3    System.out.println(responseBody);
4}
5
Full Screen
copy
1URLConnection connection = new URL(url).openConnection();
2connection.setDoOutput(true); // Triggers POST.
3connection.setRequestProperty("Accept-Charset", charset);
4connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
5
6try (OutputStream output = connection.getOutputStream()) {
7    output.write(query.getBytes(charset));
8}
9
10InputStream response = connection.getInputStream();
11// ...
12
Full Screen
copy
1HttpURLConnection httpConnection = (HttpURLConnection) new URL(url).openConnection();
2httpConnection.setRequestMethod("POST");
3// ...
4
Full Screen
copy
1    int status = httpConnection.getResponseCode();
2
Full Screen
copy
1    String contentType = connection.getHeaderField("Content-Type");
2    String charset = null;
3
4    for (String param : contentType.replace(" ", "").split(";")) {
5        if (param.startsWith("charset=")) {
6            charset = param.split("=", 2)[1];
7            break;
8        }
9    }
10
11    if (charset != null) {
12        try (BufferedReader reader = new BufferedReader(new InputStreamReader(response, charset))) {
13            for (String line; (line = reader.readLine()) != null;) {
14                // ... System.out.println(line)?
15            }
16        }
17    } else {
18        // It's likely binary content, use InputStream/OutputStream.
19    }
20
Full Screen
copy
1// First set the default cookie manager.
2CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
3
4// All the following subsequent URLConnections will use the same cookie manager.
5URLConnection connection = new URL(url).openConnection();
6// ...
7
8connection = new URL(url).openConnection();
9// ...
10
11connection = new URL(url).openConnection();
12// ...
13
Full Screen
copy
1// Gather all cookies on the first request.
2URLConnection connection = new URL(url).openConnection();
3List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
4// ...
5
6// Then use the same cookies on all subsequent requests.
7connection = new URL(url).openConnection();
8for (String cookie : cookies) {
9    connection.addRequestProperty("Cookie", cookie.split(";", 2)[0]);
10}
11// ...
12
Full Screen
copy
1httpConnection.setFixedLengthStreamingMode(contentLength);
2
Full Screen
copy
1httpConnection.setChunkedStreamingMode(1024);
2
Full Screen
copy
1connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); // Do as if you're using Chrome 41 on Windows 7.
2
Full Screen
copy
1InputStream error = ((HttpURLConnection) connection).getErrorStream();
2
Full Screen
copy
1System.setProperty("http.keepAlive", "false");
2
Full Screen
copy
1String param = "value";
2File textFile = new File("/path/to/file.txt");
3File binaryFile = new File("/path/to/file.bin");
4String boundary = Long.toHexString(System.currentTimeMillis()); // Just generate some unique random value.
5String CRLF = "\r\n"; // Line separator required by multipart/form-data.
6URLConnection connection = new URL(url).openConnection();
7connection.setDoOutput(true);
8connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
9
10try (
11    OutputStream output = connection.getOutputStream();
12    PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true);
13) {
14    // Send normal param.
15    writer.append("--" + boundary).append(CRLF);
16    writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);
17    writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF);
18    writer.append(CRLF).append(param).append(CRLF).flush();
19
20    // Send text file.
21    writer.append("--" + boundary).append(CRLF);
22    writer.append("Content-Disposition: form-data; name=\"textFile\"; filename=\"" + textFile.getName() + "\"").append(CRLF);
23    writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF); // Text file itself must be saved in this charset!
24    writer.append(CRLF).flush();
25    Files.copy(textFile.toPath(), output);
26    output.flush(); // Important before continuing with writer!
27    writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary.
28
29    // Send binary file.
30    writer.append("--" + boundary).append(CRLF);
31    writer.append("Content-Disposition: form-data; name=\"binaryFile\"; filename=\"" + binaryFile.getName() + "\"").append(CRLF);
32    writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(binaryFile.getName())).append(CRLF);
33    writer.append("Content-Transfer-Encoding: binary").append(CRLF);
34    writer.append(CRLF).flush();
35    Files.copy(binaryFile.toPath(), output);
36    output.flush(); // Important before continuing with writer!
37    writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary.
38
39    // End of multipart/form-data.
40    writer.append("--" + boundary + "--").append(CRLF).flush();
41}
42
Full Screen
copy
1static {
2    TrustManager[] trustAllCertificates = new TrustManager[] {
3        new X509TrustManager() {
4            @Override
5            public X509Certificate[] getAcceptedIssuers() {
6                return null; // Not relevant.
7            }
8            @Override
9            public void checkClientTrusted(X509Certificate[] certs, String authType) {
10                // Do nothing. Just allow them all.
11            }
12            @Override
13            public void checkServerTrusted(X509Certificate[] certs, String authType) {
14                // Do nothing. Just allow them all.
15            }
16        }
17    };
18
19    HostnameVerifier trustAllHostnames = new HostnameVerifier() {
20        @Override
21        public boolean verify(String hostname, SSLSession session) {
22            return true; // Just allow them all.
23        }
24    };
25
26    try {
27        System.setProperty("jsse.enableSNIExtension", "false");
28        SSLContext sc = SSLContext.getInstance("SSL");
29        sc.init(null, trustAllCertificates, new SecureRandom());
30        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
31        HttpsURLConnection.setDefaultHostnameVerifier(trustAllHostnames);
32    }
33    catch (GeneralSecurityException e) {
34        throw new ExceptionInInitializerError(e);
35    }
36}
37
Full Screen
copy
1public Synchronized class service(ServletRequest request,ServletResponse response)throws ServletException,IOException
2
Full Screen
copy
1Synchronized(Object)
2
3{
4
5----Instructions-----
6
7}
8
copy
1public class ExampleServlet extends HttpServlet {
2
3    private Object thisIsNOTThreadSafe;
4
5    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
6        Object thisIsThreadSafe;
7
8        thisIsNOTThreadSafe = request.getParameter("foo"); // BAD!! Shared among all requests!
9        thisIsThreadSafe = request.getParameter("foo"); // OK, this is thread safe.
10    } 
11}
12
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

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.

Try LambdaTest

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)