Question

We have a Keyword driven framework which was developed using Selenium Webdriver. While running the scripts some test cases are getting timed out in the first run. When I do the second run the same test cases which failed last time pass but this time some other test cases fail.

Can someone please advise if anything needs to be done on the Framework/Configuration part.

I am using IE9, Java 6, Selenium 2.40 on Windows 7 and IE driver from the official Selenium website.

Was it helpful?

Solution 3

Sainath,

The Secret to run TestCases efficiently lies in the Way You wrote the TestCases.. Use of Fluent wait, Wait before the Element is Visible and Enabled and use of html ID's in Testcases makes the TCs Efficient. IE and Selenium Does not get along almost all time.. i mean,, There are so many Issues with IE and Selenium.

The Only way to Achieve Efficiency is by Proper Handling of Exceptions and Use of Wait statements

OTHER TIPS

Your tests could be brittle because of various reasons.

1. Synchronization- DO NOT USE Thread.sleep. You should consider waiting mechanism in your tests. There are two types of waits in WebDriver. Implicit wait and Explicit wait.

a. Implicit wait- For example below WebDriver will internally poll at max for 30 seconds before throwing NoSuchElementFoundException

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

b. Explicit wait- Here you are telling WebDriver to wait for a certain condition to satisfy. For example, below I am waiting the link Account to be available to click. Once its available WebDriver will return me the WebElement so that I can click on it. Take a look at some already implemented useful ExpectedConditions

WebDriverWait wait = new WebDriverWait(driver,30/*Timeout in seconds*/);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Account")));
element.click();

2. Data Dependency- Make sure your tests are independent of each other and they don't share data. Tests can collide if they are sharing data which makes them brittle

3. Use CSS over Xpaths - Find my answer here as to why

4. A layer of abstraction- Make sure you have abstracted test logic from page logic. Use PageObjects and PageFactory technics for better maintenance of your suite

Finally read Simon Stewarts blog on Automated Web Testing: Traps for the Unwary for details.

I would suggest making sure that the keywords you are using are not dynamically generated.

I worked on a site once where all of the ID's looked like this: 'ext-gen123', then the next run through, the very same element would have the ID: 'ext-gen124', but the run through after that would have the ID back to 'ext-gen123'...

In this case, you'd have to use some other identifier to locate the element--maybe a CssClass or an XPath.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top