Skip to content

Commit 02a611d

Browse files
[java] Added PATCH request
Co-authored-by: Argo triwidodo <argo.triwidodo@gdn-commerce.com>
1 parent f5dbc35 commit 02a611d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

‎java/src/org/openqa/selenium/remote/http/HttpMethod.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ public enum HttpMethod {
2222
GET,
2323
POST,
2424
PUT,
25-
OPTIONS
25+
OPTIONS,
26+
PATCH
2627
}

‎java/test/org/openqa/selenium/devtools/NetworkInterceptorRestTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,37 @@ public void tearDown() {
7676
() -> appServer.stop());
7777
}
7878

79+
@Test
80+
public void shouldInterceptPatchRequest() throws MalformedURLException {
81+
AtomicBoolean seen = new AtomicBoolean(false);
82+
interceptor = new NetworkInterceptor(
83+
driver,
84+
Route.matching(req -> (req.getMethod() == HttpMethod.PATCH))
85+
.to(() -> req -> {
86+
seen.set(true);
87+
return new HttpResponse()
88+
.setStatus(200)
89+
.addHeader("Access-Control-Allow-Origin", "*")
90+
.setContent(utf8String("Received response for PATCH"));
91+
}));
92+
93+
JavascriptExecutor js = (JavascriptExecutor) driver;
94+
Object response = js.executeAsyncScript(
95+
"var url = arguments[0];" +
96+
"var callback = arguments[arguments.length - 1];" +
97+
"var xhr = new XMLHttpRequest();" +
98+
"xhr.open('PATCH', url, true);" +
99+
"xhr.onload = function() {" +
100+
" if (xhr.readyState == 4) {" +
101+
" callback(xhr.responseText);" +
102+
" }" +
103+
"};" +
104+
"xhr.send('Hey');", new URL(appServer.whereIs("/")).toString());
105+
106+
assertThat(seen.get()).isTrue();
107+
assertThat(response.toString()).contains("Received response for PATCH");
108+
}
109+
79110
@Test
80111
public void shouldInterceptPutRequest() throws MalformedURLException {
81112
AtomicBoolean seen = new AtomicBoolean(false);

0 commit comments

Comments
 (0)