0

I'm trying to validate that a page redirect in an iframe is working correctly. Ideally a request gets sent from my server to our gateway server, and then redirected to an external page. However because of the way my page handles permissions, the best way to validate that this is succeeding is by confirming that the redirect has occurred and it is to the correct URL.

Using Robot / Selenium automation, is there a way to grab redirect URLs and status codes in order to compare them to an expected value? I've seen mixed answers on whether or not this is possible.

The javascript navigator object seems like it might solve this problem, but I'm not sure how to use it in the context of automation to retrieve redirect URLs.

Any advice is appreciated.

UpQuark
  • 791
  • 1
  • 11
  • 35

1 Answers1

2

As this is tagged with Selenium and Python, the Selenium Python bindings allow you to get the current url with:

driver.current_url

You could use this to validate the URL you're looking for to verify whether the redirect resolves to the right page/url. Depending on the complexity of what you're testing involving the iframes and what not, Selenium might be overkill.

If you're looking for more general answers as far as approaching a problem of testing redirects in general, I'd recommend looking into using Requests, as they offer a nice way of handling redirects and providing you redirect histories.

You can check Requests out here: http://docs.python-requests.org/en/latest/user/quickstart/#redirection-and-history

which I ultimately found through this Stack thread: Python follow redirects and then download the page?

Community
  • 1
  • 1
Pietro Ferrero
  • 476
  • 2
  • 10
  • Thanks, helpful answer. Do you know how one could use this sort of logic within an iFrame in an automation context? – UpQuark Feb 04 '14 at 18:20
  • to clarify, you have a web page that contains an iframe which points to "url x". "url x" redirects to a different url, "url y", and you're trying to validate that the iframe is in fact resolving to "url y"? – Pietro Ferrero Feb 04 '14 at 20:41
  • Yep, that's exactly the issue. – UpQuark Feb 04 '14 at 20:45
  • You could request the page, parse the content to get the iframe and grab its src url, then make a second request to that url and ensure it resolves to the expected one. Does that work? – Pietro Ferrero Feb 04 '14 at 20:50