Unable to launch IE browser using Selenium Webdriver - selenium

I am trying invoke IE browser using Selenium Webdriver and have used the below code to invoke:
System.setProperty("webdriver.ie.driver", driverPath+"IEDriverServer.exe");
driver = new InternetExplorerDriver();
But while execution I am getting error as below:
Started InternetExplorerDriver server (64-bit)
3.4.0.0
Listening on port 3210
Only local connections are allowed
Dec 12, 2017 6:29:04 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Dec 12, 2017 6:29:07 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
Dec 12, 2017 6:29:07 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to straight W3C remote end connection
Exception in thread "pool-1-thread-1" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}], required capabilities = Capabilities [{}]
Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc', time: '2014-06-03 10:52:47'
System info: host: 'PCXXXXXX', ip: 'XX.XXX.XXX.XX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_141'
Driver info: driver.version: InternetExplorerDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:91)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:227)
at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:180)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:172)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:144)
at com.cognizant.framework.selenium.WebDriverFactory.getWebDriver(WebDriverFactory.java:76)
at supportlibraries.DriverScript.initializeWebDriver(DriverScript.java:301)
at supportlibraries.DriverScript.driveTestExecution(DriverScript.java:155)
at allocator.ParallelRunner.run(ParallelRunner.java:48)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Please let me know if there is some additional settings that I have missed. System IE browser version: 11

Open Internet Options, select 'Security' Tab. Check that 'EACH' zone (Internet, Local Intranet, Trusted Sites, Restricted Sites) has 'Enable Protected Mode' enabled. This will likely require an IE restart.

You might be missing "\" in the path
try
System.setProperty("webdriver.ie.driver", driverPath+"\IEDriverServer.exe");
driver = new InternetExplorerDriver();

Try with the below options
Change the Web driver opened IE browser zoom to 100%
Navigate to Internet Options -> Security and unselect Enable protect mode for all the zones

Related

Katalon Studio fails to start application in Windows object spy

I use Katalon Studio 7.0.4 and Windows Application Driver v1.2 RC and allowed port 4723 on firewall. I used PuTTY for testing. Connection is successful, application is shown in spy tool, but got errors when try to use some methods(e.g.:click, getText). I see following errors in logs.
On server side:
==========================================
GET /session/3A8AB5F8-E6B3-4FB1-9C14-E48B8F4F5C4D/screenshot HTTP/1.1
Accept-Encoding: gzip
Cache-Control: no-cache
Connection: Keep-Alive
Host: myip:4723
User-Agent: selenium/3.141.59 (java windows)
HTTP/1.1 500 Internal Error
Content-Length: 133
Content-Type: application/json
{"status":13,"value":{"error":"unknown error","message":"An unknown error occurred in the remote end while processing the command."}}
==========================================
GET /session/3A8AB5F8-E6B3-4FB1-9C14-E48B8F4F5C4D/window_handle HTTP/1.1
Accept-Encoding: gzip
Cache-Control: no-cache
Connection: Keep-Alive
Host: myip:4723
User-Agent: selenium/3.141.59 (java windows)
HTTP/1.1 200 OK
Content-Length: 84
Content-Type: application/json
{"sessionId":"3A8AB5F8-E6B3-4FB1-9C14-E48B8F4F5C4D","status":0,"value":"0x000A09F4"}
On client side:
org.openqa.selenium.WebDriverException: An unknown error occurred in
the remote end while processing the command. (WARNING: The server did
not provide any stacktrace information) Command duration or timeout: 0
milliseconds Build info: version: ‘3.141.59’, revision: ‘e82be7d358’,
time: ‘2018-11-14T08:25:53’ System info: host: ‘LAPTOP’, ip:
‘192.168.56.1’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version:
‘10.0’, java.version: ‘1.8.0_181’ Driver info:
io.appium.java_client.windows.WindowsDriver Capabilities {app:
C:\Users\user101\Downloads…, javascriptEnabled: true, platform:
WINDOWS, platformName: WINDOWS} Session ID:
3A8AB5F8-E6B3-4FB1-9C14-E48B8F4F5C4D at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at
org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at
org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at
org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at
io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at
io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:46)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at
io.appium.java_client.windows.WindowsDriver.execute(WindowsDriver.java:1)
at
org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:295)
at
com.kms.katalon.composer.windows.spy.WindowsInspectorController.captureScreenshot(WindowsInspectorController.java:82)
at
com.kms.katalon.composer.windows.dialog.WindowsRecorderDialog$3.captureImage(WindowsRecorderDialog.java:653)
at
com.kms.katalon.composer.windows.dialog.WindowsRecorderDialog$3.run(WindowsRecorderDialog.java:620)
at
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
In Katalon Studio:

Selenium Grid: URL in RemoteWebDriver(url, caps)

