JavaScud | Forum | JIRA | Blog |
  Dashboard > Selenium 中文 > ... > Selenium chinese translation road map > Selenium Remote Control - Java
  Selenium 中文 Log In View a printable version of the current page.  
  Selenium Remote Control - Java
Added by Tin Steeler, last edited by Tin Steeler on Nov 15, 2006
Labels: 
(None)

Selenium Remote Control: Using the Java Client Driver

JavaDoc reference is available

First, make sure you've already started the Selenium Server separately in another process. The Selenium Server should remain up and running throughout this process; you shouldn't need to start/stop it each time you use the Client Driver. (Though, of course, if you need to start and stop the server, you certainly can, just by automatically starting it from the command line.)

Just add selenium-java-client-driver.jar to your classpath, and create a new DefaultSelenium object. You'll need to give it the hostname and port of the Selenium Server, the browser string to use with "getNewBrowserSession", and the base URL at which we'll start testing. When you're ready to begin, run the .start() method on your DefaultSelenium object; when it's time to close the browser, use the .stop() method.

The DefaultSelenium object is full of handy methods that handle your Selenium Commands. If one of them has an error (or if an "assert" command fails) the method will throw an exception with a handy error message, which you can wrap up in a try/catch block if you like.

While we recommend that you use the Java Client Driver together with a testing framework like JUnit or TestNG, a testing framework is not required; you can use the Java Client Driver with any program whatsoever to automate tasks in your browser.

If you do run your tests in JUnit you may run into a common issue with organizing the tests: if you start your browser during setUp and then stop your browser during tearDown, you'll very likely be stopping and starting your browser dozens or even hundreds of times throughout the test run. Furthermore, there's no easy way to configure JUnit to run the same test multiple times with different configurations (aka "data-driven" testing). TestNG makes these tasks very easy, so you may prefer to use TestNG for that purpose.

With that said, JUnit is the the de facto standard for Java automated tests. If you want to use JUnit anyway, you'll probably want to look into using a global setUp and tearDown. Note that the JUnit team recommends that you not use TestSetup, because JUnit is a unit testing tool (for verifying your code in isolation) rather than an integration or functional testing tool (for verifying your code's compatibility with particular browsers). Think about using TestNG instead.

Examples: GoogleTest.java, RealDealIntegrationTest.java.

Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators