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

时间:2014-02-19 17:19:09

标签: java selenium

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

 InetAddress IP = InetAddress.getLocalHost();
 System.out.println(IP.toString());

如何捕获存储在执行冒烟测试的VM上的主机文件中的IP地址。

谢谢你, 哈密​​

2 个答案:

答案 0 :(得分:0)

我建议你使用专门的服务。有很多方法可以做到这一点,但我建议你使用其中一个内部服务器。

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

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

并让您的测试机器获取它。 (这就是我可以检测所有EC2节点的位置)

答案 1 :(得分:0)

读取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();
}