CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
One function with 3 calls

 



Chaoui005
Novice

May 9, 2016, 4:23 PM

Post #1 of 4 (1588 views)
One function with 3 calls Can't Post

Hello everybody ! Iam beginner with Perl. I would like to create one function to have all this following code attached in file, inside. And i would like to call it with 3 "same" calls.

I did that but it doesn't work:


Code
$item; 
$root = "'//a[@href="/"]';
$name;
sub OneHome {
$elem = $driver->find_element('$root');
$driver->mouse_move_to_location(element => $elem); # xoffset => x, yoffset => y
$elem = $driver->find_element('$item');
$driver->mouse_move_to_location(element => $elem); # xoffset => x, yoffset => y
$driver->click_ok('LEFT');
$driver->pause(3000);
$driver->capture_screenshot("$path/snap$name-$browser.png");
#return OneHome();
}


How can i do ? Thanks !
Attachments: test1.png (68.7 KB)


Laurent_R
Veteran / Moderator

May 10, 2016, 2:28 AM

Post #2 of 4 (1581 views)
Re: [Chaoui005] One function with 3 calls [In reply to] Can't Post

I really don't understand what you are trying to do.

A couple of comments on the code, though.

First, it will not compile "as is". I assume you are using a module, but this is not shown in your code. Please show your full code.

Second, the OneHome sub is never called. There is no chance that is will ever be executed.

Third, you have these funny declarations:

Code
$item;  
$root = "'//a[@href="/"]';
$name;


These should really be:

Code
my $item;  
my $root = "'//a[@href="/"]';
my $name; # does not seem to be used


You should insert the following lines at the top of your program:

Code
use strict; 
use warnings;

and correct any errors or warnings appearing in your code after you've added these. For example, you'll have to change the first line of the sub to:


Code
my $elem = $driver->find_element('$root');


But these are details, the main point is that you should provide complete code and explain better what you're trying to do.


Chaoui005
Novice

May 10, 2016, 3:22 AM

Post #3 of 4 (1574 views)
Re: [Laurent_R] One function with 3 calls [In reply to] Can't Post

Thanks Laurent ! Iam understanding. I will do that !


Chaoui005
Novice

May 10, 2016, 3:34 AM

Post #4 of 4 (1573 views)
Re: [Chaoui005] One function with 3 calls [In reply to] Can't Post

So now i did that . I create this function:


Code
    my $root ='//a[@href="/"]'; 
my @name = ('//a[@href="/install/kit"]','//a[@href="/license/view"]');
my @snapname = ("Installkit","Licenseview");

sub myHomeTest {
my ( $RefName, $RefSnapname ) = @_;
my $elem = $driver->find_element($root);
#my $elem = $driver->find_element('//a[@href="/"]'); # Other way to get Xpath: $elem = $driver->find_element("//a[\@href='/']");
$driver->mouse_move_to_location(element => $elem); # xoffset => x, yoffset => y
foreach my $name ( @{$RefName}){
$driver->click_element_ok($name, 'xpath', "Loaded");
}
$driver->pause(3000);
foreach my $name ( @{$RefSnapname}){
$driver->capture_screenshot("$path/snap$snapname-$browser.png");
}
$driver->get_ok("$base_url","get Home url");
$driver->pause(2000);
}

myHomeTest ($root, @name, @snapname);


And i would like to simplify this following code with above function also:

Code
 $elem = $driver->find_element('//a[@href="/"]'); 
$driver->mouse_move_to_location(element => $elem); # xoffset => x, yoffset => y
$driver->click_element_ok('//a[@href="/license/view"]', 'xpath', 'License View loaded');
$driver->pause(2000);
$driver->capture_screenshot("$path/snapLicenseview-$browser.png");
$driver->get_ok("$base_url","Get Home url");
$driver->pause(2000);


$elem = $driver->find_element('//a[@href="/"]');
$driver->mouse_move_to_location(element => $elem); # xoffset => x, yoffset => y
$driver->click_element_ok('//a[@href="/licenses"]', 'xpath', 'Licenses loaded');
$driver->pause(2000);
$driver->capture_screenshot("$path/snapLicenses-$browser.png");
$driver->get_ok("$base_url", "get Home url");
$driver->pause(2000);


But i have this issue , stdout in my Shell:
Variable "$driver" will not stay shared at MyTestingSuite.pm line 168.
Variable "$root" will not stay shared at MyTestingSuite.pm line 168.
Variable "$browser" will not stay shared at MyTestingSuite.pm line 176.
Global symbol "$snapname" requires explicit package name at MyTestingSuite.pm line 176.

Many Thanks !!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives