【问题标题】:Can I run Selenium tests when hosts file does not have localhost alias?当 hosts 文件没有 localhost 别名时,我可以运行 Selenium 测试吗?
【发布时间】:2014-10-08 16:43:31
【问题描述】:

在 Firefox 中使用 Selenium WebDriver 开始测试运行时出现“错误请求”异常。我将此问题追溯到主机配置文件(使用 Windows 7)。我机器上的 hosts 文件有这一行(当然,稍作编辑):

127.0.0.1 alias.set.by.security

这应该通过将 localhost 添加到该行来解决。问题是,我无法更改此文件,我们有一个依赖于此并覆盖我的权利的安全工具。 我发现了一个与此相关的问题,https://code.google.com/p/selenium/issues/detail?id=3280

但是,他们对如何使用修复程序有点神秘。有谁知道如何修复我的代码以使其正常工作(它无法正常工作)?

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost");
driver = new FirefoxDriver(profile);

【问题讨论】:

  • 您使用哪个版本的 webdriver?即使我的主机文件条目没有 127.0.0.1 的 localhost 值,我在运行 selenium 测试时也没有看到任何问题。
  • 最新,2.43.1。现在使用我放在下面的代码可以正常工作

标签: java selenium selenium-webdriver automated-tests


【解决方案1】:

没关系,这……很明显

profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "alias.set.by.security");

【讨论】:

    猜你喜欢
    • 2018-07-08
    • 1970-01-01
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 2016-11-03
    • 2020-12-16
    相关资源
    最近更新 更多