1
votes

I have been testing web pages using Selenium webdriver in my local machine. However, I want to do this on Windows EC2 instance. I was able to identify that we can use Selenium grid2 on EC2 machines. So after launching and registering the nodes to the hub, I am facing the following errors when executing the JavaScript in eclipse.

I have used the following commands:

To start the hub: java -jar selenium-server-standalone-2.46.0.jar -role hub

To register node to hub: java -jar selenium-server-standalone-2.46.0.jar -role webdriver -hub http://:4444/grid/register/ -port 5555

My code is as follows:

package com.example.grid;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class seleniumgridclass {    
    //Remote webdriver instance
    public static RemoteWebDriver driver;
    public static void main(String[] args) throws MalformedURLException {

        DesiredCapabilities cap = new DesiredCapabilities().firefox();
        cap.setPlatform(Platform.VISTA);
        cap.setBrowserName("firefox");      
        driver = new RemoteWebDriver(new URL("http://<ip addr of node>:5555/wb/hub"),cap);      
        driver.navigate().to("http://www.google.com");      
        driver.findElementByName("q").sendKeys("execute automation");       
        driver.findElementByName("btnG").click();       
    }
}

I am facing the following error:

Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: <html>
<head>
<title>Error 403 Forbidden for Proxy</title>
</head>            
<body>
<h2>HTTP ERROR: 403</h2><pre>Forbidden for Proxy</pre>
<p>RequestURI=/wb/hub/session</p>
<p><i><small><a href="http://jetty.mortbay.org">Powered by Jetty://</a></small></i></p>                                               

</body>
</html>
Command duration or timeout: 218 milliseconds
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10'
System info: host: 'WIN-Y636DAAY2OH', ip: '10.0.1.226', os.name: 'Windows Server 2008', os.arch: 'x86', os.version: '6.0', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:155)
    at com.example.grid.seleniumgridclass.main(seleniumgridclass.java:26)

Kindly provide me guidelines in resolving Proxy Forbidden 403 Error.

1

1 Answers

1
votes

The issue is due to a typo in your code Please change

driver = new RemoteWebDriver(new URL("http://<ip addr of node>:5555/wb/hub"),cap);

to

driver = new RemoteWebDriver(new URL("http://<ip addr of node>:5555/wd/hub"),cap);

Note how I have changed wb to wd.

Also I believe you should be pointing at your Hub and NOT at the IP address of your node, because that kind of defeats the whole point of having the Hub and leverage its capability of routing your test to a particular node (you are directly hitting a node)