Page 1 of 1

clean_selenium_script assistance

Posted: Fri Jan 30, 2015 4:28 pm
by ghostcat
OS: CentOS 64-bit
Software: Nagios XI install running on vmware.

Hello, I need some assistance with "clean_selenium_script" referenced in document (/nagiosxi/docs/Integrating-Selenium-With-Nagios-XI.pdf ) i am running this against an selenium IDE exported perl file per the doc.

Code: Select all

use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;
use TimePerf2;

my $time= TimePerf2->new(60,90,120);


my $sel = Test::WWW::Selenium->new( host => "localhost", 
                                    port => 4444, 
                                    browser => "*firefox", 
                                    browser_url => "https://www.supplychainguru.com/" );

$time->startTime("ALL");
$sel->set_timeout_ok("30000");
if ( !  $sel->open_ok("/Authentication/LogOn?ReturnUrl=%2f") ) {print "Location: " . $sel->get_location() . "\n";}
elsif ( ! $sel->set_speed("1500") ) { }

elsif ( !  $sel->type_ok("id=UserNameOverlay", "User Name") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->type_ok("id=UserName", "jeeves\@scguru.hostedservices.com") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->type_ok("id=Password", "*hidden*") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->click_ok("css=input.sign-in-scg-com") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
elsif ( !  $sel->click_ok("css=a[title=\"LoadTestModel\"] > div.recent-item-name") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
elsif ( !  $sel->click_ok("link=Default") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
elsif ( !  $sel->click_ok("css=div.model-item") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
elsif ( !  $sel->click_ok("css=#view-selected-map > span.sprite") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(5000);
elsif ( !  $sel->click_ok("id=add-layer") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(5000);
elsif ( !  $sel->type_ok("css=div.editor-field > #Name", "test1") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->click_ok("id=create-layer-submit") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
elsif ( !  $sel->click_ok("id=add-layer") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
elsif ( !  $sel->type_ok("css=div.editor-field > #Name", "test2") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->select_ok("id=DataSource", "label=Sites") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->click_ok("id=create-layer-submit") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(5000);
elsif ( !  $sel->click_ok("css=#delete > span.sprite") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->click_ok("//button[\@type='button']") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(5000);
elsif ( !  $sel->click_ok("css=#delete > span.sprite") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !  $sel->click_ok("//button[\@type='button']") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(5000);
elsif ( !  $sel->click_ok("link=Home") ) {print "Location: " . $sel->get_location() . "\n";}

elsif ( !$time->endTime("ALL") ) { }

else { $time->getTimes(); }
$sel->stop();
The problem occurs when running the previously "tidy'd" script with the following
syntax error at checkmaps.edited line 31, near "elsif"
Execution of checkmaps.edited aborted due to compilation errors.
# Looks like your test exited with 255 before it could output anything.
I've taken a look at line 31 and around the elseif statement however i am no perl expert and am unsure how the clean selenium script is breaking it.
The test works from start to end under selenium IDE.

Kind Thanks,
Dale Sallis
Systems Administrator
Llamasoft

Re: clean_selenium_script assistance

Posted: Sun Feb 01, 2015 10:02 am
by questrad
I dont think that using construction between 29 and 31 lines is correct (it applies over all code).
Can you please explain the code at following lines
  • Line 30: $sel->pause(3000);
    Line 33: $sel->pause(3000);
    Line 36: $sel->pause(3000);
    Line 39: $sel->pause(3000);
    Line 42: $sel->pause(5000);
    Line 45: $sel->pause(5000);
    Line 50: $sel->pause(3000);
    Line 53: $sel->pause(3000);
    Line 60: $sel->pause(5000);
    Line 65: $sel->pause(5000);
    Line 70: $sel->pause(5000);

Code: Select all

   
    28. elsif ( !  $sel->click_ok("css=input.sign-in-scg-com") ) {print "Location: " . $sel->get_location() . "\n";}
    29. 
    30. $sel->pause(3000);
    31. elsif ( !  $sel->click_ok("css=a[title=\"LoadTestModel\"] > div.recent-item-name") ) {print "Location: " . $sel->get_location() . "\n";}
You cannot use some other code between if () {} elseif () {} - it will break the if statement logic.

For some information you can use following url http://perlmaven.com/if as reference.
As well, Perl is a family of high-level, general-purpose, interpreted, dynamic programming languages. (http://en.wikipedia.org/wiki/Perl).
So it does line by line interpretation and informing about the first error, as soon as you fix the first error, if you have next it will complain about next one.

Re: clean_selenium_script assistance

Posted: Sun Feb 01, 2015 10:20 pm
by Box293
questrad wrote:You cannot use some other code between if () {} elseif () {} - it will break the if statement logic.
Agreed

Re: clean_selenium_script assistance

Posted: Mon Feb 02, 2015 10:42 am
by ghostcat
questrad wrote:I dont think that using construction between 29 and 31 lines is correct (it applies over all code).
Can you please explain the code at following lines
  • Line 30: $sel->pause(3000);
    Line 33: $sel->pause(3000);
    Line 36: $sel->pause(3000);
    Line 39: $sel->pause(3000);
    Line 42: $sel->pause(5000);
    Line 45: $sel->pause(5000);
    Line 50: $sel->pause(3000);
    Line 53: $sel->pause(3000);
    Line 60: $sel->pause(5000);
    Line 65: $sel->pause(5000);
    Line 70: $sel->pause(5000);

Code: Select all

   
    28. elsif ( !  $sel->click_ok("css=input.sign-in-scg-com") ) {print "Location: " . $sel->get_location() . "\n";}
    29. 
    30. $sel->pause(3000);
    31. elsif ( !  $sel->click_ok("css=a[title=\"LoadTestModel\"] > div.recent-item-name") ) {print "Location: " . $sel->get_location() . "\n";}
You cannot use some other code between if () {} elseif () {} - it will break the if statement logic.

For some information you can use following url http://perlmaven.com/if as reference.
As well, Perl is a family of high-level, general-purpose, interpreted, dynamic programming languages. (http://en.wikipedia.org/wiki/Perl).
So it does line by line interpretation and informing about the first error, as soon as you fix the first error, if you have next it will complain about next one.

Thank you so much for the response, I had a feeling the issue involved those statements before posting and was happy to see it confirmed, your info helped me understand the issue better so i now believe i have a way now to resolve the problem.

I believe based upon the logic those lines pointed out should be removed and replaced with

Code: Select all

elsif ( !  $sel->pause(3000) ) {print "Location: " . $sel->get_location() . "\n";}
I will do some testing to see if the script behaves as it should.

Thanks again.

Update1 - Its important to quote the pause value.

Code: Select all

elsif ( !  $sel->pause("3000") ) {print "Location: " . $sel->get_location() . "\n";}

Re: clean_selenium_script assistance

Posted: Mon Feb 02, 2015 11:09 am
by tgriep
Thanks for the update. Let us know how it works out.

Re: clean_selenium_script assistance

Posted: Mon Feb 02, 2015 1:25 pm
by questrad
Always welcome, but now I think you don't do correct again.

Original code:

Code: Select all

elsif ( !  $sel->click_ok("css=input.sign-in-scg-com") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
elsif ( !  $sel->click_ok("css=a[title=\"LoadTestModel\"] > div.recent-item-name") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
elsif ( !  $sel->click_ok("link=Default") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
The code that you changed:

Code: Select all

elsif ( !  $sel->pause("3000") ) {print "Location: " . $sel->get_location() . "\n";}
And here what I think:

Code: Select all

elsif ( !  $sel->click_ok("css=input.sign-in-scg-com") ) {
    print "Location: " . $sel->get_location() . "\n";
    $sel->pause(3000);
}

elsif ( !  $sel->click_ok("css=a[title=\"LoadTestModel\"] > div.recent-item-name") ) {
    print "Location: " . $sel->get_location() . "\n";
    $sel->pause(3000);
}

elsif ( !  $sel->click_ok("link=Default") ) {
    print "Location: " . $sel->get_location() . "\n";
    $sel->pause(3000);
}
And etc.

You need just make necessary changes over all your code.

Let us know which one is working.

Thanks

Re: clean_selenium_script assistance

Posted: Mon Feb 02, 2015 2:32 pm
by ghostcat

Code: Select all

elsif ( !  $sel->pause("3000") ) {print "Location: " . $sel->get_location() . "\n";}
this worked for me, the script waits the set milliseconds and then continues on as expected.
questrad wrote:Always welcome, but now I think you don't do correct again.

Original code:

Code: Select all

elsif ( !  $sel->click_ok("css=input.sign-in-scg-com") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
elsif ( !  $sel->click_ok("css=a[title=\"LoadTestModel\"] > div.recent-item-name") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
elsif ( !  $sel->click_ok("link=Default") ) {print "Location: " . $sel->get_location() . "\n";}

$sel->pause(3000);
The code that you changed:

Code: Select all

elsif ( !  $sel->pause("3000") ) {print "Location: " . $sel->get_location() . "\n";}
And here what I think:

Code: Select all

elsif ( !  $sel->click_ok("css=input.sign-in-scg-com") ) {
    print "Location: " . $sel->get_location() . "\n";
    $sel->pause(3000);
}

elsif ( !  $sel->click_ok("css=a[title=\"LoadTestModel\"] > div.recent-item-name") ) {
    print "Location: " . $sel->get_location() . "\n";
    $sel->pause(3000);
}

elsif ( !  $sel->click_ok("link=Default") ) {
    print "Location: " . $sel->get_location() . "\n";
    $sel->pause(3000);
}
And etc.

You need just make necessary changes over all your code.

Let us know which one is working.

Thanks
I think this would also work, however because it bundles the pause in with the previous elseif statement and i want to keep this as close to the original export im going to go with my method.

hopefully this helps others in future.

Re: clean_selenium_script assistance

Posted: Mon Feb 02, 2015 3:28 pm
by questrad

Code: Select all

elsif ( !  $sel->click_ok("css=input.sign-in-scg-com") ) {
    print "Location: " . $sel->get_location() . "\n";
    $sel->pause(3000);
}

elsif ( !  $sel->click_ok("css=a[title=\"LoadTestModel\"] > div.recent-item-name") ) {
    print "Location: " . $sel->get_location() . "\n";
    $sel->pause(3000);
}

elsif ( !  $sel->click_ok("link=Default") ) {
    print "Location: " . $sel->get_location() . "\n";
    $sel->pause(3000);
}
This more close to the original one, because it does check if it can click on that css element :)

Good if just sleep is working for you.

Re: clean_selenium_script assistance

Posted: Mon Feb 02, 2015 4:14 pm
by slansing
Awesome, thank you for getting back to us on this.