Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
selenium网格,以编程方式创建节点_Selenium_Grid_Registration_Nodes - Fatal编程技术网

selenium网格,以编程方式创建节点

selenium网格,以编程方式创建节点,selenium,grid,registration,nodes,Selenium,Grid,Registration,Nodes,我必须创建一个java应用程序来启动一个节点并将其连接到中心。到目前为止,当集线器和节点位于同一台计算机上时,我可以这样做,但只要我尝试连接到另一台计算机集线器上,注册过程就会永远挂起 我尝试了不同的方法。只需在代码中调用我的bat文件函数 String command = "java -jar selenium-server-standalone-2.26.0.jar -role node -hub http://192.168.0.11:4444/grid/register -port 44

我必须创建一个java应用程序来启动一个节点并将其连接到中心。到目前为止,当集线器和节点位于同一台计算机上时,我可以这样做,但只要我尝试连接到另一台计算机集线器上,注册过程就会永远挂起

我尝试了不同的方法。只需在代码中调用我的bat文件函数

String command = "java -jar selenium-server-standalone-2.26.0.jar -role node -hub http://192.168.0.11:4444/grid/register -port 4449 -Dwebdriver.chrome.driver=data\\driver\\chromedriver.exe -Dwebdriver.ie.driver=data\\driver\\IEDriverServer.exe -nodeConfig data\\configurations.json";

    try
    {
        pr = Runtime.getRuntime().exec(command);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
该命令在从bat文件调用时有效,但在代码中,它仅在节点和集线器位于同一台计算机上时有效

我还尝试使用注册请求

RegistrationRequest req = new RegistrationRequest();
                req.setRole(GridRole.NODE);

                Map<String, Object> nodeConfiguration = new HashMap<String,
                Object>();

                nodeConfiguration.put(RegistrationRequest.AUTO_REGISTER, true);
                nodeConfiguration.put(RegistrationRequest.HUB_HOST, "192.168.100.66");

                nodeConfiguration.put(RegistrationRequest.HUB_PORT, 4444);
                nodeConfiguration.put(RegistrationRequest.PORT, 5555);

                URL remoteURL = new URL("http://" + "192.168.100.66" + ":" + 5555);
                nodeConfiguration.put(RegistrationRequest.PROXY_CLASS, "org.openqa.grid.selenium.proxy.DefaultRemoteProxy");
                nodeConfiguration.put(RegistrationRequest.MAX_SESSION, 1);
                nodeConfiguration.put(RegistrationRequest.CLEAN_UP_CYCLE, 2000);
                nodeConfiguration.put(RegistrationRequest.REMOTE_HOST, remoteURL);
                nodeConfiguration.put(RegistrationRequest.MAX_INSTANCES, 1);

                req.setConfiguration(nodeConfiguration);

                remote = new SelfRegisteringRemote(req);
                remote.startRemoteServer();
                remote.startRegistrationProcess();
RegistrationRequest req=new RegistrationRequest();
请求setRole(GridRole.NODE);
Map nodeConfiguration=newhashmap();
nodeConfiguration.put(RegistrationRequest.AUTO_REGISTER,true);
nodeConfiguration.put(RegistrationRequest.HUB_HOST,“192.168.100.66”);
nodeConfiguration.put(RegistrationRequest.HUB_端口,4444);
nodeConfiguration.put(RegistrationRequest.PORT,5555);
URL remoteURL=新URL(“http://“+”192.168.100.66“+”:“+5555);
nodeConfiguration.put(RegistrationRequest.PROXY_类,“org.openqa.grid.selenium.PROXY.DefaultRemoteProxy”);
nodeConfiguration.put(RegistrationRequest.MAX_会话,1);
nodeConfiguration.put(RegistrationRequest.CLEAN\u\u CYCLE,2000年);
nodeConfiguration.put(RegistrationRequest.REMOTE\u主机,remoteURL);
nodeConfiguration.put(RegistrationRequest.MAX_实例,1);
请求设置配置(节点配置);
远程=新的自注册远程(req);
remote.startRemoteServer();
remote.startRegistrationProcess();
同样的结果是,当我尝试在另一个计算机集线器上运行时,它会在注册过程中切换。 信息-将节点注册到集线器:http://192.168.100.66:4444/grid/register


知道为什么吗?或者怎么做。

好。不确定是否适合您,但我想分享我在项目中使用的方法。 我有一台192.168.4.52 IP的远程机器,上面运行着selenium stanadlone服务器。 我在本地得到的所有selenium测试套件。 因此,要在远程机器上运行selenium测试套件,我只需在本地机器上的BaseSeleniumTest.java中使用以下设置:

....
@BeforeClass
    public static void firefoxSetUp() throws MalformedURLException {

          DesiredCapabilities capability = DesiredCapabilities.firefox();


        driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability);

        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        driver.manage().window().setSize(new Dimension(1920, 1080));
    }
    @Before
    public void homePageRefresh() throws IOException {

        driver.manage().deleteAllCookies();
        driver.get(propertyKeysLoader("login.base.url"));
    }


    @AfterClass
    public static void closeFirefox(){
        driver.quit();
    }
弦在哪里

driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability);
指示要在其上运行selenium测试的计算机的IP。 我正在使用以下命令启动远程计算机上的服务器: 运行测试套件之前,在cmd中使用java-jar selenium-server-standalone-2.26.0.jar。
希望对您有所帮助。

我解决了我的问题,解决起来非常简单。在我的代码中

URL remoteURL = new URL("http://" + "192.168.100.66" + ":" + 5555);

我只需要将ip地址替换为本地ip地址,而不是集线器ip地址,这样就可以了。这很奇怪,因为我很确定我从网上的某个地方获取了这段代码,他有一个ip变量,remoteURL和HUB_主机也是一样的

不幸的是,我无法访问我将要运行测试的计算机的ip,我真的需要一个java程序将节点连接到我的HUB。现在我能做的唯一方法是使用bat文件,但我真的希望它能以编程方式启动(这样我就可以将进程隐藏在系统托盘中)。到目前为止,我只能在同一台计算机上创建集线器和节点时才能做到这一点。我解决了我的问题,解决起来非常简单。在我的代码中,我有URL remoteURL=newurl(“http://“+”192.168.100.66“+”:“+5555”);我只需要将ip地址替换为本地ip地址,而不是集线器ip地址,这样就可以了。这很奇怪,因为我很确定我从网上的某个地方得到了这段代码,他有一个ip变量,b也是一样