Selenium Scripts on the command line

2019-06-07 19:23发布

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?

1条回答
Animai°情兽
2楼-- · 2019-06-07 19:34

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.

查看更多
登录 后发表回答