Unable to launch Chrome Browser in Selenium Remote WebDriver - java

I am new to Selenium. I am trying to Launch Chrome using Remote web driver. Below are the environment I am using.
Windows : Windows 10 Enterprise
Java Version : 9.0.4
Selenium Standalone Jar : 3.5.3
IDE : Eclipse
Started hub and node servers on my local machine like below -
On one CMD session -
java -jar selenium-server-standalone-3.5.3.jar -role hub
22:10:41.391 INFO - Selenium build info: version: '3.5.3', revision: 'a88d25fe6b'
22:10:41.391 INFO - Launching Selenium Grid hub
2022-05-25 22:10:43.322:INFO::main: Logging initialized #2152ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:10:43.332 INFO - Will listen on 4444
2022-05-25 22:10:43.365:INFO:osjs.Server:main: jetty-9.4.5.v20170502
2022-05-25 22:10:43.381:INFO:osjs.session:main: DefaultSessionIdManager workerName=node0
2022-05-25 22:10:43.381:INFO:osjs.session:main: No SessionScavenger set, using defaults
2022-05-25 22:10:43.382:INFO:osjs.session:main: Scavenging every 600000ms
2022-05-25 22:10:43.387:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler#4d0d9fe7{/,null,AVAILABLE}
2022-05-25 22:10:43.399:INFO:osjs.AbstractConnector:main: Started ServerConnector#1500b2f3{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
2022-05-25 22:10:43.400:INFO:osjs.Server:main: Started #2230ms
22:10:43.400 INFO - Nodes should register to http://********:4444/grid/register/
22:10:43.401 INFO - Selenium Grid hub is up and running
22:10:44.300 INFO - Registered a node http://******:5555
22:10:54.537 INFO - Registered a node http://********:5555
22:10:54.537 WARN - Cleaning up stale test sessions on the unregistered node http://********:5555
And on another CMD session i have like below -
java -jar -Dwebdriver.chrome.driver="C:\********\chromedriver.exe" selenium-server-standalone-3.5.3.jar -role node -hub http://localhost:4444
22:10:51.312 INFO - Selenium build info: version: '3.5.3', revision: 'a88d25fe6b'
22:10:51.313 INFO - Launching a Selenium Grid node
2022-05-25 22:10:53.750:INFO::main: Logging initialized #2658ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:10:53.773 INFO - Driver class not found: com.opera.core.systems.OperaDriver
22:10:53.783 INFO - Driver provider class org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform WIN10
22:10:53.798 INFO - Using the passthrough mode handler
2022-05-25 22:10:53.811:INFO:osjs.Server:main: jetty-9.4.5.v20170502
2022-05-25 22:10:53.824:WARN:osjs.SecurityHandler:main: ServletContext#o.s.j.s.ServletContextHandler#4ed5eb72{/,null,STARTING} has uncovered http methods for path: /
2022-05-25 22:10:53.826:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler#4ed5eb72{/,null,AVAILABLE}
2022-05-25 22:10:53.837:INFO:osjs.AbstractConnector:main: Started ServerConnector#e19bb76{HTTP/1.1,[http/1.1]}{0.0.0.0:5555}
2022-05-25 22:10:53.837:INFO:osjs.Server:main: Started #2745ms
22:10:53.837 INFO - Selenium Grid node is up and ready to register to the hub
22:10:53.845 INFO - Starting auto registration thread. Will try to register every 5000 ms.
22:10:53.845 INFO - Registering the node to the hub: http://localhost:4444/grid/register
22:10:54.537 INFO - The node is registered to the hub and ready to use
I have the code for Chrome like below -
public class ChromeFactory extends DriverFactory{
String mcWebUrl;
public ChromeFactory(String mcURL) {
mcWebUrl = mcURL;
initBrowser();
}
#Override
protected void initBrowser() {
try {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setBrowserName("chrome");
URL remoteUrl = new URL("http://*******:4444/wd/hub");
WebDriver driver = new RemoteWebDriver(cap);
driver.get(mcWebUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
I get a below message in red and thats all the Browser do not launch -
May 25, 2022 10:23:25 PM org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer createTracer
INFO: Using OpenTelemetry for tracing

WebDriver driver = new RemoteWebDriver(cap);
You are missing the parameter URL in the RemoteWebDriver constructor.
The correct way to call is:
URL remoteUrl = new URL("http://*******:4444/wd/hub");
WebDriver driver = new RemoteWebDriver(*remoteUrl* , cap);

Related

Gitlab ci selenium testing with docker not connecting to RemoteWebDriver

I want to run automatically selenium tests with gitlab-ci, docker.
Locally everything works fine, but it seems like, there are some connection issues with docker and selenium.
The job is failing with
selenium.test.dashboard.MyTest > myFirstTest FAILED
org.openqa.selenium.remote.UnreachableBrowserException
Caused by: java.net.ConnectException
Caused by: java.net.ConnectException
java.lang.NullPointerException
I tried to change different url's to connect to selenium server and I thought there is maybe a port issue. But every combination which I tried ended up with the same result.
.gitlab-ci.yml
image: gradle:alpine
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
stages:
- build
- seleniumTesting
build:
stage: build
script:
- echo $CI_JOB_STAGE
- echo $CI_COMMIT_REF_NAME
- gradle --build-cache war
artifacts:
paths:
- public
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
seleniumTestingChrome:
stage: seleniumTesting
script: gradle integrationTest
# services:
# - selenium/standalone-chrome:latest
services:
- name: selenium/standalone-chrome:latest
artifacts:
paths:
- build/reports/tests/
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
Java code for RemoteWebDriver
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
try {
// driver = new RemoteWebDriver( new URL("http://selenium_standalone-chrome:4444/wd/hub"), capabilities);
WebDriver driver = new RemoteWebDriver( new URL("http://127.0.0.1:4444/wd/hub"), capabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
created container on runner
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92f018da4cbe 8017d8c2ba74 "sh -c 'if [ -x /usr…" 20 seconds ago Up 19 seconds runner-Y2QWpCBd-project-4-concurrent-0-build-4
9dfdc838a7af 9e599fb82f84 "/opt/bin/entry_poin…" 40 seconds ago Up 38 seconds 4444/tcp runner-Y2QWpCBd-project-4-concurrent-0-selenium__standalone-chrome-0
docker logs command on runner
019-08-30 17:06:02,099 INFO Included extra file "/etc/supervisor/conf.d/selenium.conf" during parsing
2019-08-30 17:06:02,101 INFO supervisord started with pid 7
2019-08-30 17:06:03,106 INFO spawned: 'xvfb' with pid 10
2019-08-30 17:06:03,109 INFO spawned: 'selenium-standalone' with pid 11
17:06:03.826 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
2019-08-30 17:06:03,830 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2019-08-30 17:06:03,830 INFO success: selenium-standalone entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
17:06:04.065 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2019-08-30 17:06:04.200:INFO::main: Logging initialized #1058ms to org.seleniumhq.jetty9.util.log.StdErrLog
17:06:04.804 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
17:06:05.050 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
I do expect that the test is running on the gitlab-ci-runner in a docker container. Connects to the selenium-server and executes the selenium test with a public available url
As pointed out by #Sascha Frinken
The URL to connect to the RemoteWebDriver was wrong. I missed one underscore.
"http://selenium_standalone-chrome:4444/wd/hub"
VS
"http://selenium__standalone-chrome:4444/wd/hub"
there is topic in gitlab https://docs.gitlab.com/ee/ci/services/#accessing-the-services, which states
Everything after the colon (:) is stripped.
Slash (/) is replaced with double underscores (__) and the primary alias is created.
Slash (/) is replaced with a single dash (-) and the secondary alias is created (requires GitLab Runner v1.1.0 or higher).

Selenium GeckoDriver get IP and Port no of the launched driver instance

I'm using Selenium 3.4, Geckodriver 0.17.
I launch FirefoxDriver using the below code
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.bing.com");
System.out.println(driver.getSessionId());
Is there a way I can get the IP and the port of the launched driver instance?
The data I want is printed in the logs.
1499170600204 geckodriver INFO Listening on 127.0.0.1:38840
1499170601127 geckodriver::marionette INFO Starting browser C:\Program Files\Mozilla Firefox\firefox.exe with args ["-marionette"]
[GFX1]: Potential driver version mismatch ignored due to missing DLLs igd10umd32 v= and igd10iumd32 v=
1499170608388 Marionette INFO Listening on port 12793
Jul 04, 2017 5:46:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
The First line of the output 127.0.0.1:38840 prints the info I want. I don't want to parse the log as I will be running drivers in parallel.
The RemoteWebDriver has getCommandExecutor method.
Which can be TypeCasted to HttpCommandExecutor and getAddressOfRemoteServer() method returns the URL.
HttpCommandExecutor ce = (HttpCommandExecutor) driver.getCommandExecutor();
System.out.println(ce.getAddressOfRemoteServer());

Selenium 3.0.1 with new FirefoxDriver + Marionette stuck on start page

I'm migrating my Selenium app from 2.53 to 3.0.1. First of all, I want to test it in a small app just launching a browser and navigating to a specific page.
Moreover, I want to use a custom binary for Firefox (version 51.0, Portable App).
This is my code:
public class Selenium {
public static void main(String[] args) {
WebDriver driver = createFFDriver();
driver.navigate().to("http:....");
System.out.println("Finished");
}
public static WebDriver createFFDriver(){
System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY,"foo/geckodriver64.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("firefox_binary","foo/firefox.exe");
return new FirefoxDriver(capabilities);
}
}
The browser actually opens up, but blocked.
Logs:
1486713046153 geckodriver INFO Listening on 127.0.0.1:12466
Feb 10, 2017 8:50:46 AM org.openqa.selenium.remote.ProtocolHandshake
createSession INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1486713046731 mozprofile::profile INFO Using profile path foo\AppData\Local\Temp\rust_mozprofile.p25D0Gb1sBQm
1486713046752 geckodriver::marionette INFO Starting browser foo\firefox\51.0\FirefoxPortable.exe
1486713046782 geckodriver::marionette INFO Connecting to Marionette on localhost:52818
Why is Geckodriver listening on 127.0.0.1:12466 but it's trying to connect to Marionette on localhost:52818 ?
This is the page where I get stuck:
EDIT:
It gets stuck in the RemoteWebDriver startSession method:
Response response = this.execute("newSession", parameters);
I have tried your code with Selenium V 3.0.1 and Firefox 51.0.1 (32-bit) and was successful in accessing URL/other web driver functions/no blocking.
UPDATE
WebDriver firefox;
System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY,"pathtogeckodriver");
FirefoxProfile profile = new FirefoxProfile();
firefox = new FirefoxDriver( new FirefoxBinary(
new File(System.getProperty("user.dir"),
"\\FirefoxPortable\\FirefoxPortable.exe")), profile);
driver.get("http://www.google.com");
This works perfectly with Portable Firefox version (51.0.1)
It seems that the Portable Edition of Firefox isn't working well with Gecko Driver.
It works as expected with traditional Firefox (51.0.1).

Selenium RC: I am unable run test suite in firefox or any other browser

I am newbie with Selenium. I recently encountered with one failure that I could not overcome.
I am trying to run next suite in firefox or chrome:
C:\auto_tools>java -jar selenium-server-standalone-2.46.0.jar -htmlSuite "*googlechrome C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "http://google.com" "D:\Selenium_2.0\Selenium_tests\Selenium_IDE&Selenium Builder\Selenium_start\test_suit.html" "D:\Selenium_2.0\Selenium_tests\Selenium_IDE&Selenium Builder\Selenium_start\results.html"
As answer I am see chrome browser with:
http://google.com/selenium-server/core/TestRunner.html?auto=true&multiWindow=true&defaultLogLevel=info&baseUrl=http%3A%2F%2Fgoogle.com&resultsUrl=../postResults&test=http%3A%2F%2Fgoogle.com%2Fselenium-server%2Ftests%2Ftest_suit.html
and
23:02:46.698 INFO - Launching a standalone Selenium Server
23:02:46.825 INFO - Java: Oracle Corporation 25.45-b02 23:02:46.826
INFO - OS: Windows 7 6.1 amd64 23:02:46.838 INFO - v2.46.0, with Core
v2.46.0. Built from revision 87c69e2 23:02:46.897 INFO - Driver class
not found:com.opera.core.systems.OperaDriver 23:02:46.897 INFO -
Driver provider com.opera.core.systems.OperaDriver is not registered
23:02:47.096 INFO - Launching Google Chrome...
with *firefox path/to/firefox.exe - same issue...
Can anyone help please?
Yesterday I found out that the reason was that my antivirus blocked connection to localhost including port 4444 - thats why I could not run test suit.

Selenium RC doesn't run the test suite by BAT file

I've tried to run my test suite by Selenium RC through a BAT file.
Actually it worked OK until yesterday morning and it stopped to run my test suite.
Probably because I've added user-extensions.js and since that I can't run my test suite by the selenium RC.
How can I add this script to my test suite?
I'm using Selenium IDE for to write my test cases, so I guess that make this more complex problem..
This is the console log of the BAT file during the execution:
>
C:\automation>cd C:\automation\screenshots\
C:\automation\screenshots>del *.png
Could Not Find C:\automation\screenshots\*.png
10:46:38.926 INFO - Launching a standalone server
10:46:39.098 INFO - Java: Oracle Corporation 25.25-b02
10:46:39.098 INFO - OS: Windows 8.1 6.3 amd64
10:46:39.113 INFO - v2.44.0, with Core v2.44.0. Built from revision 76d78cf
10:46:39.238 INFO - RemoteWebDriver instances should connect to: http://127.0.0.
1:4444/wd/hub
10:46:39.238 INFO - Version Jetty/5.1.x
10:46:39.238 INFO - Started HttpContext[/selenium-server,/selenium-server]
10:46:39.379 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler#6e3c1e
69
10:46:39.379 INFO - Started HttpContext[/wd,/wd]
10:46:39.379 INFO - Started HttpContext[/selenium-server/driver,/selenium-server
/driver]
10:46:39.379 INFO - Started HttpContext[/,/]
10:46:39.379 INFO - Started SocketListener on 0.0.0.0:4444
10:46:39.379 INFO - Started org.openqa.jetty.jetty.Server#b1bc7ed
jar:file:/C:/automation/selenium-server-standalone-2.44.0.jar!/customProfileDirC
USTFFCHROME
10:46:39.535 INFO - Preparing Firefox profile...
10:46:42.666 INFO - Launching Firefox...
10:46:44.245 INFO - Checking Resource aliases
This is the code line from the BAT file:
java -jar C:\automation\selenium-server-standalone-2.44.0.jar -htmlSuite "*firefox C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "https://www.mywebsite.com" "C:\automation\emailSanity.html" "C:\automation\testing_results.html" -port 4444
This is the screenshot of the actual result of the Selenium RC in action:
http://i57.tinypic.com/28u71jl.png
Please your help!
Thanks a lot.
Considering your app is at the splash screen, I can only assume that you forgot to put in your URL to initially open.
Since you are using RC, then your first statement of your test script should be:
selenium.open("http://example.com"); // where example.com is the app is your SUT.

Categories

Resources