瀏覽代碼

Fix #54: Experimental support for the locator api.

George Baugh 1 年之前
父節點
當前提交
129d25802e
共有 6 個文件被更改,包括 24 次插入2 次删除
  1. 4 0
      conf/Changes
  2. 1 1
      dist.ini
  3. 5 0
      example.pl
  4. 7 0
      lib/Playwright.pm
  5. 1 1
      package.json
  6. 6 0
      playwright_server

+ 4 - 0
conf/Changes

@@ -1,5 +1,9 @@
 Revision history for Playwright
 
+1.323 2023-04-17 TEODESIAN
+    - Ensure temporary files used for IPC by await() are cleaned out of /tmp.  Patch courtesy of Yanick Champoux.
+    - Add experimental support for the locator API via Page->locator().
+
 1.291 2022-12-28 TEODESIAN
     - Add 'port' mechanism to connect to remote instances of playwright_server
     - Add systemd service files for running things in user mode.  See service/Readme.md

+ 1 - 1
dist.ini

@@ -1,5 +1,5 @@
 name = Playwright
-version = 1.291
+version = 1.323
 author = George S. Baugh <george@troglodyne.net>
 license = MIT
 copyright_holder = Troglodyne LLC

+ 5 - 0
example.pl

@@ -149,6 +149,11 @@ use Try::Tiny;
     print Dumper($resp->headers());
     print "200 OK\n" if $resp->status() == 200;
 
+    # Test that we can do stuff with with the new locator API.
+    my $loc = $page->locator('body');
+    my $innerTubes = $loc->allInnerTexts();
+    print Dumper($innerTubes);
+
     # Save a video now that we are done
     my $bideo = $page->video;
 

+ 7 - 0
lib/Playwright.pm

@@ -48,6 +48,13 @@ use feature qw{signatures};
 
     my $kids = $body->selectMulti('*');
 
+    #Alternatively, use the new locator API instead of select/selectMulti:
+    my $loc = $page->locator('body');
+    my $innerTubes = $loc->allInnerTexts();
+    print Dumper($innerTubes);
+
+    # See a more full exploration of the API in example.pl on github.
+
 =head1 DESCRIPTION
 
 Perl interface to a lightweight node.js webserver that proxies commands runnable by Playwright.

+ 1 - 1
package.json

@@ -6,7 +6,7 @@
   "private": true,
   "dependencies": {
     "express": "^4.17",
-    "playwright": "^1.29.1",
+    "playwright": "^1.32.3",
     "uuid": "^8.3"
   }
 }

+ 6 - 0
playwright_server

@@ -203,6 +203,8 @@ app.post('/command', async (req, res) => {
                 }
             }
 
+            console.log("COMMAND RESULT:", commandResult);
+
             // XXX videos are special, we have to magic up a guid etc for them
             if (command == 'video' && commandResult) {
                 commandResult._guid = 'Video@' + uuidv4();
@@ -223,6 +225,10 @@ app.post('/command', async (req, res) => {
                 commandResult._guid = 'FetchResponse@' + uuidv4();
                 commandResult._type = 'FetchResponse';
             }
+            if (commandResult && type == 'Page' && command == 'locator') {
+                commandResult._guid = 'Locator@' + uuidv4();
+                commandResult._type = 'Locator';
+            }
 
             var toReturn = commandResult;
             // XXX we have to duplicate this parameter so as not to confuse playwright when we change it to reflect the spec