Переглянути джерело

Fix #10: handle page.video correctly

George S. Baugh 5 роки тому
батько
коміт
8772a8e70e
4 змінених файлів з 16 додано та 4 видалено
  1. 1 0
      .gitignore
  2. 8 1
      bin/playwright.js
  3. 6 2
      example.pl
  4. 1 1
      lib/Playwright.pm

+ 1 - 0
.gitignore

@@ -48,3 +48,4 @@ package-lock.json
 
 #nobody need know of our love, baby
 test.jpg
+video/*

+ 8 - 1
bin/playwright.js

@@ -3,7 +3,7 @@
 "use strict";
 
 const yargs = require('yargs');
-const uuid = require('uuid');
+const { v4 : uuidv4 } = require('uuid');
 const express = require('express');
 const { chromium, firefox, webkit, devices } = require('playwright');
 
@@ -71,6 +71,7 @@ app.post('/command', async (req, res) => {
         console.log(type,object,command,args);
     }
 
+    // XXX this would be cleaner if the mouse() and keyboard() methods just returned a Mouse and Keyboard object
     var subject = objects[object];
     if (subject) {
         if (type == 'Mouse') {
@@ -91,6 +92,12 @@ app.post('/command', async (req, res) => {
                 }
             }
 
+            // XXX videos are special, we have to magic up a guid etc for them
+            if (command == 'video' && res) {
+                res._guid = 'Video@' + uuidv4();
+                res._type = 'Video';
+            }
+
             if (res && res._guid) {
                 objects[res._guid] = res;
             }

+ 6 - 2
example.pl

@@ -7,13 +7,17 @@ use Playwright;
 
 use Try::Tiny;
 
-my $handle = Playwright->new();
+my $handle = Playwright->new( debug => 1 );
 
 # Open a new chrome instance
 my $browser = $handle->launch( headless => JSON::PP::false, type => 'chrome' );
 
 # Open a tab therein
-my $page = $browser->newPage();
+my $page = $browser->newPage({ videosPath => 'video' });
+my $bideo = $page->video;
+
+my $vidpath = $bideo->path;
+print "Video Path: $vidpath\n";
 
 # Browser contexts don't exist until you open at least one page.
 # You'll need this to grab and set cookies.

+ 1 - 1
lib/Playwright.pm

@@ -162,7 +162,7 @@ sub DESTROY ($self) {
 sub _start_server($port, $debug) {
     $debug   = $debug   ? '-d' : '';
 
-    $ENV{DEBUG} = 'pw:api';
+    $ENV{DEBUG} = 'pw:api' if $debug;
     my $pid = fork // confess("Could not fork");
     if ($pid) {
         print "Waiting for port to come up..." if $debug;