我们可以用IIS运行Selenium WebDriver测试用例,而不是Visual Studio开发服务器

时间:2012-07-25 16:09:39

标签: asp.net iis selenium webdriver selenium-webdriver

我正在使用Selenium 2 WebDriver。而不是UnitTest项目,我从网站发起它,原因如下:

  1. 它应该每24小时自动运行一次。我使用System.Threading编写了一些调度代码。
  2. 为客户提供一些用户界面,以便在需要时在中间运行。
  3. 每次运行时都会发送一封电子邮件作为测试结果的一部分。
  4. 我的目标网站是:http://www.vroomvroomvroom.com.au

    我创建了一个包含所有Selenium代码的类。我在default.aspx的页面加载时使用System.Threading调用该类。

    当我通过按F5或Ctrl + F5从Visual Studio运行default.aspx时工作正常,即使用Visual Studio开发服务器,例如http://localhost:3251/default.aspx

    但是,当我尝试直接从IIS运行它时,使用默认端口(80),例如http://localhost/seleniumTest/default.aspx,然后因以下观察/错误而失败:

    1. 它会延长Selenium代码,但不显示broswer。
    2. 使用No response from server for url http://localhost:7094/hub/session/4bbe4b0c-aeee-4fa3-8bc0-aae47c6869af/element
    3. 执行某些步骤后失败

      我想要实现的目标是可能的。

      仅供参考:如果需要进一步的详细信息,请与我们联系。

1 个答案:

答案 0 :(得分:8)

我自己设法找到了解决方案。

基本上,必须使用RemoteWebDriver而不是FirefoxDriver。 步骤进行:

  1. 将FirefoxDriver的初始化更改为RemoteWebDriver:
  2. 改变
    IWebDriver driver = new FirefoxDriver();
    

    DesiredCapabilities capability = DesiredCapabilities.Firefox();
    Uri url = new Uri("http://REMOTE_IP:4545/wd/hub");
    IWebDriver driver = new RemoteWebDriver(url, capability);
    

    2。下载Selenium Standalone服务器并使用〜

    通过命令提示符启动它
    java -jar E:\Software\selenium-server-standalone-2.24.1.jar -interactive -port 4545
    

    这种方法有两个好处:

    1. 可以使用本地IIS运行测试。
    2. 可以远程运行测试。请参阅Selenium RC文档。可以使用

      远程查看截图

      REMOTE_IP:4545 / WD /集线器/静态/资源/ hub.html

    3. 我正在考虑修改其中使用的hub.html和client.js文件的代码,以提供更好的远程感觉。

      我希望这对其他人也有用。

      仅供参考:

      1. IP地址REMOTE_IP可以更改为任何实时IP地址或localhost。在启动页面请求时使用上述端口。
      2. 可以在测试中安装Standalone Server的启动/停止代码,以便通过批处理文件自动启动/停止。
      3. 不关闭命令提示符,使服务器保持运行。
相关问题