Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.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
Java 如何捕获执行Webdriver测试的主机IP地址?_Java_Selenium - Fatal编程技术网

Java 如何捕获执行Webdriver测试的主机IP地址?

Java 如何捕获执行Webdriver测试的主机IP地址?,java,selenium,Java,Selenium,我的Junit4/Java webdriver冒烟测试在FF23.0上windows 7上的VM上运行。我可以使用以下方式打印VM机器的主机名/URL: InetAddress IP = InetAddress.getLocalHost(); System.out.println(IP.toString()); 在执行烟雾测试的VM上,如何捕获主机文件中存储的IP地址 谢谢,, 哈米德我敦促您使用专门的服务。有很多方法可以做到这一点,但我建议您使用一个内部服务器(如果您有) 一个简单的1行

我的Junit4/Java webdriver冒烟测试在FF23.0上windows 7上的VM上运行。我可以使用以下方式打印VM机器的主机名/URL:

 InetAddress IP = InetAddress.getLocalHost();
 System.out.println(IP.toString());
在执行烟雾测试的VM上,如何捕获主机文件中存储的IP地址

谢谢,,
哈米德

我敦促您使用专门的服务。有很多方法可以做到这一点,但我建议您使用一个内部服务器(如果您有)

一个简单的1行php脚本可以工作:

<?php echo $_SERVER['remote_addr']; ?>

让你的测试机去拿。这就是我如何检测我的所有EC2节点的位置的方法。读入hosts文件并在字符串中找到IP地址

private static final String HOSTS_FILE_LOCATION = "C:\\Windows\\System32\\drivers\\etc\\hosts";


static String readFile(String path, Charset encoding) 
throws IOException 
{
    byte[] encoded = Files.readAllBytes(Paths.get(path));
    return encoding.decode(ByteBuffer.wrap(encoded)).toString();
}