Home > Software design >  How to keep browser open with Selenium WebDriver 4 and Groovy on Jmeter?
How to keep browser open with Selenium WebDriver 4 and Groovy on Jmeter?

Time:12-21

I am currently in the process, with a Jmeter script, of opening firefox browsers which are functional. However, I have a small problem which is to let the browsers turn on even after the script is finished.

Currently my browsers turn off once the script is finished.

Here is my code :

WDS.sampleResult.sampleStart()
    def display = WDS.vars.get("DISPLAY");
    WDS.browser.get('url'  display  'set')
WDS.sampleResult.sampleEnd()

Is there a possibility to do it?

Are there additional parameters to set in the webdriver sampler, because I don't have an HTTP Sampler or even HTTP cookies.

Thank you for your time

CodePudding user response:

I think if you tick Development Mode box the browser will remain open:

enter image description here

If it doesn't fit your needs, i.e. you're using headless or Remote WebDriver, looking in the source code

@Override
public void threadFinished() {
    if (!isDevMode()) {
        final T browser = removeThreadBrowser();
        quitBrowser(browser);
    }
}

so just comment out/remove this quitBrowser function, recompile the plugin and replace the version in the "lib/ext" folder with your own one.

and last but not the least the browser is being shut down when your test ends, if you want to keep the browser open it's sufficient to configure your test so it would never end by adding i.e. Flow Control Action sampler configured to sleep the required amount of time or just adding the next line as the last one in your WebDriver Sampler code:

Thread.sleep(3600000)

the line will pause the execution for 1 hour, hopefully this time will be sufficient for troubleshooting.

More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

  • Related