aspose file tools*
The moose likes Testing and the fly likes Selenium 2 Best Practice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Selenium 2 Best Practice" Watch "Selenium 2 Best Practice" New topic
Author

Selenium 2 Best Practice

Tobi McFarland
Greenhorn

Joined: Nov 21, 2001
Posts: 22
1- Is it acceptable to use JUnit to write Selenium 2 tests with Web Driver? We are using Jenkins + Maven to execute the unit tests.

2- We have noticed fairly often, that when a test is executed locally it passes, but as soon as the test is pointed at the development environment it fails. It looks like the tests execute so quickly (esp in Firefox) that tests often time out before a page loads. Are there any tricks to avoid this? Is this a common occurrence?

I can't find a lot of documentation on Selenium 2 yet, so any tips would be appreciated.

Thanks!


Tobi<br /> <br />Aspiring Java Jedi
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

They had a similar pratice in my job. But the problem that it was to hard to create the test. The maintenance was hard also. They kind abandoned it and sticky with only JUnit test. =/


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

1- Is it acceptable to use JUnit to write Selenium 2 tests with Web Driver? We are using Jenkins + Maven to execute the unit tests.


Yes, but some selenium command are not supported in WebDriver mean doesn't create a code for you in Selenium IDE when you can change the format in Junit Webdriver,
and show you the output something like this.


but there is code practice to handle such type of commands-and-operation. One advantage using a webdriver test run independently means does not require the standalone Selenium RC server to be run.

2- We have noticed fairly often, that when a test is executed locally it passes, but as soon as the test is pointed at the development environment it fails. It looks like the tests execute so quickly (esp in Firefox) that tests often time out before a page loads. Are there any tricks to avoid this? Is this a common occurrence?


there is many commands provided in selenium-IDE when follow the test, mostly tester know which pages takes a bit more time load or render an element on page.
The most common command we use "WaitForElementPresent" to inforce my test to don't move further until you have dependent element for the next step.

Hope its helps.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Tobi McFarland
Greenhorn

Joined: Nov 21, 2001
Posts: 22
Thanks, I'll give it a try! There is something similar in the WebDriver API. I've been putting in manual timeouts periodically like:

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Brian Burress
Ranch Hand

Joined: Jun 30, 2003
Posts: 122
Tobi McFarland wrote:1- Is it acceptable to use JUnit to write Selenium 2 tests with Web Driver? We are using Jenkins + Maven to execute the unit tests.


Not sure if I have the authority to determine if it is "acceptable", but I have written JUnit tests using selenium webdriver and had a lot of success with it. I may be mis-remembering as I have not worked with it in a while, but I think the client tests of the prior release (Selenium RC) were just extentions of JUnit, you just had to have a selenium server running which handled the browser work. I actually had a lot of RC tests which I migrated to web driver without a lot of issues with the control itself (parsing the pages was a different matter, but the architecture swap itself and navigation updates were pretty easy)


Tobi McFarland wrote:2- We have noticed fairly often, that when a test is executed locally it passes, but as soon as the test is pointed at the development environment it fails. It looks like the tests execute so quickly (esp in Firefox) that tests often time out before a page loads. Are there any tricks to avoid this? Is this a common occurrence?


I have run into this. Approach automated tests like you would for any programming solution and consider how to 'design' the code to help you out. I tend to have a base class with common variables and things like URLs (which can be overridden with -D) to allow easy swaps between environments, etc. Specific to this issue, I have helper methods in my base class to do the webdriver "get" followed by a "wait" method call which just does a Thread.sleep wrapped in a try/catch and the waittime as an input parm to the wait.

 
 
subject: Selenium 2 Best Practice