Perl和Selenium :: Remote :: Driver [英] Perl and Selenium::Remote::Driver

查看:58
本文介绍了Perl和Selenium :: Remote :: Driver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再次编辑

我在北弗吉尼亚州某处的AWS上有一台服务器,这是我的监视服务器.我从另一个州进入这个Ubuntu服务器进行系统管理.我想在此服务器上进行Web自动化测试,这将测试Internet上的Web应用程序是否命中URL,并验证我是否可以硒测试登录名并成功进行身份验证.该服务器位于AWS云上,我不确定要使用哪个Perl模块,因为我正在远程访问它.

I have a server on AWS somewhere in Northern Virginia and this is my monitoring server. I ssh into this Ubuntu server from another State to do system administration. I want to do web automation tests on this server which will test a web application on the Internet hitting a URL and verify that I can selenium test a login and authenticate successfully. This server is on an AWS cloud I'm not quite sure which Perl module to use since I'm accessing it remotely.

有两个CPAN模块:Selenium :: Remote :: Driver和WWW :: Selenium.我都尝试过,他们给了我一些问题.而且我真的不知道哪种方法适合我的情况.当我使用Selenium :: Remote :: Driver时,出现以下错误:

There are two CPAN modules: Selenium::Remote::Driver and WWW::Selenium. I have tried both and they are giving me issues. And I really don't know which is appropriate for my scenario. When I use Selenium::Remote::Driver, I get the following error:

Selenium server did not return proper status at     /usr/local/share/perl/5.18.2/Selenium/Remote/Driver.pm line 401.

当我使用WWW :: Selenium时,出现此错误:

When I use WWW::Selenium, I get this error:

Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser

我能够通过导出DISPLAY从AWS监控服务器手动启动firefox,但这确实很慢.我听说我可以使用无头浏览器,但必须通过以下方式导出DISPLAY:

I was able to launch firefox manually from the AWS monitoring server by exporting the DISPLAY but it was really slow. I have heard that I can use a headless browser but I would have to export the DISPLAY by:

export DISPLAY=:5

但是请记住,我是从台式机切入此AWS/Selenium服务器的,所以我假设我从台式机切入此AWS/Selenium服务器时使用上述命令吗?实际上,在这一点上,我不确定我是否在这里做.有人可以帮忙吗?

But remember, I'm sshing into this AWS/Selenium server from my desktop so I'm assuming I use the above command on the AWS/Selenium Server while I'm ssh into it from my desktop? Actually, at this point, I'm not sure I'm doing here. Can somebody help?

推荐答案

这类问题的问题在于,您的设置中的配置和二进制文件种类繁多,以至于很难实际提供简单的配置文件和二进制文件.您的设置的正确答案.该答案具有以下假设:

The problem in this type of questions is that the variety of configurations and binaries in your setup might be so broad that the it is hard to actually provide a straight and correct answer for YOUR SETUP. This answer has the following assumptions:

  • 您已将selenium-server-standalone.jar下载到/usr/lib/
  • 您拥有jdk 1.8(在外壳中运行 java -version
  • 您已经安装并配置了xvfb-run(这是一个斗争)因此:

```

 # ssh to your server , obs the -X !
 ssh -X user-name@server-name

 # start the selenium-server-standalone on the server
 xvfb-run -e /dev/stdout java -Dwebdriver.chrome.driver=/usr/bin/chromedriver -jar /usr/lib/selenium-server-standalone.jar &

  # one liner test - this is one veery long one 
 perl -e 'use strict ; use warnings ; use Data::Printer ; my $host="127.0.0.1"; use Selenium::Remote::Driver;my $driver = Selenium::Remote::Driver->new( "browser_name" =>"chrome", "error_handler" => sub { print $_[1]; croak 'goodbye'; }, "remote_server_addr" => "$host","port"=> "4444");$driver->debug_on();$driver->get("http://www.google.com"); print $driver->get_title();$driver->quit();' &

```

以下是作为perl脚本的单行代码

Here is the code in the one-liner as a perl script

#!/usr/bin/env perl
use strict ;
use warnings ;
use Carp ;
use Data::Printer ;
 use Selenium::Remote::Driver;

my $host="127.0.0.1";
my $driver = Selenium::Remote::Driver->new(
    "browser_name" =>"chrome"
  , "error_handler" => sub { print $_[1]; croak 'goodbye' ; }
  , "remote_server_addr" => "$host"
  , "port"=> "4444") ;
$driver->debug_on() ;
$driver->get("http://www.google.com");
print $driver->get_title();
$driver->quit();

输出应类似于:```

        Prepping get
        Executing get
        REQ: POST, http://127.0.0.1:4444/wd/hub/session/ddb9c2575ab026cdb8c640bdc554181b/url, {"url":"http://www.google.com"}
        RES: {"sessionId":"ddb9c2575ab026cdb8c640bdc554181b","status":0,"value":null}

        Prepping getTitle
        Executing getTitle
        REQ: GET, http://127.0.0.1:4444/wd/hub/session/ddb9c2575ab026cdb8c640bdc554181b/title, {}
        RES: {"sessionId":"ddb9c2575ab026cdb8c640bdc554181b","status":0,"value":"Google"}

        GooglePrepping quit
        Executing quit
        REQ: DELETE, http://127.0.0.1:4444/wd/hub/session/ddb9c2575ab026cdb8c640bdc554181b, {}
        RES: {"sessionId":"ddb9c2575ab026cdb8c640bdc554181b","status":0,"value":null}

```

这篇关于Perl和Selenium :: Remote :: Driver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