Can't launch browser with Selenium Remote Driver - perl

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');

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');

How to change the logfile path of phantomjs through selenium?

i ran into a problem that seems to be a bug in selenium but maybe someone can hint me to a solution anyway.
A similar question has been asked 11 months ago see: How can I change logfile path of phantomjs with selenium?
but it was not solved.
I'm using Selenium::Remote::Driver in Perl to connect to selenium. My code looks like this:
my $driver = new Selenium::Remote::Driver(
'remote_server_addr' => 'localhost',
'port' => "4444",
'browser_name' => 'phantomjs',
extra_capabilities => {
'phantomjs.cli.args' => ['--webdriver-logfile=/tmp/phantomjsdriver.log']
}
);
I found out that the phantomjs devs have integrated the parameter phantomjs.cli.args to pass parameters through to phantomjs. The parameters show up but unfortunately are added to the default parameters.
See the logfile of selenium:
10:20:29.207 INFO - Creating a new session for Capabilities [{platform=ANY, javascriptEnabled=true, acceptSslCerts=true, phantomjs.cli.args=[--webdriver-logfile=/tmp/phantomjsdriver.log], browserName=phantomjs, version=}]
10:20:29.208 INFO - executable: /usr/local/node/bin/phantomjs
10:20:29.208 INFO - port: 5710
10:20:29.208 INFO - arguments: [--webdriver-logfile=/tmp/phantomjsdriver.log, --webdriver=5710, --webdriver-logfile=/phantomjsdriver.log]
10:20:29.208 INFO - environment: {}
PhantomJS is launching GhostDriver...
Unable to open file '/phantomjsdriver.log'
On the 4th line you can see that my argument was passed but the default '--webdriver-logfile=/phantomjsdriver.log' is also part of the arguments.
I tried also to set the loglevel to NONE but it tries to open the logfile anyways.
Lastly i tried to start phantomjs with a config file but i couldn't figure out the config option for the logfile and i'm not sure that would help.
My selenium server runs as a daemon if that is important.
Any help is appreciated!
Have a nice day
Have you tried using new_from_caps method for full control of your driver instance? Using this option no defaults are assumed by the constructor.
e.g.
my $driver = Selenium::Remote::Driver->new_from_caps(
desired_capabilities => {
'browserName' => 'phantomjs',
'phantomjs.cli.args' => ['--webdriver-logfile=/tmp/phantomjsdriver.log']
}
);
See doc here: https://metacpan.org/pod/Selenium::Remote::Driver#new_from_caps

Unable to connect to SeleniumWebDriver through 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!

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'
}
);

xdebug in xampp doesn't work on netbeans

I try to config xdebug but doesn't work I use:
XAMPP 1.7.4 , Netbeans 7.0
Xdebug installed: 2.1.0rc1
Server API: Apache 2.0 Handler
Windows: yes - Compiler: MS VC6 - Architecture: x86
Zend Server: no
PHP Version: 5.3.5
Zend API nr: 220090626
PHP API nr: 20090626
Debug Build: no
Thread Safe Build: yes
Configuration File Path: C:\WINDOWS
Configuration File: C:\xampp\php\php.ini
Extensions directory: C:\xampp\php\ext
And php.ini:
zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
xdebug.collect_includes = 1
xdebug.collect_params = 1
xdebug.collect_return = 1
xdebug.default_enable = 1
xdebug.extended_info = 1
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "C:\xampp\tmp"
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler = "DBGp"
xdebug.remote_host = "localhost"
xdebug.remote_port = 9000
Now the problems:
Menu attach Debugger is still disabled or grayed out.
When I try to debug the break point is never hit. Scripts run like a normal.
Following is the URL of I get when I click Debug main project:
http://localhost/index.php?XDEBUG_SESSION_START=netbeans-xdebug
When I close the browser debugger does not stop. It shows the waiting for connection status.
When I click the stop debugging button in NetBeans gives a messagebox There is no connection from xdebug detected with in some seconds xdebug is not configured or xdebug is not installed.
Please guide me to resolve the above mentioned issues and debug the project.
First are you able to see xdebug in http://localhost/xampp/index.php ? If NOT then probably you are NOT editing the right php.ini file? Seems like XAMPP is using the php.ini file in:
c:\xampp\apache\bin\php.ini
Enter your configuration for xdebug in that file, restart Apache and you should be able to connect.
There was no need for me to change anything in Netbeans to get it to work.
Screenshots here: http://rudyegenias.wordpress.com/2011/07/03/xampp-xdebug-xdebug-not-showing-in-phpinfo/
? to use XDebug on Netbeans & XAMPP
use http://xdebug.org/wizard.php to inspect your system and download best xdebug.dll
place that .dll in C:/xampp/php/ext
edit C:/xampp/php/php.ini adding following
[XDebug]
zend_extension = C:\xampp\php\ext\php_xdebug-2.2.3-5.5-vc11.dll
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.show_local_vars=on
xdebug.output_buffering=off
restart Apache web server
I've struggled with a lot of other setting but this is best to do the job