Unable to connect to SeleniumWebDriver through Perl - perl

I have written a simple Perl script to launch google. But it terminates with an error - Could not connect to SeleniumWebDriver at C:/perl/lib/Selenium/Remote/Driver.pm line 220
I am using selenium server version - 2.31
OS - windows7 (32 bit)
Perl Code
use warnings;
use strict;
use Selenium::Remote::Driver;
my $driver = Selenium::Remote::Driver->new( browser_name => 'firefox', port => 4444,
platform => 'ANY');
$driver->get('http://www.google.com');
sleep(5);
print $driver->get_title();
$driver->quit();
When i execute perl script, at each instance, on server command prompt i could see this line -
14:07:23.325 INFO - Executing: org.openqa.selenium.remote.server.handler.Status#
8e96fc at URL: /status)
14:07:23.327 INFO - Done: /status
But browser is not getting launched. Please can anybody help me about the issue?

Did you start the selenium server on a machine with firefox and X (assuming Linux)
and maybe add the proxy in
{remote_server_addr=>'localhost', port=>4444,proxy => { 'proxyType' => 'system' }}
can you post how you're starting selenium

I started the selenium server using command
"java -jar selenium-server-standalone-2.31.0.jar"
But the issue get resolved now. I guess it was Perl issue. I was using Active Perl V 5.16.
Then i installed Strawberry Perl V 5.18 and it worked.
Thank you!

Related

Perl and Selenium::Remote::Driver

