Clear dns cache when using Selenium?

553 views
Skip to first unread message

fschwiet

unread,
Jul 12, 2011, 3:12:54 PM7/12/11
to Selenium Users
I have some tests which modify the hosts file to redirect page
subrequests to a fake server implementation. When I run the tests
individually test using selenium then they work fine.

If however a previous selenium test visits a page that accesses the
faked server before the hosts file is change, then the later tests
fails. Apparently chrome is caching the DNS entry for the faked
server. However this happens even if I Stop() the DefaultSelenium
instance and start a new one after updating the hosts file (which
closes and restarts chrome).

Does anyone have any thoughts on how to make this work? I am running
on Windows 7, if it matters I am starting the selenium service running
"java -jar .\selenium-server-1.0.3\selenium-server.jar". Does anyone
think using Selenium 2.0 / WebDriver instead would help?

Simon Stewart

unread,
Jul 13, 2011, 8:01:32 AM7/13/11
to seleniu...@googlegroups.com
The DNS lookup may be cached in a number of places, including the OS.
The best way to ensure that it's flushed (or, at least, looked up
regularly) is to have the DNS server provide the address with a short
TTL and then wait for _at least_ that TTL before starting the next
test.

Simon

> --
> You received this message because you are subscribed to the Google Groups "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
>
>

Frank Schwieterman

unread,
Jul 13, 2011, 1:07:15 PM7/13/11
to seleniu...@googlegroups.com
Thanks for looking at this. With the hosts file, I am not able to
set a TTL. But thats ok, asthings started working once I moved to
selenium 2.0. Maybe its because I'm testing against Firefox instead
of chrome, but I found the problem went away. The hosts file is
updated before the 2.0 webdriver instance is instantiated, so it gets
the updated address from the hosts file. I don't understand why
restarting the browser seleniumRC didn't accomplish that, I suppose it
wanted to encourage me to move to 2.0.

thanks again

Reply all
Reply to author
Forward
0 new messages