super simple solution, that does exactly what's needed
The idea is that you don't really want to keep alive the session but rather pause it for a very long time when tests are done and be able to resume on-close procedures at any time
So just add this to your config.js
async onComplete() {
await browser.waitForAngularEnabled(false);
await browser.wait(
async () => {
let url = await browser.getCurrentUrl();
return url.includes('close/');
},
5 * 60 * 1000,
'Keep-alive timeout reached, closing the session...',
);
},
What the code does is, after all tests passed or failed, it waits until you type and submit close/
in browser's url field, or times out itself in 5 mins.
The reason await browser.waitForAngularEnabled(false);
is needed here, because the browser opens an empty page when you type close/
which is non angular
You can even improve it and make it conditional, based on a parameter you pass to protractor config