I have a very simple test I'm creating to run a smoke test of about
300 sites.
So, my code looks like:
private final WebDriver driver;
public TestHomePage(String siteUrl) {
driver = new FirefoxDriver();
driver.get(siteUrl);
}
public void checkHomePage() {
System.out.println("Page title is: " + driver.getTitle());
boolean isErrorPage = driver.getTitle().contains("Error");
System.out.println("Page url is: " + driver.getCurrentUrl());
isErrorPage = isErrorPage ? true : driver.getPageSource
().contains("Coming Soon!!");
isErrorPage = isErrorPage ? true : driver.getPageSource
().contains("Error Message");
isErrorPage = isErrorPage ? true : driver.getPageSource
().contains("Technical Difficulties");
List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println("Number of Links: " + links.size());
}
The problem I'm having is the test runs fine for FireFoxDriver. But as
soon as I run with the test with new HtmlUnitDriver(), I get an error:
Exception in thread "main" org.openqa.selenium.WebDriverException:
java.lang.NullPointerException
System info:
os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_12'
Driver info: driver.version: htmlunit
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get
(HtmlUnitDriver.java:228)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get
(HtmlUnitDriver.java:211)
at com.diginsite.product.webcenter.TestBackPage.<init>
(TestBackPage.java:17)
at com.diginsite.product.webcenter.TestHomePage.checkLinks
(TestHomePage.java:49)
at com.diginsite.product.webcenter.TestHomePage.checkHomePage
(TestHomePage.java:40)
at com.diginsite.product.webcenter.TestingHarness.main
(TestingHarness.java:16)
Caused by: java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:80)
at org.cyberneko.html.HTMLScanner$ContentScanner.changeEncoding
(HTMLScanner.java:2679)
at org.cyberneko.html.HTMLScanner$ContentScanner.scanPI
(HTMLScanner.java:2537)
at org.cyberneko.html.HTMLScanner$ContentScanner.scan
(HTMLScanner.java:1990)
at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:910)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:
499)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:
452)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser
$HtmlUnitDOMBuilder.parse(HTMLParser.java:771)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse
(HTMLParser.java:252)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage
(DefaultPageCreator.java:127)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage
(DefaultPageCreator.java:101)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto
(WebClient.java:439)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:
327)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:
384)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get
(HtmlUnitDriver.java:222)
... 5 more
My guess is that this is caused my malformed HTML. However, I have
not seen any documentation stating that the HTML must be well-formed.
Any ideas of what this issue could be?
Thanks,
Erron