Selenium in -browserSessionReuse mode launchs a new browser

别来无恙 提交于 2020-01-02 07:09:20

问题


I'm trying the -browserSessionReuse Selenium mode to speed up my tests but i've noticed a strange behaviour.

The purpose of this mode is avoid the time wasted opening browsers between tests, and this is how it works. But not always, if i run tests continuously they are run in the same browser, correct. But if between each test run pass some minutes, it will forget it has an already opened browser and it opens a new one.

I suppose there is a timeout to discard the "old" browser, but i don't understand why. Is there anyway to avoid this issue?

(tested with Selenium1 and Selenium2)

Thanks in advance

Victor


回答1:


Answering my own question.

Selenium caches the sessions in the -browserSessionReuse mode to reuse it again in the following tests, but they have a max idle session time to expire 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 param to do the cleanup which is TRUE by default.

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

AFAIK there is no way to change it using a Selenium param, the only way is modify the Selenium source code and compile it again. So, that's what i'm doing




回答2:


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',
        ...
    )
);

The alternative (default) is 'isolated'.



来源:https://stackoverflow.com/questions/6099521/selenium-in-browsersessionreuse-mode-launchs-a-new-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!