我正在使用 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)
有什么建议么?附言。这是黑盒测试,我无权在现场更改内部代码。