Selenium HtmlUnit Driver Exception



我正在使用JUnit,Selenium WebDriver,并尝试使用HtmlUnit和 http://vk.com 站点进行一些测试,但失败了。看起来FirefoxDriver对我来说很好用。
这是代码:

@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());   
    //...     
}

当我启动它时,我得到一个异常:

    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)

有什么建议吗?这是黑盒测试,我无权在现场更改内部代码。

Different drivers have different ways to handle javascript. 

Htmlunit使用Rhino,Firefox-driver使用Firefox的默认javascript处理程序,因此,使用不同的驱动程序可以看到不同的结果。

htmlUnit()替换为firefox()以进行修复。

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); 

相关内容

  • 没有找到相关文章

最新更新