I am trying to run a test suite using selenium grid, and I was able to establish hub and one node. After this, when I am initializing the RemoteWebdiver(url, caps) call, it is throwing an exception:
org.openqa.selenium.WebDriverException: Error forwarding the new session Error forwarding the request Failed to connect to <IP>:<PORT>
Also when I ping to that "Node_IP", it shows 100% loss. But my grid console shows it is connected. I have added inbound and outbound rules for the port: 4444 through firewall. telnet command also fails for "Node_IP" and "PORT" which is "4444".
I can execute the tests in my local when I pass the URL as : http://localhost:4444/wd/hub
/**** Added Description *****/
hubConfig: java -jar selenium-server-standalone-3.13.0.jar -role hub -host "Host_IP"
nodeConfig: java -Dwebdriver.chrome.driver="chrome_driver_location_on_node" -jar selenium-server-standalone-3.13.0.jar -role node -hub http://"host_ip":4444/grid/register -browser
"browserName=chrome,platform=WINDOWS,version=67.0,maxInstances=5"
Same goes for FireFox and IE.
Code works fine as I am able to execute as a localhost.
The stacktrace is as:
FYI: "Node_PORT" is a random port. I have not assigned it. I also tried it by assigning a port but it didn't work too.
org.openqa.selenium.WebDriverException: Error forwarding the new session Error forwarding the request Failed to connect to /<Node_IP>:<Node_PORT>
Command duration or timeout: 51.98 seconds
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z'
System info: host: '<System_Info>', ip: <Hub_IP>, os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_151'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:143)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.openqa.grid.common.exception.GridException: Error forwarding the new session Error forwarding the request Failed to connect to /<Node_IP>:<Node_PORT>
at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:118)
at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:86)
at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:860)
at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:535)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.seleniumhq.jetty9.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190)
at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473)
at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.seleniumhq.jetty9.server.Server.handle(Server.java:530)
at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:347)
at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:256)
at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:102)
at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
at org.seleniumhq.jetty9.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:382)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:708)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:626)
at java.lang.Thread.run(Unknown Source)
I got the solution for my own query and it was a very simple one which I was aware of earlier but didn't gave any second thoughts for that.
Basically, I had to start the node with a specific port and I whitelisted that port number from the security groups.
Thanks again everyone who took an effort for answering. Hope this helps those who are stuck in a similar situation.

Safari automation through Jenkins

I am trying to run my selenium automation tests on safari but I am facing an issue running through Jenkins.
I have a osX env running on a vm and running the tests locally everything is working fine. Its when I try to run these tests through Jenkins that I run into issues. They run but they are unable to open safari.
Im not very familiar with macs so dont really know whats causing the issue. The vm is a slave of jenkins and everything seems ok there.
Thanks for any help.
The error i am seeing is as follows
System info: host: 'Test-MacBook-Pro.local', ip:
'fe80:0:0:0:1c75:5215:5f4d:cef2%en0', os.name: 'Mac OS X', os.arch:
'x86_64', os.version: '10.13.4', java.version: '1.8.0_171'
Driver info: driver.version: SafariDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:60)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:40)
at extra.StartupTestCase.cleanUpLogin(StartupTestCase.java:292)
at extra.StartupTestCase.beforeSuite(StartupTestCase.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:326)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.TestNG.privateMain(TestNG.java:1442)
at org.testng.TestNG.main(TestNG.java:1411)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:16788 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:139)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:87)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:343)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
... 26 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
... 41 more
Looking at the error log it seems you haven't set Safari driver for Selenium.
Find out the latest safari driver for Selenium and set it's path in your code.
Running selenium code from Jenkins:
I would suggest you to use a jenkins node and trigger your java code on node.
Also you may like to use Gradle/Maven/TestNG as trigger and build.
I have faced the same error a couple of times. It seems to be a problem with the way you connect to jenkins. When you define a node in jenkins there is the option Launch method. Depending on the launch method you use behavour changes a little bit.
Probably you are using the Launch agents via SSH, which allows you to permanently connect certain machine with certain Node. However, this method runs processes in the background. For some reason, safari does not work with background processes.
Another method is the Launch agent via Java Web Start. With this option, each time you restart your machine you will have to manually connect it to the jenkins node through a Java applet. However with this method processes are launched on the front and lets you launch safari from jenkins.
I have not found a way to connect through SSH and launch safari correctly, nor I have seen any other solution.
Hope this is your issue!

WebDriverException: Error forwarding the new session Error forwarding the request Connect to my_ip:5555 [/my_ip] failed: Connection timed out

