Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

selenium - 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:UsersAdministrator>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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...