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)); }
port = port == 0 ? PortProber.findFreePort() : port;
private void ping(long time, TimeUnit timeUnit) throws UrlChecker.TimeoutException, MalformedURLException { URL status = new URL(url.toString() + "/status"); new UrlChecker().waitUntilAvailable(time, timeUnit, status); }
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; }
private void stop() throws IOException { try { new UrlChecker().waitUntilUnavailable(3, SECONDS, new URL(url + "/shutdown")); process.destroy(); } catch (TimeoutException e) { throw new WebDriverException("Driver failed to stop.", e); } } }
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); } }
@Override protected void waitUntilAvailable() throws MalformedURLException { PortProber.waitForPortUp(getUrl().getPort(), 20, SECONDS); }
Integer getDefaultValue() { return PortProber.findFreePort(); }
private void ping(long time, TimeUnit timeUnit) throws UrlChecker.TimeoutException, MalformedURLException { URL status = new URL(url.toString() + "/status"); new UrlChecker().waitUntilAvailable(time, timeUnit, status); }
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; }
private void stop() throws IOException { try { new UrlChecker().waitUntilUnavailable(3, SECONDS, new URL(url + "/shutdown")); process.destroy(); } catch (TimeoutException e) { throw new WebDriverException("Driver failed to stop.", e); } } }
public BMPCLocalManager(String executablePath, String logPath) { this(executablePath, logPath, PortProber.findFreePort()); }
@Override protected void waitUntilAvailable() throws MalformedURLException { try { // Use a longer timeout, because 45 seconds was the default timeout in the predecessor to // XpiDriverService. This has to wait for Firefox to start, not just a service, and some users // may be running tests on really slow machines. URL status = new URL(getUrl(port).toString() + "/status"); new UrlChecker().waitUntilAvailable(45, SECONDS, status); } catch (UrlChecker.TimeoutException e) { throw new WebDriverException("Timed out waiting 45 seconds for Firefox to start.", e); } }
/** * See {@link com.github.detro.browsermobproxyclient.BMPCLocalLauncher#launch(int)} */ public static BMPCLocalManager launchOnRandomPort() { return launch(PortProber.findFreePort()); }
private void start() throws IOException { try { process.executeAsync(); new UrlChecker().waitUntilAvailable(20, SECONDS, new URL(url + "/status")); } catch (TimeoutException e) { process.checkForError(); throw new WebDriverException("Driver failed to start.", e); } }
Integer sanitize(Object value) { checkNotNull(value); int port = Integer.valueOf(String.valueOf(value)); // 0 = random, -1 = Opera default (7001) (for use with Opera < 11.60) if (port == SERVER_RANDOM_PORT_IDENTIFIER) { port = PortProber.findFreePort(); } else if (port == SERVER_DEFAULT_PORT_IDENTIFIER) { port = SERVER_DEFAULT_PORT; } return port; } },
private void start() throws IOException { try { process.executeAsync(); new UrlChecker().waitUntilAvailable(20, SECONDS, new URL(url + "/status")); } catch (TimeoutException e) { process.checkForError(); throw new WebDriverException("Driver failed to start.", e); } }
protected PhantomJSDriver createNewPhantomJsDriver(File phantomJsExe, Capabilities desiredCapabilities) { try { URL url = new URL("http://localhost:" + PortProber.findFreePort()); return new PhantomJSDriver(phantomJsExe, url, new File("target/phantomjs.log"), desiredCapabilities); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
protected PhantomJSDriver createNewPhantomJsDriver(File phantomJsExe, Capabilities desiredCapabilities) { try { URL url = new URL("http://localhost:" + PortProber.findFreePort()); return new PhantomJSDriver(phantomJsExe, url, new File("target/phantomjs.log"), desiredCapabilities); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
/** * Checks out the next available unused port. Callers should send the returned port * back to {@link #releaseUnusedPort(int)} when it's no longer being used. * * @throws NoSuchElementException if no unused port is available. */ public synchronized int checkOutUnusedPort() { if (availablePorts == null) { return PortProber.findFreePort(); } else if (availablePorts.isEmpty()) { // All available ports are checked out. throw new NoSuchElementException("No unused ports are available"); } return availablePorts.pop(); }