http://qs321.pair.com?node_id=1164043

Chaoui05 has asked for the wisdom of the Perl Monks concerning the following question:

Hi every Monks ! I am appealing to your wisdom yet again. I have an issue. Iam using Selenium::Screenshot. I get screenshots i'd like to compare. I did this following code:
$driver->set_window_size(320, 480); $elem = $driver->find_element('applgs','id' ); my $white = Selenium::Screenshot->new( png => $driver->screenshot, exclude => [{ size => { width => 10, height => 10 }, location => { x => 5, y => 5 }, }] )->save( file => "snapScreenshot" ); $driver->execute_script('document.getElementsByTagName("body")[0]. +style.backgroundColor = "red"'); my $blue = Selenium::Screenshot->new(png => $driver->screenshot)-> +save( file => "snapScreenshot1" ); unless ($white->compare($blue)) { my $diff_file = $white->difference($blue); print 'The images differ; see ' . $diff_file . ' for details'; }
But i get after this ouput in my Shell:
not ok 22 - A_test died (Can't locate object method "compare" via pack +age "D:/t/gui-tests/tests/screenshots/snapScreenshot-firefox.png " (perhaps you forgot to load "D:/t/gui-tests/tests/screenshots/snapSc +reenshot-firefox.png"?) at MyTestingSuite.pm line 260.)
I have my 2 screenshots and one of them have got effectively its body in red. Somenone can help ? Many Thanks !!

Replies are listed 'Best First'.
Re: Compare method with Selenium
by choroba (Cardinal) on May 25, 2016 at 07:45 UTC
    $white should contain an object (or a package name) in order to have methods run on itself. Selenium::Screenshot->new returns the object you want, but you called `->save` on it, which returned only the file name. You can't chain the constructor with the save method.

    my $white = 'Selenium::Screenshot'->new( png => $driver->screenshot, exclude => [{ size => { width => 10, height => 10 }, location => { x => 5, y => 5 }, }]); $white->save( file => "snapScreenshot" );

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Thanks Choroba ! It works right now . But i have another issue. Why i could not have a black out in my page. It should work :
      $elem = $driver->find_element('applgs','id' ); my $white = 'Selenium::Screenshot'->new( png => $driver->screenshot, exclude => [{ size => { width => 10, height => 10 }, # siz +e => $elem->get_size, location => { x => 5, y => 5 }, #location => $el +em->get_element_location, }] );
Re: Compare method with Selenium
by ablanke (Monsignor) on May 25, 2016 at 08:16 UTC
    Hello Chaoui05,

    I assume the return value of the save Method is stored in your Scalars $white and $blue

    Try this:
    my $white = Selenium::Screenshot->new( png => $driver->screenshot, exclude => [{ size => { width => 10, height => 10 }, location => { x => 5, y => 5 }, }] ); $white->save( file => "snapScreenshot" );
      Hello ablanke

      Thanks. I did that and it's perfect. But now i have another issue. I can't get a black out on my page doing that :

      $elem = $driver->find_element('applgs','id' ); my $white = Selenium::Screenshot->new( png => $driver->screenshot, exclude => [{ size => { width => 10, height => 10 }, # siz +e => $elem->get_size, location => { x => 5, y => 5 }, #location => $el +em->get_element_location, }] );
      Thanks again !