Eclipse+Junit+SeleniumRC

上一篇 / 下一篇  2010-01-13 17:53:01 / 个人分类:Selenium

目前正在研究如何将SeleniumRC和Junit结合起来进行REGRESSION TESTING.

按照zhangting85博客中的说明一步一步的进行设置:

原文地址:http://e-pyramid.blogspot.com/2008/04/setting-up-selenium-rc-and-junit.html

I recently started learning Selenium RC on my own. I read the materials available on the Selenium RC website. This material assumes that you are familiar withJavaand JUnit concepts. Therefore, it is difficult to setup a working Selenium RC with Java for people having worked onTestAutomation with limited knowledge of Java and JUnit.
Following are the step by step instructions to setup Selenium RC with JUnit for test execution.

1. Download Selenium RC from www.openqa.org
2. Extract the files to the following location C:\selenium-rc
3. Download JUnit 4.4 from www.junit.org.
4. Extract the files to the following location C:\junit4.4
5. Download and Install JDK 1.6 or above to the following location C:\jdk1.6
6. Create a new folder C:\selenium_tests (This would be the location where you will save the test classes).
7. Set an environment variable CLASSPATH as C:\selenium-rc\selenium-java-client-driver-1.0-beta-1\selenium-java-client-driver.jar;C:\selenium_tests\;C:\junit4.4\junit-4.4.jar;
8. Make sure that C:\jdk1.6\bin is included in your PATH environment variable.
9. Download the GoogleTest.java from the Java Tutorials available for Selenium RC at www.openqa.org. Save this file under selenium_tests directory you made eariler.
10. Open a Command Prompt and go to the following location. C:\selenium-rc\selenium-server-1.0-beta-1
11. Type the following command to start the selenium RCserverfor test execution.

>java -jar selenium-server.jar -interactive

12. Open another command prompt window and go the location where you saved GoogleTest.java file. i.e. C:\selenium_tests
13. Compile the java file with javac as

>javac GoogleTest.java

14. This would create a class file that you can run with JUnit for testing purposes as

>java junit.textui.TestRunner GoogleTest

You will notice that it would open a firefox session with Selenium Test Runner and execute the tests. In the end you will get the status of the test result on the command prompt as


C:\Selenium>java junit.textui.TestRunner GoogleTest
.
Time: 5.769

OK (1 test)

This shows that you have successfully run GoogleTest.java as a Selenium RC test using JUnit.

You can experiment editing GoogleTest.java and see the changes in the output.

I would also recommend using Selenium IDE for recording a new test, saving it as Selenium RC Java test and then executing it using Selenium RC and JUnit.


在执行过程中发现了以下几个问题:
1.找不到GoogleTest.java,在网上找了一下几个,编译时报错,自己重新DEBUG了一下,上传在附件中作为参考吧.
2. GoogleTest 编译成功后,没有办法执行,报以下错误:
(1) Exception in thread "main" java.lang.NoClassDefFoundError:
junit/textui/TestRunner.出现这个问题的原因是CLASSPATH设置不正确造成的,你可以通过以下2种方式解决此问题:
  • 右击"我的电脑"-高级-环境变量: CLASSPATH=.;C:\j2sdk1.4.1_02\lib;C:\junit4.1\junit.jar;(根据自己的环境进行设置,这只是一个例子,在设置过程上要注意 . 和 C:\junit4.1\junit.jar)
  • 在DOS窗口中执行TESTCASE时,附带上JUNIT的路径 java -cp C:\junit3.8.1\junit.jar;. junit.textui.TestRunner MyTest 
(2) 按照(1)所述,设置CLASSPATH后还是不行,报了另一个错:Exception in thread "main" java.lang.NoClassDefFoundError: GoogleTest (wrong name: com/example/tests/GoogleTest).到目前为止我也不知道问题原因在哪,不过通过eclipse将junit和SeleniumRC集成在一起后就解决了.

2.Eclipse+junit+selenium
  • (1)Open eclipse and create a new Java Project.

  • (2)Create a lib folder and import the required libraries:

  • From the menu select File -> Import -> File system. Select your jar and select the folder lib as target.
    • selenium-java-client-driver.jarfromSELENIUM_HOME/selenium-java-client-driver-1.0-beta-1
    • junit-3.8.1.jardownloaded from sourceforge.

  • (3) Then select the libraries, right-click and selectBuild Path>Add to Build Path
  • (4)Under src, in the default package import the GoogleTest.java and save
  • (5)To run the test right-click on GoogleTest.java and selectRun As>JUnite Test




TAG:

 

评分:0

我来说两句

Open Toolbar