简体   繁体   中英

login fails with selenium perl on linux

I have been desperately trying to get the following perl/Selenium script to work on my GNU Linux server. I have no idea why my script which I have set to start with the 'login' page goes to the 'loginok' page and then to the 'loginerror' page (See PERL output). That i believe is the reason for the subsequent errors I am getting - although, I cant figure out why the redirection is happening - i verified the credentials in the script

Any help would be very much appreciated!!

My PERL script -

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

my $sel = Test::WWW::Selenium->new( host => "localhost",
                                    port => 4444,
                                    browser => "*firefox",
                                    browser_url => "http://monitoring.cogenra.com/login/" );

$sel->open_ok("http://monitoring.cogenra.com/login");
$sel->wait_for_page_to_load_ok("90000");
$sel->set_speed(30000);
print "\n". $sel->get_location() ;
$sel->title_is("");
$sel->type_ok("id=ContentPlaceHolder1_txtUname", "CorrectUser");
$sel->type_ok("id=ContentPlaceHolder1_txtPwd", "CorrectPswd");
$sel->click_ok("id=ContentPlaceHolder1_btn_Login");
$sel->wait_for_page_to_load_ok("90000");
print "\n". $sel->get_location() ;
$sel->wait_for_element_present("css=#gn_output > a > span", 90000);
print "\n". $sel->get_location() ;
$sel->title_is("Cogenra Monitoring");
print "\n". $sel->get_location() ;
$sel->click_ok("css=#gn_output > a > span");
$sel->wait_for_page_to_load_ok("60000");
$sel->title_is("Cogenra Monitoring");
$sel->click_ok("css=div.ob_iDdlTR");
$sel->click_ok("css=b");
$sel->type_ok("id=ContentPlaceHolder1_txt_fromdate", "9/21/2013");
$sel->type_ok("id=ContentPlaceHolder1_txt_todate", "9/27/2013");

PERL output -

ok 1 - open, http://monitoring.cogenra.com/login
ok 2 - wait_for_page_to_load, 90000

http://monitoring.cogenra.com/loginok 3 - get_title, ''
ok 4 - type, id=ContentPlaceHolder1_txtUname, CorrectUser
ok 5 - type, id=ContentPlaceHolder1_txtPwd, CorrectPswd
ok 6 - click, id=ContentPlaceHolder1_btn_Login
ok 7 - wait_for_page_to_load, 90000

http://monitoring.cogenra.com/loginError requesting http://localhost:4444/selenium-server/driver/:
Timed out after 30000ms
1..7
# Looks like your test exited with 255 just after 7.

Here is the selenium server output

