Usage of TestNg, HtmlUnitDriver, selenium, Java and EclipseAsk Question

问题:

I'm trying to run a very simple code that retrieves the title of a page and uses assertion but in a Headless Browser. I'm using HTML Unit Driver. I will show my code, the libraries included and the result. I know the test case should be a pass but it's failing. Any help?

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.Assert;
import org.testng.annotations.Test;


public class Verify {

    @Test
    public  void verifyGoogle() {
        // TODO Auto-generated method stub


        WebDriver driver = new HtmlUnitDriver();

        driver.get("http://google.com");

        String title = driver.getTitle();

        System.out.println(title);

        Assert.assertTrue(title.contains("Google")); 

    }

}

This is the result i'm getting:

[TestNG] Running:
  C:\Users\ntouma\AppData\Local\Temp\testng-eclipse-1794337486\testng-customsuite.xml

FAILED: verifyGoogle
java.lang.NoSuchFieldError: INSTANCE
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.configureHttpsScheme(HttpWebConnection.java:601)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClient(HttpWebConnection.java:536)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClientBuilder(HttpWebConnection.java:498)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:156)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1323)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1240)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:347)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:416)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:519)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:508)
    at Verify.verifyGoogle(Verify.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@19bb089b: 42 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@35bbe5e8: 9 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@6bdf28bb: 20 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@1fbc7afb: 70 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@129a8472: 8 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 8 ms

[And these are the Libraries referenced.][1]

project setup

标签: selenium testng headless-browser htmlunit-driver
© 2014 TuiCode, Inc.