EDITED AGAIN
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.
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.
When I use WWW::Selenium, I get this error:
Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser
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
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:
you have downloaded the selenium-server-standalone.jar into /usr/lib/
you have jdk 1.8 ( run the java -version in the shell
you have installed and configured the xvfb-run ( it is a fight on it's own )
So :
```
# 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();' &
```
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();
The output should look something like:
```
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}
```
Try running the below code:
#!/usr/bin/perl
use warnings;
use strict;
use Selenium::Remote::Driver;
my $host = "10.10.1.1"; //Enter your server IP in this place
my $driver = new Selenium::Remote::Driver('remote_server_addr' => $host,
'port' => '4444',
'auto_close' => 0);
$driver->get('http://www.google.com');

Can't get DBD::ODBC to work with DataDirect ODBC Driver Manager 7.0 - [DataDirect][ODBC lib] Specified driver could not be loaded (SQL-IM003)

I'm trying to set-up PERL DBD::ODBC to use the DataDirect ODBC Driver Manager (7.0) that is provided with Informatica PowerCenter. This is on a Solaris 10 Sparc64 environment. We've had this working in the past with the 5.1 driver manager (on an sp32 server), but now running into problems since moving to this new version. For all ODBC connections I get this error:
failed: [DataDirect][ODBC lib] Specified driver could not be loaded (SQL-IM003) at test_odbctd.pl line 19
Can't connect to DBI:ODBC:tdedwprd: [DataDirect][ODBC lib] Specified driver could not be loaded (SQL-IM003) at test_odbctd.pl line 19, <STDIN> line 2.
I have tested the same connections using the "ssgodbc" tool provided by Informatica for testing and they work. I can login and run queries.
As an example, here's one of my Teradata connections as definied in odbc.ini (we're having the same problem with DB2, SQL Server, Teradata, Sybase, PowerExchange, etc). Don't ask why I have to hard-code the full driver path in this file instead of odbcinst.ini. I couldn't get it to work and the Informatica standard is to hard-code it in odbc.ini so I don't want to affect our support from them.
[tddev]
Driver=/opt/teradata/client/odbc/drivers/tdata.so
Description=Teradata Development
DBCName=teradata1
DBCName2=teradata2
MaxRespSize=65477
DateTimeFormat=AAA
EnableExtendedStmtInfo=No
LoginTimeout=60
ldd output for the driver:
$ ldd /opt/teradata/client/odbc/drivers/tdata.so
warning: ldd: /opt/teradata/client/odbc/drivers/tdata.so: is not executable
libCstd.so.1 => /opt/SUNWspro/lib/v9/libCstd.so.1
libthread.so.1 => /usr/lib/sparcv9/libthread.so.1
libm.so.1 => /usr/lib/sparcv9/libm.so.1
libw.so.1 => /usr/lib/sparcv9/libw.so.1
libc.so.1 => /usr/lib/sparcv9/libc.so.1
libsocket.so.1 => /usr/lib/sparcv9/libsocket.so.1
libnsl.so.1 => /usr/lib/sparcv9/libnsl.so.1
libxnet.so.1 => /usr/lib/sparcv9/libxnet.so.1
libodbcinst.so => /opt/powercenter/v951/ODBC7.0/lib/libodbcinst.so
libddicu25.so => /opt/teradata/client/odbc/lib/libddicu25.so
libtdparse.so => /opt/teradata/client/odbc/lib/libtdparse.so
libicudatatd.so.46 => /usr/lib/sparcv9/libicudatatd.so.46
libicuuctd.so.46 => /usr/lib/sparcv9/libicuuctd.so.46
libCrun.so.1 => /opt/SUNWspro/prod/usr/lib/v9/libCrun.so.1
libmp.so.2 => /lib/64/libmp.so.2
libmd.so.1 => /lib/64/libmd.so.1
libscf.so.1 => /lib/64/libscf.so.1
libDWicu26.so => /opt/powercenter/v951/ODBC7.0/lib/libDWicu26.so
libdl.so.1 => /usr/lib/sparcv9/libdl.so.1
librt.so.1 => /usr/lib/sparcv9/librt.so.1
libpthread.so.1 => /usr/lib/sparcv9/libpthread.so.1
libdoor.so.1 => /lib/64/libdoor.so.1
libuutil.so.1 => /lib/64/libuutil.so.1
libgen.so.1 => /lib/64/libgen.so.1
libaio.so.1 => /lib/64/libaio.so.1
libm.so.2 => /lib/64/libm.so.2
/lib/sparcv9/../libm/sparcv9/libm_hwcap1.so.2
/platform/sun4v/lib/sparcv9/libc_psr.so.1
/platform/sun4v/lib/sparcv9/libmd_psr.so.1
I tried to run strace as the user that uses these connections, but I get this error so not sure what to do with that:
$ strace perl test_odbctd.pl
ERROR: unable to open /dev/log
Here's the PERL test script we're using:
#!/usr/bin/perl -w
use DBI;
# use DBD::ODBC;
# use DBD::DB2::Constants;
my $data_source = "DBI:ODBC:tdedwprd";
#Prompt for username
print "Enter user:";
my $user = <STDIN>;
#Prompt for password
print "Enter password:";
my $password =<STDIN>;
# Connect to the tdedwdev teradata database
my $dbh = DBI->connect($data_source, $user, $password, {AutoCommit =>1})
or die "Can't connect to $data_source: $DBI::errstr";
$stmt = "SELECT database, time; ";
$sth = $dbh->prepare($stmt);
$sth->execute();
#associate variable with output columns...
$sth->bind_col(1,\$db);
$sth->bind_col(2,\$timestap);
while ($sth->fetch) {
print "The database is: $db\n";
print "The time is: $timestap\n";
}
$dbh->disconnect;
The above script works on our existing dev box (Solaris 10 sp32), but not on the new one we're building (Solaris 10 sp64).
The old server had the driver manager bundled with Informatica PowerCenter 8.6.1 sp32, and the new one has Informatica PowerCenter 9.5.1 sp64.
The DBD::ODBC module did compile fine with some modifications, roughly following this guide from DataDirect (the logic was basically the same, but the references to the Makefile.PL weren't identical):
http://knowledgebase.datadirect.com/articles/Article/2973
I enabled Trace in odbc.ini (Trace=1) but this just resulted in a "Segmentation Fault (core dumped)". However it does output a trace file when using the Informatica-provided "ssgodbc" tool.
I tried using isql, but it seems to be tied to the Sybase drivers so I'm not sure if I can use that. I couldn't get it to work
$ which isql
/opt/sybase/OCS-15_0/bin/isql
Here are my ODBC environment variables:
$ env | grep -i odbc
MANPATH=/usr/share/man:/opt/teradata/client/14.00/odbc_32/help/man:
ODBCINST=/opt/powercenter/v951/ODBC7.0/odbcinst.ini
LD_LIBRARY_PATH=/opt/powercenter/v951/ODBC7.0/lib:/opt/powercenter/v951/server/bin:/home/etlin1d/sqllib/lib:/opt/pwx/v851:/opt/sybase/OCS-15_0/lib:/opt/sybase/OCS-15_0/lib3p64:/opt/sybase/OCS-15_0/lib3p:/opt/teradata/client/14.00/tbuild/lib:/opt/teradata/client/odbc/lib:/opt/teradata/client/odbc/drivers:/opt/teradata/client/14.00/tbuild/lib:/usr/lib:/prj/db2/etlin1d/sqllib/lib64:/prj/db2/etlin1d/sqllib/lib32:/usr/lib
LD_LIBRARY_PATH_64=/opt/powercenter/v951/ODBC7.0/lib:/opt/powercenter/v951/server/bin:/opt/pwx/v851:/prj/db2/etlin1d/sqllib/lib64:/opt/sybase/OCS-15_0/lib:/opt/sybase/OCS-15_0/lib3p64:/opt/sybase/OCS-15_0/lib3p:/opt/teradata/client/14.00/tbuild/lib:/opt/teradata/client/odbc/lib:/opt/teradata/client/odbc/drivers:/usr/lib
NLSPATH=/opt/teradata/client/14.00/odbc_64/msg:/opt/teradata/client/14.00/odbc_32/msg:/opt/teradata/client/14.00/tbuild/msg/%N:/opt/teradata/client/14.00/tbuild/msg/%N:/opt/teradata/client/14.00/odbc_32/msg/%N:
PATH=/opt/sybase/ASEP/bin:/opt/sybase/DBISQL/bin:/opt/sybase/UAF-2_0/bin:/opt/sybase/OCS-15_0/bin:/opt/teradata/client/14.00/tbuild/bin:/opt/teradata/client/14.00/tbuild/bin:/usr/bin:/bin:/usr/local/bin:/opt/powercenter/v951/ODBC7.0/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/powercenter/v951/server/bin:.:/prj/db2/etlin1d/sqllib/bin:/prj/db2/etlin1d/sqllib/adm:/prj/db2/etlin1d/sqllib/misc:/prj/db2/etlin1d/sqllib/db2tss/bin
ODBCINI=/opt/powercenter/v951/ODBC7.0/odbc.ini
ODBCHOME=/opt/powercenter/v951/ODBC7.0
I'm totally at a loss. I'm not a Solaris admin by trade though (in fact this is my first significant exposure to Solaris and Informatica really) so I'm hoping I'm missing something obvious.
I'm not sure what else to share right now. Any help would be GREATLY appreciated. I've been stuck on problems with this ODBC implementation for weeks.
I realised that the problem here was not with the driver manager. It was caused by the fact that I was using 32-bit Perl but a 64-bit ODBC driver. If I added an entry that used a 32-bit ODBC driver to odbc.ini (despite the driver manager being 64-bit) then there is no problem (although it did raise a licensing issue which is separate to this discussion).
In short, this error message occured because the driver is not the same bitness as the client (check by running the file command against both client and driver):
Specified driver could not be loaded
An example of the file command is:
file /opt/teradata/client/odbc/drivers/tdata.so
However, it also occurs when the driver cannot find all of its dependent drivers, which can be checked using ldd on the driver to make sure it is finding all of its dependencies.
An example of the ldd command is:
ldd /opt/teradata/client/odbc/drivers/tdata.so
I tried the above method given by LokMac, all dependant drivers were there and still it wont work, at the end I added "# Driver: The location where the ODBC driver is installed to." before driver path and it magically worked:
[tddemo]
# Driver: The location where the ODBC driver is installed to.
Driver=/opt/teradata/client/16.20/odbc_64/lib/tdataodbc_sb64.so
in above, tddemo is my DNS name and since I am on TD Express 16.20, thats why my driver name is different.

Undefined subroutine LWP::Protocol::https::Socket::can_read called

I'm trying to script some interaction between a Linux box and an ESXi host, using the VMware Perl library (which appears to call a SOAP service on the ESXi host).
I am getting an error for which I can't find a solution: Undefined subroutine &LWP::Protocol::https::Socket::can_read called at /usr/local/share/perl5/LWP/Protocol/http.pm line 22
I am currently running Net-HTTP-6.03. I did try with Net-HTTP-6.05 but it makes the web-based calls very slow (and subsequent ones also eventually fail, instead with about 1.2MB of XML as the error message) -- which various forums suggest is only resolvable by reverting to 6.03 (via cpan install GAAS/Net-HTTP-6.03.tar.gz).
The crux of my code is as follows:
use VMware::VIRuntime;
my $context = {
options => ParseOptions(), # result of using GetOpts::Long to parse command-line
session => undef
};
$ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL"; # Suppresses SSL_VERIFY_NONE
if ($context->{options}->{'ignore-ssl-errors'}) {
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; # Ignores certificate errors
}
## next line fails
$context->{session} = Vim::login(
service_url => $context->{options}->{url},
username => $context->{options}->{username},
password => $context->{options}->{password}
);
Is there something else I (can|need to) do to get this working?
I've got it. I needed to reinstall Bundle::LWP from an older version, not just Net-HTTP. Without it, I had LWP v6.05 trying to talk to Net-HTTP v6.03.
Once I realised that LWP == libwww-perl (yes, I'm that new), I found the overall package I needed:
cpan install GAAS/libwww-perl-6.03.tar.gz
Reproduced with LWP 6.05 and Net::HTTP 6.01, which is the cocktail that MacPorts installs at the time of this writing. Upgrading Net::HTTP to 6.06 (current) solved it:
sudo cpan Net::HTTP

Can't launch browser with Selenium Remote Driver

I don't know why but I cannot launch browser using the below code. I am using EPIC on eclipse. I have installed required selenium modules for this.
I get this error when I run below mentioned code: "Could not connect to SeleniumWebDriver at C:/ProgramFiles/Perl/site/lib/Selenium/Remote/Driver.pm line 220"
Any help is appreciated.
Here is my code:
use Selenium::Remote::Driver;
my $driver = new Selenium::Remote::Driver(browser_name => 'firefox', port => 5555,
platform => 'WINDOWS');
$driver->get('http://www.google.com');
print $driver->get_title();
$driver->quit();
It might be closing the page before you notice it? Also, I think by default the port number selenium listens on is 4444.
Try this:
use Selenium::Remote::Driver;
my $driver = new Selenium::Remote::Driver(browser_name => 'firefox', port => 4444,
platform => 'ANY',);
$driver->get('http://www.google.com');
sleep(200);
print $driver->get_title(),"\n";
$driver->quit();
I changed the Selenium version to 2.31 and it worked. Previously I was using 2.28 which had incompatibility with FF 19
Charles, my PC was updated with new Java version and so my server start up file was failing to start the server. I corrected the start up file with correct java path and it launches the browser.
But I don't know why it gives blank page as it should open google.com
before run the code you should start the remote server.
Enter the path as below where your chrome driver and jar file are exited in your system and
Go to the command prompt an run the following command- please
java -Dwebdriver.chrome.driver="\Enter folder path\chromedriver.exe" -jar \Enter folder path\selenium-server-standalone-2.53.0.jar
and if you are using Firefox then write the following code.
my $driver = Selenium::Remote::Driver->new();
for chrome user following -
my $driver = Selenium::Remote::Driver->new(browser_name => 'chrome');

How to set up Chrome driver for Selenium Grid 2 (Perl binding)?

I'm trying to set up Selenium Grid 2 (Ubuntu-host for hub and Perl installed and Windows-host for various browsers (Firefox, IE, Chrome, Opera)). Everything works fine, I can start short sample test against IE, FF, Opera and see how browser is open and page is loaded. Here is the test:
#!/usr/bin/perl
use Selenium::Remote::Driver;
use Test::More tests=>4;
my $driver = Selenium::Remote::Driver -> new(
'browser_name' => 'internet explorer'
);
$driver->get("http://www.google.com");
$driver->quit();
But I can't make Chrome to work. I started Selenium-server with custom driver option on Windows-host (is this correct?) with
java -jar selenium-server-standalone-2.22.0.jar -role node -hub http://my-ubuntu-host:4444/grid/register -browser "browserName=chrome,version=19" -Dwebdriver.chrome.driver="c:\selenium-2-22-0\chromedriver.exe"
And when I attempt to run a test on Ubuntu-host with 'browser_name' => 'chrome' it only reports short error-message:
caligula#my-ubuntu-host:~/www$ ./test.pl
1..4
Could not create new session at ./test.pl line 5.
# Looks like your test exited with 255 before it could output anything.
Can somebody assist me with this? There are a lot of examples, but they are all in Java and I couldn't accommodate any of them to Perl code.
Also I noticed that chrome driver archive was named chromedriver_win_20.0.1133.0.zip. Is it compatible with selenium server 2.22 ? I've tried to use selenium server 2.20 but then nothing worked at all: nor FF, nor IE.
Required parameter 'proxy' => {HASH} was not passed to the constructor. Only chrome-driver throws an exception, whereas when you call FF or IE everything is fine.
There was short message in console:
org.openqa.selenium.WebDriverException: proxy must be of type dictionary, not null.
Received: null
creating Selenium::Remote::Driver instance in the following way solved the problem:
my $driver = new Selenium::Remote::Driver(
'browser_name' => 'chrome',
'proxy' => {
'proxyType' => 'system'
}
);