Ken
Ken

Reputation: 373

How to let Selenium Driver resolve hostname to another ip?

Currently our tests have a specific hostname in the url (eg. http://foo.bar/whatever)

We want to resolve foo.bar to a different IP when running the tests.

Manually we would do this by changing the host file or using this piece of c# code:

var request = (HttpWebRequest)WebRequest.Create("http://ip-of-foobar/whatever");
request.Host = "foo.bar";

We need to have the correct hostname... maybe there is another way setting request headers in Selenium?

Upvotes: 4

Views: 2865

Answers (1)

Naveen Kumar R B
Naveen Kumar R B

Reputation: 6398

From my knowledge, there is NO API in selenium to set the IP of the server you want to open the browser. get() takes the URL which contains the domain name or IP address. you can not set the value as you set using C# libraries.

As you want to change the domain name to IP address, following are the two options available:

  1. Keep the IP address in a file. Use the language libraries to read the value from the file and set it to a variable. Use that variable wherever you are referencing the URL. example: driver.get("http://"+variable+"/") to get the home page.
  2. Use the test framework capabilities. parameterization (parameter in testng, example) or data references. This allows you to define the value outside the code and then refer the value using a variable name in the code. Same as the first option, but avoids File reading activity. During the run, change the value, so it will be reflected everywhere.

please let us know the language and framework you are using, so I can try to give the exact solution based on above options.

Upvotes: 1

Related Questions