1

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?

Sanady_
  • 68
  • 10
  • Regarding your main question - to answer we need more info about your case and the flow you like to test. I guess you call this with the url of the login page. But i have no idea where you think the redirect takes place - when retrieving the login page or when submitting your credentials. – RBRi Apr 07 '22 at 09:55
  • When the page is loaded, the user fills in the two inputs (username, password) data, when the user clicks on the sign-in button, the backend should redirect the user to a page that contains 6 digits code that is used to generate an access token. But issue is problem when the endpoint ends with callback, I tried to change to for example oauth-login – Sanady_ Apr 07 '22 at 09:59
  • OAuth is currently not supported by HtmlUnit - you have to use a real browser driver. – RBRi Apr 07 '22 at 10:00

2 Answers2

1

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
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

UnknownHostException: No such host is known

This usually point to some problems resolving the URL into an ip address to connect to. Please check if this url is available from your browser. Maybe there is a proxy configured for your browser.

RBRi
  • 2,704
  • 2
  • 11
  • 14
  • The catch is that I don't need any of that, I mean converting domain to IP address. Only what I need is the code that is attached to that non-existing URL – Sanady_ Apr 07 '22 at 09:53
  • Sorry but there is no way to contact a server without having the ip address. Maybe you have to learn a bit more about how the internet works. – RBRi Apr 07 '22 at 09:57