5

So I am concerned with

webdriver.navigate().back();

in particular. AFter reading How does the Back button in a web browser work?

it made me think of how can I make sure back button behaves as expected?

Here's different ways of having "back" navigation. How would you go about detecting which approach to use? Listen to whether POST or GET is being made? Listen for AJAX requests and plan the appropriate plan?

a) navigate back() (essentially hitting back button in firefox)
b) make GET request to the previous page url
c) click on "return to results" on current page

with a) back() sometimes do not work correctly for AJAX sites with no breadcrumbs. or for POST search results for example where pressing back will prompt alert message.

with b) my concern is that the url may not match up,

ex) dynamic urls with unique hash sessionid parameters

http://www.aa.com/results.php?sessionid=29756293changeseverytime

So how do I create a contingency to make sure the back navigation works correctly as expected for a variety of web apps and sites (there are lot of variability in terms of how the back button will behave).

Community
  • 1
  • 1
KJW
  • 15,035
  • 47
  • 137
  • 243

1 Answers1

8

Why don't you store the location of the page that you want to verify, hit a link, use the goBack and then verify location of check the variables (the one you stored and the location of the verify page)?

By the way, if your site uses AJAX I suggest you use the pause function that waits for the AJAX lib. To fully load, or set the speed of your site (maybe combine them together in rare cases).

Ryan Berger
  • 9,644
  • 6
  • 44
  • 56
Roy Segall
  • 336
  • 2
  • 6
  • do you think this will be consistent? my fear is that as above stuff like session id or some random bits of uri paremeter that might not match....but maybe im being paranoid because I mean stuff like sessionid shouldn't change too much for a page that I just visited right? – KJW Nov 16 '11 at 23:54
  • also what about pages that are arrived by POST. – KJW Nov 17 '11 at 00:16
  • If you are afraid of session id you can built your own validation: store the base address of your site(after open, you can store your address to variable), about the session you will need to some how get it: from a element in the site(maybe a meta tag, i dont know). and by what do you pages that arrived by post? – Roy Segall Nov 17 '11 at 20:55
  • so for example a search query does a POST request and the result would be http://ssss.com/results.php. the URL is same but the pages are completely different. when you click on a link and then go back(), what happens? how does back button behave for POST requests? sometimes you can't go back. – KJW Nov 17 '11 at 21:40
  • 1
    selenium is do what we doing with our browsers. Didn't you ever search something in google and click back - We go back to the last page unless there is a JS that mess it up. The main problomes with forms is when we send the data, the site didn't move us to other page and we refresh the page we got the alert because the browser save the posting data. You need to check how your site behave when he work well and then write your selenium tests as well. And for searching tests: i would check that my search works well by that i check that the returned search results conatins my search keywords. – Roy Segall Nov 18 '11 at 15:09