Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I came across an unusual issue with my automation tests while using the HtmlUnitDriver. I have been using the junit parameterized class to iterate over a list of urls to run some of my tests. The test runs just fine with other WebDriver implementations - InternetExplorerDriver, FirefoxDriver and ChromeDriver without any issues. However, with HtmlUnitDriver the test just terminates without any error message. While Debugging, I tried to print my data source (list of urls ) all I got was an empty array in case of HtmlUnitDriver but I get the urls in other WebDriver implementations. So, I am kind of confused how and why is this happenning.

My CoursePage pageobject method returns the urls in an ArrayList.

public  ArrayList<String[]> getPageURLs() throws IOException {

    ArrayList<String[]> forumURLs= new ArrayList<String[]>();
    //forums is a List<WebElement> field on my PageObject that returns a list of elements    
    for(WebElement forum : forums)
    {
        String pageURLs = forum.getAttribute("href");
        //I filter out some urls with if else statements and add only those that are required
        forumURLs.add(new String[]{pageURLs});
    }

    return forumURLs;
}

This is the JUnit method that gets the data:

@Parameters
public static ArrayList<String[]> getURLs() throws IOException{
    startBrowser(Browser.HTMLUNIT);
    LoginPage loginPage =goToLoginPage();
    HomePage homepage =loginPage.loginAs(username, password);
    CoursePage coursepage = homepage.goToCourse();
    return coursepage.getPageURLs();
}
share|improve this question
1  
I have a theory, but first, have you tried adding print statements to narrow down exactly where it fails? –  user246 Sep 26 '12 at 18:51
    
yes, it fails in the last line of the junit method shown above. Doesn't return anything for the coursepage.getPageURLs(); But does return the urls for all other webdriver implementatiosn. Would you please say something about your views? –  StatusQuo Sep 26 '12 at 19:06
    
Have you made sure you've got the HTMLUnitDriver configured with javascript explicitly enabled? If you're running in the default mode without javascript, that could explain why a lot of browser behaviours are different. –  vincebowdren Jul 24 '13 at 10:41
add comment

1 Answer

First, you did not mention why you are using HtmlUnitDriver, but I have never had a lot of luck using it. It does not seem to behave enough like any of the supported browsers, so it I could not use my HtmlUnitDriver results to infer anything about whether a test would actually pass or fail on on real browser.

Second, does your webapp use Javascript to add elements to the page? It is possible that the Javascript does not behave as expected on HtmlUnitDriver, and consequently your course page does not contain what you think it contains.

share|improve this answer
    
This is my first time using the HtmlUnitDriver. After reading about how fast it is I wanted to give it a try so that I can , in the long run, manage all regression tests with HtmlUnitDriver. I do have other tests that run OK with HtmlUnitDriver but just this one that falters.So, it's the getPageURls() method that is in confilct with HtmlUnitDriver for sure but I am totally confused how and why.I do have the javascript to true while instantiating the HtmlUnitDriver. –  StatusQuo Sep 26 '12 at 19:39
1  
@StatusQuo Javascript interpretation depends on the browser; if you have a javascript issue on your home page (or HTMLUnit cannot parse the javascript, it might be correct but HTMLUnit might not be capable of running it), there may not be any URLs on the page. No URLs to scrape means no data to parameterize. –  Yamikuronue Jun 2 at 13:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.