我一直在拼命尝试将以下perl / Selenium脚本用于我的GNU Linux服务器。我不知道为什么我设置为从'login'页面开始的脚本进入'loginok'页面然后进入'loginerror'页面(参见PERL输出)。我相信这是我得到的后续错误的原因 - 虽然,我无法弄清楚为什么重定向正在发生 - 我验证了脚本中的凭据
非常感谢任何帮助!!
我的PERL脚本 -
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输出 -
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.
这是selenium服务器输出
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
答案 0 :(得分:1)
我发现Selenium :: Remote :: Driver更好。这是我的脚本适合证明。您可能只需要代理设置
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();
}
答案 1 :(得分:0)
我在日志
中看到了这一点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)
如果你这样做,也许会有所帮助:
my $sel = Test::WWW::Selenium->new( host => "localhost",
port => 4444,
browser => "*firefox",
browser_url => "http://monitoring.cogenra.com/login" #<-- removing tailing /
);
另一件事:Selenium告诉我要杀死firefox因为30秒后没有加载页面。您正在测试的应用程序是否有可能出现问题?什么是apache日志?
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