我想从命令行运行Selenium测试用例文件

时间:2009-08-05 08:53:58

标签: testing selenium

然后我使用Firefox扩展“Selenium IDE”保存了一个测试用例。

现在我想使用命令行来运行这个导出的html文件。

我尝试按照how-do-i-launch-the-selenium-ide-from-the-command-line-with-a-specific-test-case进行操作但不起作用。

请帮帮我。

9 个答案:

答案 0 :(得分:39)

您将需要您可以获得的Selenium RC:
http://seleniumhq.org/download/

和Java 1.5或更高版本(Download Java here

1)安装Java
2)打开Selenium RC包装 3)打开cmd.exe窗口并转到包含Selenium Server(selenium-remote-control-1.0.1\selenium-server-1.0.1)的目录 4)运行以下命令:

java -jar selenium-server.jar -htmlSuite "*firefox" "http://10.8.100.106" "C:\mytestsuite\mytestsuite.html" "C:\mytestsuite\results.html"

这应该在Firefox中运行您的测试套件并将结果写入html文件。显然,您需要将"http://10.8.100.106"参数更改为您自己的服务器(这可能只是localhost / 127.0.0.1

答案 1 :(得分:3)

可以使用Selenese Runner运行单个测试用例。您可以指定单个测试用例文件或测试套件作为要运行的单元。

答案 2 :(得分:2)

我们应该使用以下命令执行SeleniumRC;

java -jar filename.jar

例如:

java -jar program1.jar
程序1包括以下内容:

  1. program1.class档案
  2. 资源库文件,例如SeleniumRC Server.jar和Selenium Java client.jar文件
  3. 此方法适用于SeleniumRC执行。我们可以直接使用eclipse创建program1.jar文件 文件 - >导出

答案 3 :(得分:1)

这篇文章向您解释如何在Java中运行Selenium RC应用程序的分步过程。

Create a Java Selenium RC test script and executing the script

答案 4 :(得分:0)

我之前需要这样做,并使用以下内容:

  1. Ant Build(复杂)
  2. 创建测试运行器类(junit框架的一部分)类。
  3. 最常见的是,我们会在尝试从cmd运行时遇到构建路径错误。

答案 5 :(得分:0)

为了能够在Chrome浏览器中运行,您可以使用* chrome选项代替* firefox,如下所示

java -jar selenium-server.jar -htmlSuite "*chrome" "http://localhost" "C:\testsuite\testsuite.html" "C:\testsuite\results.html"

其他浏览器列表包括:

*firefox
*mock
*firefoxproxy
*pifirefox
*chrome
*iexploreproxy
*iexplore
*firefox3
*safariproxy
*googlechrome
*konqueror
*firefox2
*safari
*piiexplore
*firefoxchrome
*opera
*iehta
*custom

会话null

答案 6 :(得分:0)

如果你想从命令提示符运行它,你可以考虑在python中编写你的selenium测试。 如果你在Windows上,请确保安装了python。 Mac默认会有python。

答案 7 :(得分:0)

1)从CMD运行

java -cp "C:\ProjectX\Mortgage\bin;C:\Selenium_latest\selenium2.49.1\*;C:\Selenium_latest\selenium-2.49.1\libs\*" org.testng.TestNG C:\ProjectX\Mortgage\testng.xml

在C:\ ProjectX \ Mortgage

中运行以上命令

2)创建批处理文件名runner.bat

SET projectLocation=C:\ProjectX\Mortgage
CD %projectLocation%
SET classpath=%projectLocation%\bin;C:\Selenium_latest\selenium-2.49.1\*;C:\Selenium_latest\selenium-2.49.1\libs\*
java org.testng.TestNG %projectLocation%\testng.xml
PAUSE

3)双击运行批处理文件。

答案 8 :(得分:0)

从CMD运行测试非常简单。

按照以下步骤

1-转到主目录并设置类路径

主页目录> set classpath = Home Directory \ bin;然后按Enter键

主页目录> set classpath =主目录\ lib *;然后按Enter键

2-Home-directory> java org,testng.TestNG testng.xml testng2.xml testng2.xml并按Enter键

我记录了所有steps here。希望它会有所帮助。干杯