Example usage for org.openqa.selenium.net NetworkUtils getIpOfLoopBackIp4

List of usage examples for org.openqa.selenium.net NetworkUtils getIpOfLoopBackIp4

Introduction

In this page you can find the example usage for org.openqa.selenium.net NetworkUtils getIpOfLoopBackIp4.

Prototype

public String getIpOfLoopBackIp4() 

Source Link

Usage

From source file:com.opera.core.systems.environment.webserver.WebbitAppServer.java

License:Apache License

/**
 * Gets the hostname of this machine.  By default it will attempt to retrieve the non-loopback
 * address so that remote browsers can connect to the web server, but in the event that this
 * fails, we will fall back to the internal loopback address.
 *
 * The hostname can be overriden using the {@link #HOSTNAME_FOR_TEST_ENV_NAME} environmental
 * variable./*from   www .jav a  2 s  .c  o  m*/
 *
 * @return hostname to use for web server
 */
private static String detectHostname() {
    String hostnameFromProperty = System.getenv(HOSTNAME_FOR_TEST_ENV_NAME);

    if (hostnameFromProperty != null) {
        return hostnameFromProperty;
    }

    NetworkUtils networkUtils = new NetworkUtils();
    try {
        return networkUtils.getNonLoopbackAddressOfThisMachine();
    } catch (WebDriverException e) {
        return networkUtils.getIpOfLoopBackIp4();
    }
}