How start remote webdriver after regitering a node in a hub?

☆樱花仙子☆ 提交于 2019-12-06 12:11:25

问题


I'm trying to launch remoteWebdriver, for that I have created a hub progmatically then I have added a node on it. That is fine.The problem now when I execute:

Thread.currentThread().join();

The program stop executing, and if I remove this line I get error.

try{
      String strIP = "localhost";

        GridHubConfiguration config = new GridHubConfiguration();
        config.setTimeout(30000000);
        config.setPort(4444);
        config.setHost(strIP);

        Hub hub = new Hub(config);
        hub.start();
        RegistrationRequest req = new RegistrationRequest();
        req.setRole(GridRole.NODE);
        Map<String, Object> nodeConfiguration = new HashMap<>();
        nodeConfiguration.put(RegistrationRequest.PROXY_CLASS, DefaultRemoteProxy.class.getName());

        nodeConfiguration.put(RegistrationRequest.MAX_SESSION, 5);
        nodeConfiguration.put(RegistrationRequest.PORT, 5555);
        nodeConfiguration.put(RegistrationRequest.HOST, 4444);
        nodeConfiguration.put(RegistrationRequest.AUTO_REGISTER, true);
        nodeConfiguration.put(RegistrationRequest.REGISTER_CYCLE, 5000);
        nodeConfiguration.put(RegistrationRequest.HUB_HOST, "localhost");
        nodeConfiguration.put(RegistrationRequest.HUB_PORT, 4444);
        nodeConfiguration.put("remoteHost", "http://" + strIP + ":5555");
        nodeConfiguration.put("url", "http://" + strIP + ":5555");

        nodeConfiguration.put("role", "node");
        nodeConfiguration.put("hub", "http://localhost:4444/grid/register");
        URL remoteURL = new URL("http://" + strIP + ":5555");
        nodeConfiguration.put(RegistrationRequest.REMOTE_HOST, remoteURL.toExternalForm());

        req.setConfiguration(nodeConfiguration);
        DesiredCapabilities capabilities2 = DesiredCapabilities.chrome();
        capabilities2.setCapability("browserName", "chrome");
        capabilities2.setCapability("platform", "WINDOWS");
        capabilities2.setCapability("ensureCleanSession", "true");
        capabilities2.setCapability("maxInstances", 5);
        req.addDesiredCapability(capabilities2);
        SelfRegisteringRemote remote = new SelfRegisteringRemote(req);
        remote.setRemoteServer(new SeleniumServer(req.getConfiguration()));
        remote.startRemoteServer();
        remote.startRegistrationProcess();

            WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/register"),DesiredCapabilities.chrome());

        Thread.currentThread().join();

              String URL="http://localhost:4444/wd/hub";

        WebDriver driver = new RemoteWebDriver(new URL(URL),DesiredCapabilities.chrome());
        driver.get("https://www.youtube.com");  

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

来源:https://stackoverflow.com/questions/37006829/how-start-remote-webdriver-after-regitering-a-node-in-a-hub

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!