clean_selenium_script assistance

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
ghostcat
Posts: 9
Joined: Mon Nov 24, 2014 2:54 pm

clean_selenium_script assistance

Post 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
questrad
Posts: 160
Joined: Wed Mar 21, 2012 3:08 pm
Location: Toronto
Contact:

Re: clean_selenium_script assistance

Post 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.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: clean_selenium_script assistance

Post by Box293 »

questrad wrote:You cannot use some other code between if () {} elseif () {} - it will break the if statement logic.
Agreed
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
ghostcat
Posts: 9
Joined: Mon Nov 24, 2014 2:54 pm

Re: clean_selenium_script assistance

Post 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";}
Last edited by ghostcat on Mon Feb 02, 2015 12:16 pm, edited 1 time in total.
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: clean_selenium_script assistance

Post by tgriep »

Thanks for the update. Let us know how it works out.
Be sure to check out our Knowledgebase for helpful articles and solutions!
questrad
Posts: 160
Joined: Wed Mar 21, 2012 3:08 pm
Location: Toronto
Contact:

Re: clean_selenium_script assistance

Post 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
ghostcat
Posts: 9
Joined: Mon Nov 24, 2014 2:54 pm

Re: clean_selenium_script assistance

Post 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.
questrad
Posts: 160
Joined: Wed Mar 21, 2012 3:08 pm
Location: Toronto
Contact:

Re: clean_selenium_script assistance

Post 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.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: clean_selenium_script assistance

Post by slansing »

Awesome, thank you for getting back to us on this.
Locked