01:26:54.418 INFO - Command request: getNewBrowserSession[*firefox, http://monitoring.cogenra.com/login/] on session null
01:26:54.418 INFO - creating new remote session
01:26:54.418 INFO - Allocated session 86f865ad4b864b40ba7cdac1d4da6972 for http://monitoring.cogenra.com/login/, launching...
jar:file:/home/oracle/downloads/selenium-server-standalone-2.35.0.jar!/customProfileDirCUSTFFCHROME
01:26:54.436 INFO - Preparing Firefox profile...
01:26:55.338 INFO - Launching Firefox...
01:26:57.358 INFO - Got result: OK,86f865ad4b864b40ba7cdac1d4da6972 on session 86f865ad4b864b40ba7cdac1d4da6972
01:26:57.361 INFO - Command request: testComplete[, ] on session 86f865ad4b864b40ba7cdac1d4da6972
01:26:57.361 INFO - Killing Firefox...
01:26:57.417 INFO - Got result: OK on session 86f865ad4b864b40ba7cdac1d4da6972
01:27:27.794 INFO - Command request: getNewBrowserSession[*firefox, http://monitoring.cogenra.com/login/] on session null
01:27:27.794 INFO - creating new remote session
01:27:27.795 INFO - Allocated session 2e43642945e64039a30b761f35914083 for http://monitoring.cogenra.com/login/, launching...
jar:file:/home/oracle/downloads/selenium-server-standalone-2.35.0.jar!/customProfileDirCUSTFFCHROME
01:27:27.812 INFO - Preparing Firefox profile...
01:27:28.714 INFO - Launching Firefox...
01:27:30.863 INFO - Got result: OK,2e43642945e64039a30b761f35914083 on session 2e43642945e64039a30b761f35914083
01:27:30.867 INFO - Command request: open[http://monitoring.cogenra.com/login, ] on session 2e43642945e64039a30b761f35914083
01:27:30.867 WARN - you appear to be changing domains from http://monitoring.cogenra.com/login/ to http://monitoring.cogenra.com/login
this may lead to a 'Permission denied' from the browser (unless it is running as *iehta or *chrome,
or alternatively the selenium server is running in proxy injection mode)
01:27:32.609 INFO - Got result: OK on session 2e43642945e64039a30b761f35914083
01:27:32.612 INFO - Command request: waitForPageToLoad[90000, ] on session 2e43642945e64039a30b761f35914083
01:27:32.616 INFO - Got result: OK on session 2e43642945e64039a30b761f35914083
01:27:32.619 INFO - Command request: setSpeed[30000, ] on session 2e43642945e64039a30b761f35914083
01:27:32.619 INFO - Got result: OK on session 2e43642945e64039a30b761f35914083
01:27:32.621 INFO - Command request: getLocation[, ] on session 2e43642945e64039a30b761f35914083
01:28:02.628 INFO - Got result: OK,http://monitoring.cogenra.com/login on session 2e43642945e64039a30b761f35914083
01:28:02.631 INFO - Command request: getTitle[, ] on session 2e43642945e64039a30b761f35914083
01:28:32.637 INFO - Got result: OK, on session 2e43642945e64039a30b761f35914083
01:28:32.641 INFO - Command request: type[id=ContentPlaceHolder1_txtUname, CorrectUser] on session 2e43642945e64039a30b761f35914083
01:29:02.649 INFO - Got result: OK on session 2e43642945e64039a30b761f35914083
01:29:02.653 INFO - Command request: type[id=ContentPlaceHolder1_txtPwd, CorrectPswd] on session 2e43642945e64039a30b761f35914083
01:29:32.658 INFO - Got result: OK on session 2e43642945e64039a30b761f35914083
01:29:32.661 INFO - Command request: click[id=ContentPlaceHolder1_btn_Login, ] on session 2e43642945e64039a30b761f35914083
01:30:02.714 INFO - Got result: OK on session 2e43642945e64039a30b761f35914083
01:30:02.717 INFO - Command request: waitForPageToLoad[90000, ] on session 2e43642945e64039a30b761f35914083
01:30:32.724 INFO - Got result: OK on session 2e43642945e64039a30b761f35914083
01:30:32.727 INFO - Command request: getLocation[, ] on session 2e43642945e64039a30b761f35914083
01:31:02.732 INFO - Got result: OK,http://monitoring.cogenra.com/login on session 2e43642945e64039a30b761f35914083
01:31:02.736 INFO - Command request: waitForElementPresent[css=#gn_output > a > span, 90000] on session 2e43642945e64039a30b761f35914083
01:32:02.744 INFO - Got result: Timed out after 30000ms on session 2e43642945e64039a30b761f35914083
01:32:02.748 INFO - Command request: testComplete[, ] on session 2e43642945e64039a30b761f35914083
01:32:02.748 INFO - Killing Firefox...
01:32:02.805 INFO - Got result: OK on session 2e43642945e64039a30b761f35914083

I find the Selenium::Remote::Driver better. This is my script suitable for prove. You might just need the proxy setting

use Data::Dumper;
use Test::More tests=>1+ (3 * 4);

use_ok 'Selenium::Remote::Driver';
foreach (qw( phantomjs firefox chrome opera )){
  note $_;

  my $driver = new_ok('Selenium::Remote::Driver' => [ 
      browser_name => $_, 
      proxy=>{proxyType=> 'direct'}]);

  ok $driver->get('http://www.google.com');
  is $driver->get_title(), 'Google';
  $driver->quit();
}

I see this in log

1:27:30.867 WARN - you appear to be changing domains from http://monitoring.cogenra.com/login/ to http://monitoring.cogenra.com/login
this may lead to a 'Permission denied' from the browser (unless it is running as *iehta or *chrome,
or alternatively the selenium server is running in proxy injection mode)

Maybe it is going to help if you do this:

my $sel = Test::WWW::Selenium->new( host => "localhost",
                                    port => 4444,
                                    browser => "*firefox",
                                    browser_url => "http://monitoring.cogenra.com/login" #<-- removing tailing /

);

The another thing: Selenium tells that is going to kill firefox because the page not loaded after 30s. Is it possible that something wrong with the app your are testing? What is in the apache log?

01:32:02.744 INFO - Got result: Timed out after 30000ms on session 2e43642945e64039a30b761f35914083
01:32:02.748 INFO - Command request: testComplete[, ] on session 2e43642945e64039a30b761f35914083

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM