1

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

非常感谢您的帮助。

+0

你的意思是加载和运行硒1脚本(I.E Selenium 1),或者你是指可以将Selenium 1代码转换为Selenium 2代码的东西吗?如果后者有什么语言? – Ardesco 2011-04-11 21:37:28

+0

那么我宁愿不修改脚本,如果有可能做我的工作,暂时不迁移到硒2。 – silas 2011-04-12 04:32:31

回答

1

开始 - >程序 - >附件 - >系统工具 - >计划任务 如果你可以让这些脚本被.exe调用,那么你很好去,很好,很容易。

+0

你有什么想法如何做到这一点?你知道任何可以带命令输入的selenium .html文件的exe文件吗? – silas 2011-04-12 04:33:56

0

您需要在Windows中设置一个计划任务(假设您在提到C#之后就开始使用Windows)。

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

3

您不需要将您的测试转换为Selenium 2就可以运行它们。 Selenium 2包含Selenium 1和Selenium与webdriver合并的所有代码。您现有的脚本应该在最新版本的硒上运行良好。

从上述问题中,我假设你已经在硒IDE录制脚本,想使用Selenium服务器来运行它们,如果是的话看看下面的例子:

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服务器,它可以在设定时间或被触发以基于代码提交运行测试。

+0

非常感谢。我设法使java在命令行中工作(不知道为什么它不会在命令行中工作,并在GUI中工作)。然后我用一个测试selenese文件测试它。虽然一切似乎都正常开始(FF开始),但实际测试从未开始。最后要尝试的是用自动转换将我的脚本修改为selenium 2 java。让我们探索java世界。 – silas 2011-04-12 09:28:56

+0

要检查的事情将是您的命令行首先确保没有错误,其次,您是否在您的Selenium IDE脚本中设置了一个基本域?如果不是,测试将不知道哪个网站运行测试。 – Ardesco 2011-04-12 09:48:26

+0

非常感谢。我花了5分钟安装eclipse参考selinium 2 jar并完美运行我的脚本。现在我将不得不转换为sel 2,但这很容易,因为有汽车转换器。 – silas 2011-04-12 10:04:18