javaselenium-webdriverhtmlunithtmlunit-driver

Why am I getting UnknownHostException using HtmlUnitDriver?


I am writing a test that should get only the URL from the redirect, there is no need to load the non-existing page. Every time I get this exception:

java.lang.RuntimeException: java.net.UnknownHostException: No such host is known (bank.test.com)

How I said, there is no need to load only what I need is to get the URL when a user submits the form, how should I do it?

This is the code where it is causing exception:

@Step("Sign in")
    public static String signIn(WebDriver driver, String url, String username, String password) {
        driver.get(url);

        HtmlUnitDriverSteps.setFieldValueByName(driver, USERNAME, username);
        HtmlUnitDriverSteps.setFieldValueByName(driver, PASSWORD, password + Keys.ENTER);
        
        return driver.getCurrentUrl();
    }

Is there solution for my issue?


Solution

  • Instead of the partial url_string bank.test.com you need to pass the complete (fully qualified) url_string as follows:

    https://bank.test.com