소스 검색

fix to handle 1.16

George S. Baugh 2 년 전
부모
커밋
67184f4f15
2개의 변경된 파일20개의 추가작업 그리고 4개의 파일을 삭제
  1. 2 2
      example.pl
  2. 18 2
      playwright_server

+ 2 - 2
example.pl

@@ -141,9 +141,9 @@ $element = Playwright::try_until($page, 'select', 'bogus-bogus-nothere');
 $elapsed = time() - $checkpoint;
 print "Waited $elapsed seconds for timeout to drop\n";
 
-# Try out the "experimental" API testing extensions (FetchRequests)
+# Try out the API testing extensions
 print "HEAD http://google.com : \n";
-my $fr = $page->request();
+my $fr = $page->request;
 my $resp = $fr->fetch("http://google.com", { method => "HEAD" });
 print Dumper($resp->headers());
 print "200 OK\n" if $resp->status() == 200;

+ 18 - 2
playwright_server

@@ -190,13 +190,12 @@ app.post('/command', async (req, res) => {
                 ];
             }
             var commandResult;
-            if (command == '_request') {
+            if (command == 'request') {
                 //TODO extend this to other attribute fetches as well in the future
                 commandResult = subject[command];
             } else {
                 commandResult = await subject[command](...args);
             }
-            result = { error : false, message : commandResult };
 
             if (Array.isArray(commandResult)) {
                 for (var r of commandResult) {
@@ -225,9 +224,26 @@ app.post('/command', async (req, res) => {
                 commandResult._type = 'FetchResponse';
             }
 
+            var toReturn = commandResult;
+            // XXX we have to duplicate this parameter so as not to confuse playwright when we change it to reflect the spec
+            if (commandResult && commandResult._type) {
+                toReturn = { _guid : commandResult._guid, _type : commandResult._type };
+            }
+
+            // XXX APIRequestContexts & friends are still internally FetchRequests
+            if (commandResult && commandResult._type == 'FetchRequest') {
+                toReturn._type = 'APIRequestContext';
+            }
+            if (commandResult && commandResult._type == 'FetchResponse') {
+                toReturn._type = 'APIResponse';
+            }
+
             if (commandResult && commandResult._guid) {
                 objects[commandResult._guid] = commandResult;
             }
+
+            result = { error : false, message : toReturn };
+
         } catch (e) {
             result = { error : true, message : e.message };
         }