简体   繁体   中英

Browser session get expired during script execution

Website session get expired during script execution. I have 4 classes which have 15-16 test methods. while i do execute all as a suite using from testing.xml.

Scenario : Perform search after user Login

I'm using below Condition

if(check user is already login)
{
    if(check user is on homepage URL)
    {
       // if user is already on homepage then perform search
    }
    else
    {
        //here my code is  first navigate the page to homepage and then perform search. 
        But the session get destroy once it navigate to home page here and the test get failed as 
    }
}
else
{
   // not login then first do login and then perform search
}

So my question are :

  1. Is it my website issue or webdriver issue ?
  2. Why session getting logout on page navigation ? I have tried both driver.get() and driver.navigate().to() but no success.

Can someone give me the clue if such problem has been faced ?

Without more code it's hard to tell what actual problem is but you do have a logic/ DRY issue. From the comments in your code, you have your search code in 3 different places. A better logic flow would be something like this

if (user is not logged in)
{
     // log in
}
if (browser is not on homepage URL)
{
    // navigate to home page
}
// now you can do the search

Part of the issue may be that you seem to be reusing sessions. The fact that you need to check whether the user is logged in or on the homepage indicates that you don't know where the test is at any given point.

A better way to write this test is to create a single test that instantiates the browser, navigates to the home page, logs the user in, does the search, and then closes the browser. That's one test. If you need to repeat that test with different search criteria, then you can do data driven testing. Having a small test like this will make it easier to know what the script is doing and less likely to have session timeout, etc. issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM