Forráskód Böngészése

Fix #11: Demonstrate downloads

George S. Baugh 5 éve
szülő
commit
eb7ac2714b
5 módosított fájl, 50 hozzáadás és 1 törlés
  1. 1 0
      .gitignore
  2. 1 0
      MANIFEST.SKIP
  3. 1 0
      at/other.html
  4. 40 0
      at/test.html
  5. 7 1
      example.pl

+ 1 - 0
.gitignore

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

+ 1 - 0
MANIFEST.SKIP

@@ -5,5 +5,6 @@ weaver.ini
 .git/*
 video/*
 test.jpg
+test2.jpg
 package-lock.json
 node_modules/*

+ 1 - 0
at/other.html

@@ -0,0 +1 @@
+ZIPPY

+ 40 - 0
at/test.html

@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+    <head>
+         <meta charset="UTF-8" />
+        <title>Test Page</title>
+        <style>
+            .red {
+                color:red;
+            }
+        </style>
+        <script type="text/javascript">
+            window.onload = function() {
+                alert("BEEE DOOO");
+                prompt("Are you a fugitive from Justice?","Yes");
+            };
+        </script>
+        <meta http-equiv="set-cookie" content="GorgonGlaze=Petrified%20Grits; expires=Sat, 25-Nov-2120 12:00:00 GMT; path=/;" />
+    </head>
+    <body>
+        <h1>
+            Howdy Howdy Howdy
+        </h1>
+        <form id="howIsBabbyFormed" action="other.html">
+            <label for="text" class="red">Text</label>
+            <input name="text" type="text" value="default"></input>
+            <input id="radio1" name="radio2" type="radio"></input>
+            <input id="radio2" name="radio2" type="radio" checked></input>
+            <input id="hammertime" type="submit" disabled></input>
+            <input id="hidon" type="hidden"></input>
+        </form>
+        <br />
+        <button id="no-see-em" style="display:none;">Tickle</button>
+        <button id="clickme" onclick="alert('PARTY');">PARTY HARD</button>
+        <br />
+        <a href="other.html" target="_blank" id="linky" class="red">Test Link</a>
+        <a href="../test.jpg" id="d-lo" download>Download</a>
+        <br />
+        <iframe id="frame" src="other.html" />
+    </body>
+</html>

+ 7 - 1
example.pl

@@ -14,7 +14,7 @@ my $handle = Playwright->new( debug => 1 );
 my $browser = $handle->launch( headless => JSON::PP::false, type => 'chrome' );
 
 # Open a tab therein
-my $page = $browser->newPage({ videosPath => 'video' });
+my $page = $browser->newPage({ videosPath => 'video', acceptDownloads => JSON::PP::true });
 my $bideo = $page->video;
 
 my $vidpath = $bideo->path;
@@ -99,3 +99,9 @@ $dlg->dismiss();
 $dlg = $handle->await($promise);
 $dlg->accept();
 
+# Download stuff -- note this requries acceptDownloads = true in the page open
+$promise = $page->waitForEvent('download');
+$page->select('#d-lo')->click();
+
+my $download = $handle->await( $promise );
+$download->saveAs('test2.jpg');