我们可以使用 IIS 而不是 Visual Studio 开发服务器运行 Selenium WebDriver 测试用例吗 [英] Can we run Selenium WebDriver Test case with IIS, instead of Visual Studio Development server

查看:33
本文介绍了我们可以使用 IIS 而不是 Visual Studio 开发服务器运行 Selenium WebDriver 测试用例吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Selenium 2 WebDriver.由于以下原因,我从网站启动它而不是 UnitTest 项目:

I am working with Selenium 2 WebDriver. Instead of UnitTest project, i initiate it from website because of following reasons:

  1. 它应该每 24 小时自动运行一次.我已经使用 System.Threading 编写了一些调度代码.
  2. 向客户提供一些用户界面,以便在他们需要时在中间运行.
  3. 每次运行时都会发送一封电子邮件作为测试结果的一部分.

我的目标网站是:http://www.vroomvroomvroom.com.au

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

I have created a Class which has all the Selenium Code. I call that Class using System.Threading upon page load of default.aspx.

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

It works fine when i run default.aspx from visual studio by pressing F5 OR Ctrl+F5 i.e. with Visual Studio development server e.g. http://localhost:3251/default.aspx.

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

But, when i try to run it directly from IIS, with default port (80) e.g. http://localhost/seleniumTest/default.aspx, then it fails with following observation/error:

  1. 它扩展了 Selenium 代码,但不显示浏览器.
  2. 执行一些步骤后失败,服务器没有响应 url http://localhost:7094/hub/session/4bbe4b0c-aeee-4fa3-8bc0-aae47c6869af/element

我想要达到的目标是可能的.

It is possible what i am trying to achieve.

仅供参考:如果需要更多详细信息,请告诉我.

FYI: Let me know if further details are required.

推荐答案

我已经设法自己找到了解决方案.

I have managed to find the solution myself.

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

Basically, RemoteWebDriver has to be used instead of FirefoxDriver. Steps:

  1. 将 FirefoxDriver 的初始化更改为 RemoteWebDriver 为:

更改自

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 服务器并使用 ~

2. Download Selenium Standalone server and initiate it via command prompt using ~

java -jar E:Softwareselenium-server-standalone-2.24.1.jar -interactive -port 4545

这种方法有两个好处:

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

  1. One could use the local IIS for running the test.
  2. Test could be run remotely. Refer Selenium RC documentation. One could see the screenshots remotely using

REMOTE_IP:4545/wd/hub/static/resource/hub.html

REMOTE_IP:4545/wd/hub/static/resource/hub.html

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

I am thinking to modify the code of hub.html and client.js file used within it to provide a better Remote feel.

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

I hope this can be useful for others as well.

仅供参考:

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

这篇关于我们可以使用 IIS 而不是 Visual Studio 开发服务器运行 Selenium WebDriver 测试用例吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