File tree Expand file tree Collapse file tree
src/org/openqa/selenium/remote/http
test/org/openqa/selenium/devtools Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,5 +22,6 @@ public enum HttpMethod {
2222 GET ,
2323 POST ,
2424 PUT ,
25- OPTIONS
25+ OPTIONS ,
26+ PATCH
2627}
Original file line number Diff line number Diff 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 );
You can’t perform that action at this time.
0 commit comments