I navigated to google and called the get_current_url() method. but it's showing timeout and exiting the program.
Here is the code I tried
my $driver = Selenium::Remote::Driver->new(
'browser_name' => 'firefox',
'platform' => 'Windows',
'extra_capabilities' => {
'moz:firefoxOptions' => {},
}
);
$driver->debug_on() ;
$driver->get("https://www.google.com/");
wait_until {print $driver->get_path()};
$driver->quit;
I've turned on debug and got the following output in console
Prepping get
Executing get
REQ: POST, http://localhost:4444/wd/hub/session/69ced133-9420-4b0e-a7fd-e4f6bb343f7e/url, {"url":"https://www.google.co.in/"}
RES: {"value":null}
Prepping getCurrentUrl
Executing getCurrentUrl
REQ: GET, http://localhost:4444/wd/hub/session/69ced133-9420-4b0e-a7fd-e4f6bb343f7e/url, {}
RES: read timeout at C:/Perl64/lib/Net/HTTP/Methods.pm line 268.
Error while executing command: Server returned error message read timeout at C:/Perl64/lib/Net/HTTP/Methods.pm line 268.
instead of data at C:/Perl64/site/lib/Selenium/Remote/Driver.pm line 403.
at C:/Perl64/site/lib/Selenium/Remote/Driver.pm line 353.
Prepping quit
Executing quit
REQ: DELETE, http://localhost:4444/wd/hub/session/69ced133-9420-4b0e-a7fd-e4f6bb343f7e, {}
In console,program stucks here for while- 'Executing getCurrentURL' and later shown up with timeout message-Res:read timeout
The following works for me using Windows 10, Strawberry Perl version 5.30.1.
I installed geckodriver.exe from
https://github.com/mozilla/geckodriver/releases
and Selenium Server from
https://www.selenium.dev/downloads/
then downloaded firefox binary from
https://www.mozilla.org/en-US/firefox/new/
and then started the server successfully from the command prompt:
> java "-Dwebdriver.gecko.driver=geckodriver/geckodriver.exe" -jar selenium-server/selenium-server-standalone-3.141.59.jar -host localhost -port 4444
20:00:48.591 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
20:00:53.896 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2020-07-06 20:00:54.601:INFO::main: Logging initialized #12170ms to org.seleniumhq.jetty9.util.log.StdErrLog
20:01:05.928 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
20:01:23.567 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
Now the following Perl script works:
use feature qw(say);
use strict;
use warnings;
use Selenium::Remote::Driver;
my $driver = Selenium::Remote::Driver->new(
remote_server_addr => "127.0.0.1"
);
$driver->get('http://www.google.com');
say "Result: ", $driver->get_title();
$driver->quit();
Output:
Result: Google
Note: using localhost instead of 127.0.0.1 for remote_server_addr does not work for some reason, see this question for more information.
Related
I've installed the latest version of selenium via Docker:
docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:latest
and then ran this in my python console:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote("http://127.0.0.1:4444/wd/hub", DesiredCapabilities.CHROME)
and finally checked the docker logs:
2019-04-24 19:09:26,880 INFO Included extra file "/etc/supervisor/conf.d/selenium.conf" during parsing
2019-04-24 19:09:26,881 INFO supervisord started with pid 8
2019-04-24 19:09:27,865 INFO spawned: 'xvfb' with pid 11
2019-04-24 19:09:27,867 INFO spawned: 'selenium-standalone' with pid 12
19:09:28.038 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
2019-04-24 19:09:28,039 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2019-04-24 19:09:28,039 INFO success: selenium-standalone entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
19:09:28.093 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2019-04-24 19:09:28.126:INFO::main: Logging initialized #247ms to org.seleniumhq.jetty9.util.log.StdErrLog
19:09:28.289 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
19:09:28.349 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
19:09:43.631 INFO [ActiveSessionFactory.apply] - Capabilities are: {
"browserName": "chrome",
"version": ""
}
19:09:43.633 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}) on port 22103
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1556132983.659][SEVERE]: bind() failed: Cannot assign requested address (99)
19:09:44.266 INFO [ProtocolHandshake.createSession] - Detected dialect: OSS
19:09:44.490 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session cedc7067c0133f6492ff65dda5c7dd88 (org.openqa.selenium.chrome.ChromeDriverService)
In particular, I'm unsure of how to fix this error:
[1556132983.659][SEVERE]: bind() failed: Cannot assign requested address (99)
I'm running this on my macbook pro using Mojave with the latest version of docker, python, and selenium. I also tried using other ports aside from 4444, same result. Thanks!
We have seen that entry in the logs for a long time, however, there is no evidence it affects your tests. The message comes directly from ChromeDriver/Chrome. It is safe to ignore it.
I am trying to run the selenium server standalone in a vagrant box, with the following command:
java -jar selenium-server-standalone-3.13.0.jar
When I click the 'create session' button at http://lab.local:4444/wd/hub/static/resource/hub.html from my host web browser. I get a unable to create a new session error message.
I ask to create a firefox browser session for which I get the driver located in /usr/local/bin/geckodriver.
Firefox has been installed on the vagrant box with sudo apt install firefox-esr.
Error log detail:
14:52:04.485 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.13.0', revision: '2f0d292'
14:52:04.486 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
2018-08-09 14:52:04.564:INFO::main: Logging initialized #312ms to org.seleniumhq.jetty9.util.log.StdErrLog
14:52:04.757 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
14:52:15.563 INFO [ActiveSessionFactory.apply] - Capabilities are: {
"browserName": "firefox"
}
14:52:15.568 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.firefox.GeckoDriverService)
1533819135611 geckodriver INFO geckodriver 0.21.0
1533819135614 geckodriver INFO Listening on 127.0.0.1:25541
1533819135880 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.yuusnpGo8Gw6"
1533819136508 Marionette INFO Listening on port 2828
When I run the same executable directly from my host, I get no error and the firefox session is created with success.
I try to run a X server, Xvfb as follow but this does not change anything:
Xvfb :1 -screen 0 1600x1200x16 &
export DISPLAY=:1
java -jar selenium-server-standalone-3.13.0.jar
Problem solved after switching to selenium-server-standalone-3.3.1.jar with geckodriver 0.14.0. Sessions are created with success with this configuration.
source.
I can access url and create sessions:
http://localhost:4444/wd/hub/static/resource/hub.html
but when i execute ./codecept run i get an error, but i have Selenium Server running:
[ConnectionException] Can't connect to Webdriver at http://127.0.0.1:4444/wd/hub. Please make sure that Selenium Server or PhantomJS is running.
To execute Selenium Server, i used this command:
java -Dwebdriver.gecko.driver=./geckodriver -jar "selenium-server-standalone-3.12.0.jar"
I tried too with IE and Chrome (i have the same problem too):
java -Dwebdriver.chrome.driver=./chromedriver -jar "selenium-server-standalone-3.12.0.jar"
java -Dwebdriver.ie.driver=./IEDriverServer -jar "selenium-server-standalone-3.12.0.jar"
acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- \Helper\Acceptance
config:
WebDriver:
url: 'http://localhost'
browser: firefox
window_size: 820x1000
Codeception Version: 2.4.1
WebDriver Chrome Version: 2.38 (win32)
WebDriver Firefox Version: 0.20.1 (x64)
Chrome Version: 66.0.3359.139 (64-bit)
Firefox Version: Firefox Quantum 60.0 (64-bit)
Windows Version: Windows 8.1 64bit
Selenium Version: 3.12.0
To start Selenium Server you need not require to pass/specify the WebDriver variant and you can start the Selenium Server as follows :
Command :
>java -jar selenium-server-standalone-3.12.0.jar
Console Logs :
C:\Utility\selenium-server-standalone>java -jar selenium-server-standalone-3.12.0.jar
15:28:28.249 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.12.0', revision: '7c6e0b3'
15:28:28.251 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
2018-05-11 15:28:28.361:INFO::main: Logging initialized #467ms to org.seleniumhq.jetty9.util.log.StdErrLog
15:28:28.860 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
Snapshot of the Resource Hub :
Update
As per the documentation at codeception.com the acceptance.suite.yml should have been as follows :
modules:
enabled:
- WebDriver:
url: 'http://localhost/'
browser: firefox
window_size: 820x1000
Problem fixed. I was using proxy.
For future users with same problem like me, can follow the steps.
First, check if you have proxy defined with this command:
echo %http_proxy%
If return some result, you need set a empty proxy with this command:
set http_proxy=
You need define a proxy always you are opening a new command line.
I'm getting an error when trying to set up a phantomjs node on Selenium Grid (https://wiki.jenkins-ci.org/display/JENKINS/Selenium+Plugin)
I've set up the following custom json configuration:
{
"capabilities": [
{
"browserName": "phantomjs",
"phantomjs.binary.path": "/usr/bin/phantomjs",
"platform": "LINUX",
"maxInstances": 5
}
],
"configuration": {
"nodeTimeout":120,
"port":5555,
"hubPort":4444,
"hubHost":"localhost",
"nodePolling":2000,
"registerCycle":10000,
"register":true,
"cleanUpCycle":2000,
"timeout":30000,
"maxSession":1
}
}
But I get an error when I run webdriver against it:
WebDriverException: Message: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable; for more information, see https://github.com/ariya/phantomjs/wiki. The latest version can be downloaded from http://phantomjs.org/download.html
Stacktrace:
at com.google.common.base.Preconditions.checkState (Preconditions.java:199)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS (PhantomJSDriverService.java:236)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService (PhantomJSDriverService.java:181)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init> (PhantomJSDriver.java:104)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)
at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance (Constructor.java:526)
at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor (DefaultDriverProvider.java:103)
at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance (DefaultDriverProvider.java:97)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance (DefaultDriverFactory.java:60)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call (DefaultSession.java:222)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call (DefaultSession.java:1)
at java.util.concurrent.FutureTask.run (FutureTask.java:262)
at org.openqa.selenium.remote.server.DefaultSession$1.run (DefaultSession.java:176)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:615)
at java.lang.Thread.run (Thread.java:745)
-------------------- >> begin captured logging << --------------------
selenium.webdriver.remote.remote_connection: DEBUG: POST http://127.0.0.1:4444/wd/hub/session {"desiredCapabilities": {"browserName": "phantomjs"}}
selenium.webdriver.remote.remote_connection: DEBUG: Finished Request
If I stop the node started by the plugin (and keep the plugin hub running), and manually run my own node as follows, it works fine:
java -jar selenium-server-standalone-2.53.0.jar -role webdriver
-browser browserName=phantomjs,platform=LINUX
-hub http://localhost:4444/grid/register
[edit] phantomjs is executable from the shell and lives at /usr/bin/phantomjs:
$ whereis phantomjs
phantomjs: /usr/bin/phantomjs
I can't find a canonical description online of a phantomjs setup and this isn't one of the default browser options provided by the plugin.
The problem with the above was the OS permissions on /usr/bin/phantomjs; I needed to do chmod a+x on it.
Cheekily adding this additional problem
This works (manually started by me):
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64/jre/bin/java -jar /var/lib/jenkins/selenium-server-standalone-2.53.0.jar -role webdriver -browser browserName=phantomjs,platform=LINUX -hub http://localhost:4444/grid/register
This doesn't (the process started by the selenium plugin):
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64/jre/bin/java -cp /var/cache/jenkins/war/WEB-INF/lib/remoting-2.56.jar hudson.remoting.Launcher -cp /var/lib/jenkins/selenium-server-standalone-2.53.0.jar:/var/lib/jenkins/htmlunit-driver-standalone-2.20.jar -connectTo localhost:36322
Error I'm getting when running the test:
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: The process has not exited yet therefore no result is available
Adding the answer just in case someone misses the comment.
Please check if phantomjs has 'x' (execute) access for all users. If it doesnt, then use the command to change the access.
chmod +x /usr/bin/phantomjs
The new error "The process has not exited yet therefore no result is available" mostly comes with selenium/driver version mismatch. You could try downgrading the version of selenium.
Btw, what version of phantomjs are you using.
Try adding -Dphantomjs.binary.path=/usr/bin/phantomjs to your Java flags for Jenkins (typically look to /etc/default/jenkins or /etc/sysconfig/jenkins).
juste add path in command line like this:
'/usr/bin/java' -Dphantomjs.binary.path='/home/john/.local/share/binman_phantomjs/linux64/2.1.1/phantomjs-2.1.1-linux-x86_64/bin/phantomjs' -jar '/home/john/.local/share/binman_seleniumserver/generic/3.0.1/selenium-server-standalone-3.0.1.jar'
My English is not so good. Sorry.
I have:
PHPUnit 3.7.24
Selenium 2.35.0
I am starting selenium server:
java -jar /usr/local/bin/selenium-server-standalone-2.35.0.jar
Output:
04.09.2013 13:51:15 org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
13:51:25.373 INFO - Java: Sun Microsystems Inc. 20.45-b01
13:51:25.374 INFO - OS: Linux 3.8.0-29-generic i386
13:51:25.388 INFO - v2.35.0, with Core v2.35.0. Built from revision c916b9d
13:51:25.542 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
13:51:25.543 INFO - Version Jetty/5.1.x
13:51:25.544 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
13:51:25.545 INFO - Started HttpContext[/selenium-server,/selenium-server]
13:51:25.546 INFO - Started HttpContext[/,/]
13:51:25.567 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler#dda25b
13:51:25.567 INFO - Started HttpContext[/wd,/wd]
13:51:25.571 INFO - Started SocketListener on 0.0.0.0:4444
13:51:25.577 INFO - Started org.openqa.jetty.jetty.Server#b61fd1
My simple test:
public function testTitle()
{
$this->url('/');
$this->assertEquals('My title.', $this->title());
}
Next, run phpunit test with command:
phpunit --debug functional/MainPageTest.php
Output:
PHPUnit 3.7.24 by Sebastian Bergmann.
Configuration read from /home/demyan112rv/www/boo/protected/tests/phpunit.xml
Starting test 'MainPageTest::testTitle'.
E
Time: 17.59 seconds, Memory: 2.75Mb
There was 1 error:
1) MainPageTest::testTitle
PHP Warning: include(PHPUnit_Extensions_Story_TestCase.php): failed to open stream: No such file or directory in /home/demyan112rv/www/yii/YiiBase.php on line 421
PHP Warning: include(): Failed opening 'PHPUnit_Extensions_Story_TestCase.php' for inclusion (include_path='.:/home/demyan112rv/www/boo/protected/helpers:/home/demyan112rv/www/boo/protected/widgets:/home/demyan112rv/www/boo/protected/extensions/mail:/home/demyan112rv/www/boo/protected/services:/home/demyan112rv/www/boo/protected/components:/home/demyan112rv/www/boo/protected/models:/usr/share/php:/usr/share/pear') in /home/demyan112rv/www/yii/YiiBase.php on line 421
BadMethodCallException: The command http://localhost:4444/wd/hub/session/url is not recognized by the server.
/home/demyan112rv/www/yii/test/CWeb2TestCase.php:60
/home/demyan112rv/www/boo/protected/tests/functional/MainPageTest.php:11
/home/demyan112rv/www/boo/protected/tests/functional/MainPageTest.php:11
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
And in this time in selenium server a have next output:
13:55:39.438 INFO - Executing: [new session: {browserName=firefox}] at URL: /session)
13:55:39.452 INFO - Creating a new session for Capabilities [{browserName=firefox}]
13:55:56.642 INFO - Done: /session
I have error "BadMethodCallException: The command http:/ /localhost:4444/wd/hub/session/url is not recognized by the server.". This bug fixed for 2.35 in this link , but i have 2.35 and i have this error.
How to fix this problem?
Solution (i don't may answer on my question, because my rating is less than 10.
$ whereis phpunit
phpunit: /usr/bin/phpunit /usr/bin/X11/phpunit /usr/local/bin/phpunit
I have 3 path to phphunit. I don't know, it's normal or no.
When i changed command from:
phpunit --debug functional/MainPageTest.php
to
/usr/bin/phpunit --debug functional/MainPageTest.php
it's working!!!
if you have setUp your browser launch method i.e
function setUp()
{
$this->setBrowser("*firefox");
$this->setBrowserUrl("http://www.google.com/");
}
your function should look like this
public function testTitle()
{
$this->open('/');
$this->assertEquals('My title.', $this->title());
}
I've changed $this -> url('/'); to $this -> open('/');
please try now.