public ContainerCreationStatus startDockerSeleniumContainer(final TimeZone timeZone, final Dimension screenSize) { TimeZone effectiveTimeZone = ObjectUtils.defaultIfNull(timeZone, DEFAULT_TZ); Dimension effectiveScreenSize = ObjectUtils.defaultIfNull(screenSize, DEFAULT_SCREEN_SIZE); NetworkUtils networkUtils = new NetworkUtils(); String hostIpAddress = networkUtils.getIp4NonLoopbackAddressOfThisMachine().getHostAddress(); String nodePolling = String.valueOf(RandomUtils.nextInt(90, 120) * 1000); String nodeRegisterCycle = String.valueOf(RandomUtils.nextInt(60, 90) * 1000); String seleniumNodeParams = getSeleniumNodeParameters(); String latestImage = getLatestDownloadedImage(getDockerSeleniumImageName()); int containerPort = LOWER_PORT_BOUNDARY; if (containerClient instanceof DockerContainerClient) { containerPort = findFreePortInRange(); } Map<String, String> envVars = buildEnvVars(effectiveTimeZone, effectiveScreenSize, hostIpAddress, sendAnonymousUsageInfo, nodePolling, nodeRegisterCycle, seleniumNodeParams, containerPort); return containerClient.createContainer(getContainerName(), latestImage, envVars, String.valueOf(containerPort)); }
private URL getURLofExistingLocalServer() { Socket socket = new Socket(); try { socket.bind(new InetSocketAddress("localhost", SocketLock.DEFAULT_PORT)); return null; //Able to connect on default port (Assuming that default FF driver is not running) } catch (IOException e) { }finally{ try { socket.close(); } catch (IOException e) { } } try { return new URL("http",new NetworkUtils().obtainLoopbackIp4Address(), SocketLock.DEFAULT_PORT,"/hub"); } catch (MalformedURLException e) { throw new WebDriverException(e); } }
synchronized LocalHub getLocalServerComponent() { if (instance == null) { instance = new LocalHub(); instance.setHost(new NetworkUtils().getIpOfLoopBackIp4()); // Choose a random port for local hub. int hubPort = PortProber.findFreePort(); instance.setPort(hubPort); // Set ConfigProperty.SELENIUM_PORT so that the local nodes can register to it. Config.setConfigProperty(ConfigProperty.SELENIUM_PORT, Integer.toString(hubPort)); LauncherOptions launcherOptions = new LauncherConfiguration() .setFileDownloadCheckTimeStampOnInvocation(false).setFileDownloadCleanupOnInvocation(false); instance.setLauncher(new ThreadedLauncher(new String[] { "-role", "hub", "-port", String.valueOf(instance.getPort()), "-host", instance.getHost() }, launcherOptions)); } return instance; }
synchronized LocalNode getLocalServerComponent() { if (instance == null) { instance = new LocalNode(); instance.setHost(new NetworkUtils().getIpOfLoopBackIp4()); instance.setPort(PortProber.findFreePort()); String hubPort = Config.getConfigProperty(ConfigProperty.SELENIUM_PORT); String hub = String.format("http://%s:%s/grid/register", instance.getHost(), hubPort); setLegacyFFBootupIfRequested(); LauncherOptions launcherOptions = new LauncherConfiguration() .setFileDownloadCheckTimeStampOnInvocation(false).setFileDownloadCleanupOnInvocation(false); List<String> downloadList = determineListOfDownloadsToProcess(); instance.setLauncher(new ThreadedLauncher(new String[] { "-role", "node", "-port", String.valueOf(instance.getPort()), "-proxy", DefaultRemoteProxy.class.getName(), "-host", instance.getHost(), "-hub", hub }, launcherOptions, downloadList)); } return instance; }
synchronized LocalIOSNode getLocalServerComponent() { if (instance == null) { instance = new LocalIOSNode(); instance.setHost(new NetworkUtils().getIpOfLoopBackIp4()); instance.setPort(PortProber.findFreePort()); String hubPort = Config.getConfigProperty(ConfigProperty.SELENIUM_PORT); String hub = String.format("http://%s:%s/grid/register", instance.getHost(), hubPort); String[] folder = new String[] { "", "" }; String autFolder = Config.getConfigProperty(ConfigProperty.MOBILE_APP_FOLDER); if (StringUtils.isNotEmpty(autFolder)) { folder = new String[] { "-folder", autFolder }; } ProcessLauncherOptions processOptions = new ProcessLauncherConfiguration().setContinuouslyRestart(false) .setIncludeJarsInPresentWorkingDir(false).setIncludeParentProcessClassPath(false) .setIncludeJavaSystemProperties(false).setFileDownloadCheckTimeStampOnInvocation(false) .setFileDownloadCleanupOnInvocation(false); instance.setLauncher(new IOSDriverJarSpawner(new String[] { "-port", String.valueOf(instance.getPort()), "-host", instance.getHost(), "-hub", hub, folder[0], folder[1], "-sessionTimeout", Config.getConfigProperty(ConfigProperty.MOBILE_DRIVER_SESSION_TIMEOUT) }, processOptions)); } return instance; }
instance = new LocalSelendroidNode(); instance.setHost(new NetworkUtils().getIpOfLoopBackIp4()); instance.setPort(PortProber.findFreePort());