File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
src/org/openqa/selenium/remote/http
test/org/openqa/selenium/devtools Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -22,5 +22,6 @@ public enum HttpMethod {
22
22
GET ,
23
23
POST ,
24
24
PUT ,
25
- OPTIONS
25
+ OPTIONS ,
26
+ PATCH
26
27
}
Original file line number Diff line number Diff line change @@ -76,6 +76,37 @@ public void tearDown() {
76
76
() -> appServer .stop ());
77
77
}
78
78
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
+
79
110
@ Test
80
111
public void shouldInterceptPutRequest () throws MalformedURLException {
81
112
AtomicBoolean seen = new AtomicBoolean (false );
You can’t perform that action at this time.
0 commit comments