【问题标题】:Running selenium test automatically自动运行硒测试
【发布时间】:2013-06-30 21:58:21
【问题描述】:

我遇到了 Selenium 问题,无法让它工作。
我想做什么:
我们的一个客户向我们发送了一个 Selenium 测试用例,该用例将在多个位置自动执行并记录所用时间。 我们想使用 Selenium 和 Firefox Portable,因为我们想让测试完全独立于任何用户输入和在不同位置安装的软件。 开始条件就这么多;)
到目前为止我们做了什么:
第一个版本完全用 Java 编写,我们使用 Selenium IDE Plugin -> Export to Java WebDriver 将客户的测试用例导出到 Java。 这不能再做,因为客户现在使用 WebDriver 导出不支持的一些功能。由于我们不想改变客户的测试,Java 导出不再是一种选择。
所以对于第一次运行,我们使用这个命令(任何变量都设置正确):

java -jar selenium-2.33.0/selenium-server-standalone-2.33.0.jar -port 5555 
-firefoxProfileTemplate "Firefox\Data\profile" -log logs\selenium_server.log 
-htmlSuite "*firefox" http://localhost:5555 Testsuite.html
logs\results-firefox-%curTimestamp%.html

这会启动我预装的 Firefox,而不是便携式的。在客户机器上,没有启动任何 Firefox,因为它没有安装。所以我不得不使用“自定义”htmlSuite来提供Firefox的路径:

java -jar selenium-2.33.0/selenium-server-standalone-2.33.0.jar -port 5555 
-firefoxProfileTemplate "Firefox\Data\profile" -log logs\selenium_server.log 
-htmlSuite "*custom %FF_DIR%\FirefoxPortable.exe" http://localhost:5555 Testsuite.html 
logs\results-firefox-%curTimestamp%.html

这不起作用,因为如果在 Windows 下运行,Selenium 服务器将无法执行此命令,我们这样做(请参阅:http://code.google.com/p/selenium/issues/detail?id=3274) 由于评论 #6 有一些差异,我们修补了 selenium Server 独立 Jar 并再次运行测试。现在可以启动浏览器,但无法运行测试。加载第一页后,我们收到错误“访问属性'文档'的权限被拒绝”。
此处的解决方案表明,用户权限问题可能是原因,您应该尝试“chrome”htmlSuite(请参阅:https://sqa.stackexchange.com/questions/1453/how-to-fix-permission-denied-to-access-property-document) 所以我们做到了:

java -jar selenium-2.33.0/selenium-server-standalone-2.33.0-patched.jar 
-port 5555 -firefoxProfileTemplate "FirefoxPortable\Data\profile" 
-log logs\selenium_server.log -htmlSuite "*chrome %FF_DIR%\FirefoxPortable.exe" 
http://localhost:5555 Testsuite.html logs\results-firefox-%curTimestamp%.html

请注意我们的“修补”硒和“铬”htmlSuite。 那也没用。 所以,简而言之,结果如下:

  • htmlSuite = firefox:使用预装的 Firefox(如果已安装),而不是便携式的。如果没有安装FF,则测试完全失败

  • htmlSuite = chrome:服务器无法启动浏览器,因为它试图设置 EnvironmentVariables,运行 Windows 时不支持(请参阅:http://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/os/WindowsProcessGroup.java#67 以下第 67 行)

  • htmlSuite = googleChrome: Google Chrome Portable 可以启动,但是 Chrome 浏览器找不到测试指定的某些元素,所以我们不能使用 Chrome(更改测试是没有选择的,如上所述)

  • htmlSuite = iexplore: Internet Explorer 启动,但随后出现 JavaScript 错误,引用由 Selenium 创建的自定义配置文件,因此测试在 IE 中也不起作用

  • htmlSuite = custom:Portable Firefox 已启动 (yeehaw),但没有足够的权限执行测试。

【问题讨论】:

    标签: selenium


    【解决方案1】:

    您可以使用 Jenkins 或 TeamCity 等持续集成系统自动执行测试。

    【讨论】:

    • 嗨,谢谢你的回答,但我认为这不会解决问题,因为最初开始测试没有问题,但我们无法控制它的执行方式.另外,我不知道如何从批处理文件中控制詹金斯,这样会使任务更加复杂。
    • 您能解释一下您想要实现的流程吗?例如。蝙蝠->詹金斯->硒或类似的东西。您不必从批处理文件中控制 Jenkins,因为它具有 web gui,另外您可以编译一个 selenium 脚本启动 jenkins 作业或任何东西并通过批处理文件执行它,但这是一种奇怪的方式
    【解决方案2】:

    我们现在决定支持客户在机器上安装 Firefox 进行测试,这样我们就可以毫无问题地使用我们的批处理文件。

    至于 selenium 中的错误,请看这里 (code.google.com/p/selenium/issues/detail?id=5554#c14),有一个链接到一个可以工作的夜间构建(至少对我们来说)使用 Firefox v23,而 Selenium 2.33 没有。

    感谢所有做出贡献的人,但我认为我的第一种方法无法像我想象的那样实现:(

    【讨论】:

      【解决方案3】:

      我解决了这个问题。

      访问此链接:http://www.townx.org/blog/elliot/dealing-self-signed-ssl-certificates-when-running-selenium-server-firefox

      第 9 点: 删除目录中除 cert_override.txt 和 cert8.db 文件之外的所有内容。

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-08-24
        • 1970-01-01
        • 1970-01-01
        • 2011-11-25
        • 2021-09-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多