【问题标题】:How to run Selenium tests with CI (Continuous Integration)?如何使用 CI(持续集成)运行 Selenium 测试?
【发布时间】:2011-04-11 20:20:31
【问题描述】:

我正在使用 Selenium 对我的网站进行自动化测试。我有大约 100 个测试用例,我想通过自动生成测试套件来每天运行它们。我在 Selenium 1 (Selenium RC) 中编写了我的测试用例,现在迁移到 selenium 2 (WebDriver) 并不容易。是否有任何方法或应用程序可以自动加载和执行 Selenium 1 脚本?

非常感谢您的帮助。

【问题讨论】:

  • 您的意思是加载并运行 selenium 1 脚本(即 Selenium 1),还是可以将 Selenium 1 代码转换为 Selenium 2 代码的东西?如果后者是什么语言?
  • 好吧,如果可以在不迁移到 selenium 2 的情况下完成我的工作,我宁愿不修改脚本。

标签: c# selenium continuous-integration selenium-webdriver auto-build


【解决方案1】:

您无需将测试转换为 Selenium 2 即可运行它们。 Selenium 2 包含 Selenium 1 和 Selenium 与 webdriver 合并的所有代码。您现有的脚本应该可以在最新版本的 selenium 上正常运行。

根据上述问题,我假设您已经在 Selenium IDE 中记录了您的脚本并希望使用 Selenium Server 运行它们,如果是,请查看以下内容:

Run Selenese Directly Within the Server Using -htmlSuite

You can run Selenese html files directly within the Selenium Server by passing the html file to the server’s command line. For instance:

java -jar selenium-server.jar -htmlSuite "*firefox" "http://www.google.com" "c:\absolute\path\to\my\HTMLSuite.html" "c:\absolute\path\to\my\results.html"

This will automatically launch your HTML suite, run all the tests and save a nice HTML report with the results.

Note

When using this option, the server will start the tests and wait for a specified number of seconds for the test to complete; if the test doesn’t complete within that amount of time, the command will exit with a non-zero exit code and no results file will be generated.

This command line is very long so be careful when you type it. Note this requires you to pass in an HTML Selenese suite, not a single test. Also be aware the -htmlSuite option is incompatible with -interactive You cannot run both at the same time.

以上摘自http://seleniumhq.org/docs/05_selenium_rc.html

正如其他人所说,您还可以设置 cron 作业或计划任务以在设定的时间自动运行脚本,尽管我建议研究像 Jenkins CI(正式 Hudson)这样的 CI 服务器,它可以在一组运行测试时间或被触发以根据代码提交运行测试。

【讨论】:

  • 非常感谢。我设法使 java 在命令行中工作(不知道为什么它不能在命令行中工作并在 gui 中工作)。然后我用一个测试 selenese 文件对其进行了测试。尽管一切似乎都正常启动(FF 已启动),但实际测试从未开始。最后一件事是通过自动转换将我的脚本修改为 selenium 2 java。让我们探索 Java 世界。
  • 首先要检查你的命令行以确保没有错误,其次你是否在你的 Selenium IDE 脚本中设置了一个基本域?如果不是,测试将不知道要针对哪个网站运行测试。
  • 非常感谢。我花了 5 分钟安装 eclipse 参考 selinium 2 jar 并完美运行我的脚本。现在我必须转换为 sel 2,但这很容易,因为有自动转换器。
【解决方案2】:

开始 -> 程序 -> 附件 -> 系统工具 -> 计划任务 如果您可以让这些脚本由 .exe 调用,那么您就可以开始了,很好而且简单。

【讨论】:

  • 你有什么想法吗?你知道任何可以通过命令输入获取 selenium .html 文件的 exe 吗?
【解决方案3】:

您需要在 windows 中设置计划任务(假设您在 windows 上,因为您提到了 C#)。

所以在 Selenium RC 上设置自动化任务,它将运行您的测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-14
    • 2019-10-31
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多