0

Usecase:

Step 1: Invoke Selenium and traverse till page 2 and quit

Step 2: Invoke Sikuli perform some actions in windows and exit

Step 3: Now invoke Selenium and continue from page 2 or where replay was stopped.

Replay should start from page 2 but I always end-up in starting from home-page. So is there a way to create and send unique cookie for each page traversed in Selenium and can be used later.

I get cookies before exiting from page 2(Step1) and restore them back at Step 3.But it always take me to home page.

So I'm looking for an option whether we can create unique cookies to each page(page 2) and use it to traverse directly to page 2 insteaed of home page.

pseudo code as below:

//setting user-defined cookie
HttpCookie cookie = new HttpCookie(cookieName,cvalue);
          cookie.setDomain(domain);
          cookie.setPath(path);
          cookie.setMaxAge(3600);
          cookie.setSecure(flag);

Above is the cookie which I generated before exiting from Step 2

Sysout(cookie);

test=754895648; expires=Wed, 13 Jun 2029 04:53:44 IST; path=/; domain=vdevpril0.com;secure;


Passing below uniquely created cookie along with original cookie captured
  Cookie ck1 = new Cookie(name,value,domain,path,expiry,true);//auto captured cookie by selenium driver
  Cookie ck2 = new Cookie(name,value,domain,path,expiry,true);//user-defined cookie         
  driver.manage().addCookie(ck1); 
  driver.manage().addCookie(ck2);

If i pass just ck2, I will be in login page. ck1 helps me to auto-login and stops.

Expected: Step 3 should take me to page 2

Actual: Step 3 takes to home page

sridattas
  • 459
  • 1
  • 6
  • 21
  • Possible duplicate of [How can I reconnect to the browser opened by webdriver with selenium?](https://stackoverflow.com/questions/47861813/how-can-i-reconnect-to-the-browser-opened-by-webdriver-with-selenium) – Stephen K Aug 05 '19 at 13:15
  • Why do you think a cookie will let you start at page 2? – JeffC Aug 05 '19 at 14:43
  • @JeffC. I'm trying all possible ways. First, I tried getting RequestURL but didn't get an exact way to do in Selenium then tried with browsermob-proxy which capture traces along with RequestURL but it resulted in empty har file. Now I thought if we can set a unique cookie or some similar data to access pages and later use them to navigate to respective page. Cookies captured during login helps to land into same page when addcookie is done, but why it's not with user-defined cookie. Any suggestions would be really helpful. – sridattas Aug 05 '19 at 15:21
  • I'm not sure what your ultimate goal is. Are you trying to auto log in? – Greg Burghardt Aug 05 '19 at 16:27
  • @Greg Burghardt I want to navigate to page 2 in above usecase and continue replay when browser is launched for second time. – sridattas Aug 05 '19 at 17:16
  • But *why* do you want to continue replay? Are you trying to skip the login step? The reason I ask is because this might change the recommended solution to your problem. – Greg Burghardt Aug 05 '19 at 18:33
  • @Greg Burghardt usecase is combination of web and windows based app, I perform some action in web and jump to windows and again continue replay from last exited step in web. So I'm trying to find a way to auto login using session cookies which works fine and now want to navigate directly to last exited step and continue. cookies didnt work. Now I'm able to do it with logpreferces in selenium but now the new issue is it loads only a part of page not the whole. I'm extracting framelastrequested from performance traces. – sridattas Aug 07 '19 at 04:32
  • Please add the information in your comment to your question itself. People often do not read comments, and this is useful information. – Greg Burghardt Aug 07 '19 at 11:17
  • What happens when the session in the browser expires for real users, and they come back to the browser? How does it behave? You will need to model that in your test rather than magically dumping the user back into a previous browsing session. – Greg Burghardt Aug 07 '19 at 11:42

0 Answers0