0

I'm running Codeception tests. For display purposes, I want to drive the tests on a single Chrome browser [or FF idc], and keep the browser open between test runs. I know there is a way to do this [I did it, but forgot how!].

I'm running: Ubuntu 20 google-chrome 86

Currently, the tests run fine, and the GUI pops up, but then closes at the end of the run.

I think it has something to do with the parameter "browserSessionReuse" or "restart" or "detach" but I can't figure out where to put it, especially in PHP!

How can I use just one browser, and keep using it, it Codeception?

yml:

class_name: AcceptanceTester
modules:
  enabled:
    - \Helper\Acceptance
    - WebDriver
  config:
    WebDriver:
      url: 'http://xx123xxx.com/'
      port: 4444
      browser: chrome

How I launch Selenium:

java -Dwebdriver.chrome.driver=/var/www/html/wp-content/plugins/WPbdd/chromedriver -jar selenium.jar
John Dee
  • 539
  • 4
  • 14
  • Someone has done it in Python, not in PHP. https://stackoverflow.com/questions/49764902/how-to-reuse-a-selenium-browser-session – John Dee Nov 26 '20 at 19:38

2 Answers2

0

I'm sorry for not answering exatly what you desire, but I think there is no way to do that.

But I suggest you to use codeception console for run one-by-one acceptance test instructions, so this will keep the browser open while you see each command being executed.

And if you use Docker, I suggest you to take a look at this link, for using selenium and Chrome Drive in containers and you may access the interface thru NoVNC (remote desktop access in browser): https://hub.docker.com/r/selenium/hub

Feel free to contact me if you need help with Docker for running that.

0

UPDATE: Original question was about restart between tests not between test runs.

NEW ANSWER:

Codeception WebDriver module can't do that, but you can implement such functionality yourself.

You would have to create your own module, make it extend WebDriver, overwrite _after and _afterSuite method to prevent them from stopping browser instance. Then implement storing selenium session id to file in _afterSuite and update _initializeSession method to read session id from file and pass it to constructor of RemoteWebDriver , you will have to copy some core from RemoteWebDriver::create method too.

ORIGINAL ANSWER:

That's the default behaviour!
By default WebDriver module reuses the same browser session for all tests and only deletes cookies between tests.
It is possible to make it restart browser between tests by setting restart: true parameter.

Another way to restart browser is to call _restart method in helpers, is there any chance that your Acceptance Helper is executing it?

Naktibalda
  • 13,705
  • 5
  • 35
  • 51
  • I meant keep it open between "test runs" not "tests" I changed it. There is no easy way for Selenium to grab an ALREADY open window. I haven't figured a way to run a test suite multiple times in the same browser. Selenium ALWAYS launches a new session. – John Dee Nov 26 '20 at 19:34
  • Codeception docs: restart - Set to false (default) to use the same browser window for all tests, or set to true to create a new window for each test. In any case, when all tests are finished the browser window is closed – John Dee Nov 26 '20 at 19:34