| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package Playwright::Page;
- use strict;
- use warnings;
- use Sub::Install();
- use Carp qw{confess};
- #ABSTRACT: Object representing Playwright pages
- no warnings 'experimental';
- use feature qw{signatures state};
- =head2 SYNOPSIS
- use Playwright;
- my ($browser,$page) = Playwright->new( browser => "chrome" );
- $page->goto('http://www.google.com');
- my $browser_version = $browser->version();
- $browser->quit();
- =head2 DESCRIPTION
- Perl interface to a lightweight node.js webserver that proxies commands runnable by Playwright in the 'Page' Class.
- See L<https://playwright.dev/#version=v1.5.1&path=docs%2Fapi.md&q=class-page> for more information.
- The specification for this class can also be inspected with the 'spec' method:
- use Data::Dumper;
- my $page = Playwright::Page->new(...);
- print Dumper($page->spec);
- =head1 CONSTRUCTOR
- =head2 new(HASH) = (Playwright,Playwright::Frame)
- Creates a new page and returns a handle to interact with it, along with a Playwright::Frame (the main Frame) to interact with (supposing the page is a FrameSet).
- =head3 INPUT
- browser (Playwright) : Playwright object.
- page (STRING) : _guid returned by a response from the Playwright server with _type of 'Page'.
- =cut
- my %transmogrify = (
- Frame => sub {
- my ($self, $res) = @_;
- require Playwright::Frame;
- return Playwright::Frame->new( page => $self, frame => $res->{_guid} );
- },
- ElementHandle => sub {
- my ($self, $res) = @_;
- require Playwright::Element;
- return Playwright::Element->new( page => $self, id => $res->{_guid} );
- },
- Response => sub {
- my ($self, $res) = @_;
- require Playwright::Response;
- return Playwright::Response->new( browser => $self, id => $res->{_guid} );
- },
- );
- sub new ($class, %options) {
- my $self = bless({
- spec => $options{browser}{spec}{Page}{members},
- browser => $options{browser},
- guid => $options{page},
- }, $class);
- # Install the subroutines if they aren't already
- foreach my $method (keys(%{$self->{spec}})) {
- Sub::Install::install_sub({
- code => sub { _request(shift, \%transmogrify, args => [@_], command => $method, page => $self->{guid} ) },
- as => $method,
- }) unless $self->can($method);
- }
- return ($self);#, $self->mainFrame());
- }
- =head1 METHODS
- =head2 spec
- Return the relevant methods and their definitions for this module which are built dynamically from the Playwright API spec.
- =cut
- sub spec ($self) {
- return %{$self->{spec}};
- }
- sub _request ($self,$translator, %options) {
- $options{page} = $self->{guid};
- return $self->{browser}->_request($translator, %options);
- }
- 1;
|