- I assume you have Eclipse installed
- I assume you have downloaded the Selenium RC
- The files selenium-server.jar and selenium-java-client-driver.jar will be needed
- In Eclipse create a new Java Project
- Pick a name for the project, set anything else you think you'll need on the first page
- On the next page, go to the Libraries tab and add the two selenium jar files to the project
- Finish
- Right click on the src folder and create a new JUnit Test Case
- Select JUnit 3, pick a package if you want (can be changed later), pick a name, tick setUp and tearDown, click Finish
- It should ask you if you want to add the JUnit 3 library to the project. Answer yes.
- You should now be looking at the JUnit test case class in the editor
- Change the class so it 'extends SeleneseTestCase
- You should get a warning on the SeleneseTestCase
- Hover over it and you should get the option to import com.thoughtworks.selenium.SeleneseTestCase which you should do
- In the setUp() method, the body should be:
- super.setUp(url, browser); where url is the URL of you web site being tested and browser is something like "*firefox", "*iehta" or "*safari"
- For example, super.setUp("http://www.google.ca", "*safari");
- The setUp method should now look like:
public void setUp() throws Exception { super.setUp("http://www.google.ca", "*safari"); }
- In the tearDown() method the body should be:
- super.tearDown();
- The tearDown method should now look like:
public void tearDown() throws Exception { super.tearDown(); }
- Now we can add a test case. It might look like:
- To run this, you'll need to start the Selenium Server.
- Go to a command line and enter:
- You might need some more command line switches like -firefoxProfileTemplate or -trustAllSSLCertificates. To see help on the server use:
- Once you have the server running, in Eclipse you want to run the test case as a JUnit Test
public void testAGoodDescriptionOfWhatWeAreTesting() throws Exception { selenium.open("/"); System.out.println(selenium.getHtmlSource()); }
java -jar selenium-server.jar
java -jar selenium-server.jar -help
NOTE: the SeleneseTestCase is a JUnit 3 TestCase. It assumes the names of the methods are fixed and does not use annotations. You have to use setUp, tearDown and all test cases need to start with 'test'. If you want to create the same thing as JUnit 4 you can use:
import org.junit.After; import org.junit.Before; import org.junit.Test; import com.thoughtworks.selenium.DefaultSelenium; import com.thoughtworks.selenium.Selenium; public class Whatever { Selenium selenium; @Before public void setUp() throws Exception { selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com"); } @Test public void whatever() throws Exception { selenium.open("/"); System.out.println(selenium.getHtmlSource()); } @After public void tearDown() throws Exception { selenium.close(); selenium.stop(); } }
And there is a simple test case create in Eclipse.
nicely explained..thank uuuuuuu
ReplyDeleteHi bro, I'm a new commer to this one, I still haven't know what is Junit 3 .
ReplyDeleteI tried to do as you post, with the extends Testcase.
All I got after "run as" is run1/1 and failure 1/1 (your example).
Is it right ?
And why can't I use Extends SeleneseTestCase ?
Could you explain me a little bit here ?
My basic is just Java and a little html.
Dung,
ReplyDeleteCreating test automation with Selenium is programming and requires a certain amount of programming knowledge. The larger you expect the project to become, the more development skill you will need to exhibit.
You need to learn Java, Eclipse, JUnit and then learn Selenium.
If you want to learn Java, check out http://www.oracle.com/technetwork/java/index.html.
If you want to learn about Eclipse, check out http://eclipse.org/.
If you want to learn about JUnit, check out http://junit.sourceforge.net/.
The SeleneseTestCase class was written to extend the JUnit 3 TestCase class. When they release JUnit 4 they made some significant changes. The SeleneseTestCase was never updated to take advantage of those changes. If you extend SeleneseTestCase with a JUnit 4 test case, you lose all the new features of JUnit 4, i.e. it goes into backward compatibility mode.
Additionally, all these examples assume Selenium 1.0. Selenium 2.0 is very different. Look for posts from 2011 for examples of Selenium 2.0.
Thanks for your answer, I would start from Junit .
ReplyDeleteCould I ask you some more question here ?
I orginal want to make an addon for my Firefox with my basic to improve my programming skill, so I go around around and end up at meeting Selenium , Am I going wrong cause I look closely to your Blog and looklike you are doing something else, more difficult than I image .
BTW love your blog .