开发者

Workaround for click() not working in HtmlUnitDriver in Fitnesse?

I have a jUnit test running a Fitnesse test that tests some web pages. When in development mode, I use the FirefoxDriver and all tests run great, with web pages popping up as expected.

When I try to run the test in an automated mode, i.e. using Maven, the tests fail miserably. Do any of you have any suggestions of what might be wrong or a workaround?

The relevant code:

- The web page:

      <form method="get" action="/someAction.do" name="my_form">  
  开发者_运维问答    <input id="fetch_new_submit" class="ui-button ui-widget ui-state-default ui-corner-all" type="submit" onclick="showWaitMsg()" value="Fetch new orders" role="button">  
      </form>
  • The fixturecode:

    class SomeFixture...

    public boolean pressSubmitButton(String buttonText) {
    try {
       List<WebElement> buttons = getWebDriver().findElements(By.tagName("input"));
       for (WebElement button : buttons) {
           if (button.getAttribute("value").equals(buttonText)) {
               System.out.println("found button '" + button.getAttribute("value") + "'.");
               button.click(); //HERE
               return true;
           }
       }
    } catch (Exception e) {
       LOG.debug("Some error occured, e);
       return false;
    }
    LOG.debug("Did not find the button");
    return false;
    }
    

Note:

- getWebDriver() returning FirefoxDriver works fine.

- getWebDriver returning new HtmlUnitDriver(true) i.e. with javascript enabled, ignores the button.click() at HERE. Button.submit() is also ignored here and button.sendKeys("\n") throws an element 'not enabled'-error.

- we use version 2.0rc2

Our automated tests can't use FirefoxDriver. Are there any known workarounds for this issue?


Further testing and usage of bleeding edge, i.e. snapshots gave me something that works for now.

That is:
- upgraded Selenium to 2.0rc3
- upgraded htmlunit to 2.9 SNAPSHOT !!!

And some more experimenting around:

final HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);  

The Firefox version now works for submit type buttons but fails for javascript actions. This could also be due to me using Firefox_3_6 version driver while using Firefox 4.0.1. browser.

The IE version_8 hangs on click().

But, the plain HtmlUnitDriver() works!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