自动运行硒测试

fer*_*i2k 3 selenium

我有Selenium的问题,无法让它工作.
我想做什么:
我们的客户向我们发送了一个Selenium测试用例,该测试用例将在多个位置自动执行,并记录所用的时间.我们希望使用Selenium和Firefox Portable,因为我们希望测试完全独立于任何用户输入和不同位置的已安装软件.对于起始条件来说太多了;)
到目前为止我们做了什么:
第一个版本完全用Java编写,我们使用Selenium IDE插件 - >导出到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
Run Code Online (Sandbox Code Playgroud)

这启动了我预装的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
Run Code Online (Sandbox Code Playgroud)

这不起作用,因为如果在Windows下运行,Selenium Server无法执行此命令(请参阅: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
Run Code Online (Sandbox Code Playgroud)

请注意我们的"修补"硒和"chrome"htmlSuite.这也行不通.所以,简而言之就是结果:

  • htmlSuite = firefox:如果安装了预安装的Firefox,则不使用Portable.如果没有安装FF,则测试完全失败

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

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

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

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

小智 5

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