Selenium in -browserSessionReuse mode launches a new browser

I am trying to use the -browserSessionReuse Selenium mode to speed up my tests, but I noticed strange behavior.

The purpose of this mode is to avoid the time it takes to open browsers between tests, and this is how it works. But not always, if I constantly run tests, they run in the same browser, correctly. But if a few minutes pass between each run, he will forget that he already has a browser open, and he opens a new one.

I assume that there is time to abandon the "old" browser, but I do not understand why. Anyway, to avoid this problem?

(tested with Selenium1 and Selenium2)

Thank you in advance

Victor

+3
source share
2 answers

Answering my own question.

Selenium caches sessions in the -browserSessionReuse mode to reuse it again in the following tests, but they have a maximum session timeout before expiration in the BrowserSessionFactory class:

private static final long DEFAULT_CLEANUP_INTERVAL = 300000; // 5 minutes. private static final long DEFAULT_MAX_IDLE_SESSION_TIME = 600000; // 10 minutes 

The constructor receives a parameter for cleaning, which defaults to TRUE.

 public BrowserSessionFactory(BrowserLauncherFactory blf) { this(blf, DEFAULT_CLEANUP_INTERVAL, DEFAULT_MAX_IDLE_SESSION_TIME, true); } 

AFAIK there is no way to change it with the Selenium parameter, the only way is to change the Selenium source code and compile it again. So what i do

+5
source

To share browser sessions in Selenium2TestCase , you must set sessionStrategy => 'shared' in your initial browser setup:

 public static $browsers = array( array( '... 'browserName' => 'iexplorer', 'sessionStrategy' => 'shared', ... ) ); 

An alternative (default) is 'isolated' .

0
source

Source: https://habr.com/ru/post/1389124/


All Articles