-1

I'm using JUnit, Selenium WebDriver and try to make some tests with HtmlUnit and http://vk.com site but fail. It looks like FirefoxDriver works great for me.
Here is code:

@Before
public void setUp() {
    DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();      
    capabilities.setBrowserName("Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0");
    capabilities.setVersion("24.0");
    capabilities.setJavascriptEnabled(true);
    driver = new HtmlUnitDriver(capabilities);  
    driver.manage().timeouts()
            .implicitlyWait(Integer.parseInt(TIMEOUT), TimeUnit.SECONDS);
    driver.get("http://vk.com");
}

@Test
public void SomeTest() {
    /* LoginPage - described class in PageObject traditions */
    LoginPage start = new LoginPage(driver);
    LOG.info(driver.getPageSource());   
    //...     
}

When I start it I get the an exception:

    org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking setInnerHTML
Build info: version: '2.37.0', revision: 'a7c61cb', time: '2013-10-18 17:14:00'
System info: host: 'hera', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10-3-amd64', java.version: '1.6.0_27'
Driver info: driver.version: HtmlUnitDriver
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:484)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:463)
    at vk.Execution.setUp(Execution.java:77)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

Any suggestions? ps. This is black-box testing I've no access to change internal code on site.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
user1722707
  • 151
  • 1
  • 3
  • 6
  • 1
    Have you looked at this?http://stackoverflow.com/questions/3600557/turning-htmlunit-warnings-off/18563576#18563576 – Richard Nov 02 '13 at 19:14

2 Answers2

0
Different drivers have different ways to handle javascript. 

Htmlunit uses Rhino and firefox-driver uses Firefox's default javascript handler and hence, you see different results with different drivers.

coding_idiot
  • 13,526
  • 10
  • 65
  • 116
0

Replace htmlUnit() with firefox() for your fix.

DesiredCapabilities capabilities = DesiredCapabilities.firefox()
  capabilities.setBrowserName("Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0");
  capabilities.setVersion("24.0");      
  driver = new HtmlUnitDriver(capabilities); 
Prashanth Sams
  • 19,677
  • 20
  • 102
  • 125