Search in sources :

Example 1 with NetworkUtils

use of org.openqa.selenium.net.NetworkUtils in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxy method startDockerSeleniumContainer.

@VisibleForTesting
public boolean startDockerSeleniumContainer(TimeZone timeZone, Dimension screenSize, boolean forceCreation) {
    NetworkUtils networkUtils = new NetworkUtils();
    String hostIpAddress = networkUtils.getIp4NonLoopbackAddressOfThisMachine().getHostAddress();
    String nodePolling = String.valueOf(RandomUtils.nextInt(90, 120) * 1000);
    String nodeRegisterCycle = String.valueOf(RandomUtils.nextInt(15, 25) * 1000);
    String seleniumNodeParams = getSeleniumNodeParameters();
    String latestImage = getLatestDownloadedImage(getDockerSeleniumImageName());
    int attempts = 0;
    int maxAttempts = 2;
    while (attempts < maxAttempts) {
        attempts++;
        if (forceCreation || validateAmountOfDockerSeleniumContainers()) {
            final int nodePort = findFreePortInRange(LOWER_PORT_BOUNDARY, UPPER_PORT_BOUNDARY);
            Map<String, String> envVars = buildEnvVars(timeZone, screenSize, hostIpAddress, sendAnonymousUsageInfo, nodePolling, nodeRegisterCycle, nodePort, seleniumNodeParams);
            ContainerCreationStatus creationStatus = containerClient.createContainer(getContainerName(), latestImage, envVars, String.valueOf(nodePort));
            if (creationStatus.isCreated() && checkContainerStatus(creationStatus)) {
                return true;
            } else {
                LOGGER.debug(String.format("%sContainer creation failed, retrying...", getId()));
            }
        } else {
            LOGGER.info(String.format("%sNo container was created, will try again in a moment...", getId()));
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                LOGGER.debug("Exception while making a pause during container creation.", e);
            }
        }
    }
    LOGGER.info(String.format("%sNo container was created after 3 attempts, will wait until request is " + "processed again...", getId()));
    return false;
}
Also used : ContainerCreationStatus(de.zalando.ep.zalenium.container.ContainerCreationStatus) NetworkUtils(org.openqa.selenium.net.NetworkUtils) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with NetworkUtils

use of org.openqa.selenium.net.NetworkUtils in project zalenium by zalando.

the class ParallelIT method checkIframeLinksForLivePreviewWithMachineIp.

@Test(dataProvider = "browsersAndPlatformsForLivePreview")
public void checkIframeLinksForLivePreviewWithMachineIp(String browserType, Platform platform) {
    NetworkUtils networkUtils = new NetworkUtils();
    String hostIpAddress = networkUtils.getIp4NonLoopbackAddressOfThisMachine().getHostAddress();
    // Go to the homepage
    getWebDriver().get(String.format("http://%s:%s/grid/admin/live", hostIpAddress, ZALENIUM_PORT));
    // Get the page source to get the iFrame links
    String pageSource = getWebDriver().getPageSource();
    // Assert that the href for the iFrame has the vnc links
    assertThat(pageSource, containsString("view_only=true"));
    assertThat(pageSource, containsString("view_only=false"));
}
Also used : NetworkUtils(org.openqa.selenium.net.NetworkUtils) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.testng.annotations.Test)

Aggregations

NetworkUtils (org.openqa.selenium.net.NetworkUtils)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ContainerCreationStatus (de.zalando.ep.zalenium.container.ContainerCreationStatus)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.testng.annotations.Test)1