硒脚本在命令行上 [英] Selenium Scripts on the command line

查看:151
本文介绍了硒脚本在命令行上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从使用Java和JUnit通过Eclipse IDE编写的命令行运行selenium webdriver测试脚本?



我一直在努力使用Ant或Maven,但我无法让它工作。



有人可以提供一些关于这个问题的建议吗?

解决方案

以下步骤将帮助您在没有eclipse的帮助下从命令提示符运行selenium脚本。



设置 CLASSPATH 为所有支持文件。



右键单击MyComputer - > Proprties - >高级系统设置 - >
单击高级选项卡 - >环境变量 - >
SystemVariables - >双击CLASSPATH变量



在打开的窗口中,有一个变量字段,您需要设置路径,如下所述。为此,您需要在系统上拥有管理员权限。

 。; C:\Program Files\Java\jdk1 .7.0_05\bin; 
。;系统中junit jar文件的路径;
。;系统中selenium java绑定jar文件的路径;
。;如果你正在使用任何一个; brwoser-driver的路径;
。; selenium独立服务器的路径;

我的环境变量看起来像这样。

 ; C:\Program Files(x86)\Java\jre7\lib\ext\QTJava.zip; C:\Program Files\Java\ jdk1.7.0_05\bin; E:\Books&安培; Tutorials\Selenium\junit-4.11.jar; E:\Books&安培; Tutorials\Selenium\selenium-2.31.0\selenium- 2.31.0\selenium-java的2.31.0.jar; E:\Books&放大器; Tutorials\Selenium\chromedriver.exe; E:\Books&安培; Tutorials\Selenium\selenium服务器-standalone-2.31.0.jar; 

保存并退出。



打开命令提示并导航到您的硒脚本所在的文件夹。



确保删除脚本中的包语句。



然后使用 javac programName.java 命令编译脚本。



如果没有引发任何错误,请继续执行类型 java programName 并按Enter键。



如果所有内容都设置好,到目前为止,硒脚本应该通过调用脚本中提到的浏览器来开始执行操作。


Is there any way to run selenium webdriver tests scripts from the command line that have been written using Java and JUnit through Eclipse IDE?

I've been trying to use Ant or Maven but I can't get it working.

Can someone please offer some advice about where to go with this?

解决方案

The following steps will help you run selenium scripts from the command prompt without the help of eclipse.

Set the CLASSPATH for all the supporting files.

Right-Click on MyComputer-->Proprties-->Advanced System Settings--> Click on "Advanced" tab in the new window-->Environment Variables--> SystemVariables--> Double click CLASSPATH variable

In the window that gets opened, there is a variable field, where you need to set the path as described below. For this you need to have Admin rights on your system.

  .;C:\Program Files\Java\jdk1.7.0_05\bin;
  .;path to junit jar file in your system;
  .;path to selenium java binding jar file in your system;
  .;path to brwoser-driver if you are using any;
  .;path to selenium standalone server;

My environment variables look like this.

.;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip;C:\Program Files\Java\jdk1.7.0_05\bin.;E:\Books&Tutorials\Selenium\junit-4.11.jar;.;E:\Books&Tutorials\Selenium\selenium-2.31.0\selenium-2.31.0\selenium-java-2.31.0.jar;.;E:\Books&Tutorials\Selenium\chromedriver.exe;.;E:\Books&Tutorials\Selenium\selenium-server-standalone-2.31.0.jar;

Save and exit.

Open command prompt and navigate to the folder where your selenium script is located.

Make sure you remove the package statements in your script.

Then compile the script using javac programName.java command.

If it does not throw any errors, proceed with execution type java programName and hit Enter.

If everything is set up fine till now, the selenium script should start executing the actions by invoking the browser mentioned in the script.

这篇关于硒脚本在命令行上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