I installed selenium node on AWS windows and started it. And I setup Jenkins, git, Seleniuim hub on AWS Linux. When i'm building app on Jenkins, selenium hub is trying to connect to selenium node of AWS windows with private IP address. And i'm getting following exception:
org.openqa.selenium.WebDriverException:
Error forwarding the new session Error forwarding the request Connect to windows_private_ip:5555 [/windows_private_ip] failed: Connection timed out (Connection timed out)
Command duration or timeout: 190.25 seconds
Build info: version: '3.5.1', revision: '9c21bb67ef', time: '2017-08-17T15:26:08.955Z'
System info: host: 'some_host_name', ip: 'some_ip', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.76-3.78.amzn1.x86_64', java.version: '1.8.0_151'
Driver info: driver.version: RemoteWebDriver
Caused by: org.openqa.grid.common.exception.GridException: Error forwarding the new session Error forwarding the request Connect to windows_private_ip:5555 [/windows_private_ip] failed: Connection timed out (Connection timed out)
Grid Node command:
C:\Users\Administrator>java -Dwebdriver.chrome.driver=./drivers/windows-driver/chromedriver.exe -jar C:\\Users\\Administrator\\Desktop\\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register
My code is:
if (browser.equalsIgnoreCase("FF")) {
System.setProperty("webdriver.gecko.driver", "drivers/windows-driver/geckodriver.exe");
DesiredCapabilities cap = DesiredCapabilities.firefox();
// Set the platform where we want to run our test- we can use
// MAC and Linux and other platforms as well
cap.setPlatform(Platform.ANY);
cap.setCapability("gecko", true);
// Here you can use hub address, hub will take the
// responsibility to execute the test on respective node
URL url = new URL("http://hub_public_ip:4444/wd/hub");
// Create driver with hub address and capability
gbb = PageFactory.initElements(new RemoteWebDriver(url, cap), GuruBase.class);
} else if (browser.equalsIgnoreCase("IE")) {
System.setProperty("webdriver.ie.driver", "drivers/windows-driver/IEDriverServer.exe");
gbb = PageFactory.initElements(new InternetExplorerDriver(), GuruBase.class);
} else if (browser.equalsIgnoreCase("GC")) {
System.setProperty("webdriver.chrome.driver", "drivers/windows-driver/chromedriver.exe");
ChromeOptions cho = new ChromeOptions();
cho.addArguments("disabled-extensions");
cho.addArguments("--start-maximized");
gbb = PageFactory.initElements(new ChromeDriver(cho), GuruBase.class);
}
else if (browser.equalsIgnoreCase("html")) {
gbb = PageFactory.initElements(new HtmlUnitDriver(true), GuruBase.class);
}
I'm running selenium hub on Jenkins.
A quick solution will be to change :
java -Dwebdriver.gecko.driver=./drivers/windows-driver/chromedriver.exe -jar C:\\Users\\Administrator\\Desktop\\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register
As you are using Dwebdriver.gecko.driver with chromedriver.exe
To either :
Use GeckoDriver :
java -Dwebdriver.gecko.driver=./drivers/windows-driver/geckodriver.exe -jar C:\\Users\\Administrator\\Desktop\\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register
Use Chromedriver :
java -Dwebdriver.chrome.driver=./drivers/windows-driver/chromedriver.exe -jar C:\\Users\\Administrator\\Desktop\\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register
Additionally, you need to check your if() loop as you have a mixed up representation of Windows and Linux styles in System.setProperty() line as follows :
GeckoDriver :
System.setProperty("webdriver.gecko.driver", "drivers/windows-driver/geckodriver.exe");
ChromeDriver :
System.setProperty("webdriver.chrome.driver", "drivers/windows-driver/chromedriver");
IEDriverServer :
System.setProperty("webdriver.ie.driver", "drivers/windows-driver/IEDriverServer.exe");
Note : On Windows Systems you need to mention the extension .exe part e.g. geckodriver.exe while on Linux Systems you need strip off the extension .exe part e.g. chromedriver
This probably caused by your ip not matched. I met the same error and I found that there are two IPv4 address for my machine. One is Eather net and another is WLAN.
Steps:
Disconnect the Wi-Fi.
Use command : ipconfig to check my IPv4 address (there's only one IP there).
With one IP only it should create session correctly.
Perhaps you are using your office computer to make transaction between your node and your hub.
to some extent, you can push your code from office computer <=> github <=> AWS EC2 console.
but registering it as a node / hub and trying to execute the test case may not be possible.
please try with a server in same environment.

Browser launch fails for second time through remote webdriver

I'm running several tests via selenium remote webdriver on remote machine. For each test i will be rebooting the VM and then restart the browser. For the first case browser launch is successful but on other iterations browser launch fails. However if i start another selenium server with different port, then second test gets executed with the new port.
Not sure why the first port couldn't be reused for the second time ?
Error is showing as below:-
ERROR in invoking Selenium Commands:Could not start a new session.
Possible causes are invalid address of the remote server or browser
start-up failure.
System info: host: 'N/A', ip: 'N/A', os.name: 'Linux', os.arch:
'i386', java.version:
'1.8.0_31'
Driver info: driver.version: RemoteWebDriver
capabilities.setCapability("platformVersion", "40.0.2");
capabilities.setCapability("platformName", "WINDOWS");
capabilities.setCapability("browserName", "firefox");
driver= new RemoteWebDriver(new URL("http://"+ipaddress+":"+portNumber+"/wd/hub"), capabilities);
Selenium server launched in VM as java -jar selenium-server.2.42.2.jar