-
Notifications
You must be signed in to change notification settings - Fork 69
SaveState improvements #1177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
SaveState improvements #1177
Conversation
259e4ef to
8603fea
Compare
commit: |
ab6251f to
f003ba9
Compare
shadowusr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! 🔥
I've left a couple of suggestions, specifically about configuration options for state* commands. The timeout of 5 mins in tests is a bit concerning as well
If in doubt about the config option, feel free to drop me a PM or discuss the matter in the team chat.
| import process from "node:process"; | ||
|
|
||
| const TIMEOUT = 180000; | ||
| const TIMEOUT = 320000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timeout of 5 minutes? This is not normal IMO =(
What's taking so much time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
|
||
| if (options.keepFile) { | ||
| logger.warn( | ||
| "\x1b[31mPlease be aware that the file containing authorization data will not be automatically deleted after the tests are completed!!!\x1b[0m", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm are we sure such invasive error message is needed? I'd leave no message at all...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, but this option will be used only for local development and it is good message if you forgot disable it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the triple exclamation mark is definitely too much !!!. Also, the message should be actionable — what can I do with this message? I think it should explicitly mention that you should disable the "keepFile" option in saveState command.
| cookies: true, | ||
| localStorage: true, | ||
| sessionStorage: true, | ||
| keepFile: process.env.TESTPLANE_SAVE_STATE_KEEP_FILE === "true" || false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think introducing this random env variable is a bad idea.
I would suggest introducing the dedicated config section for the state* commands. It could have the following naming and structure:
interface StateOpts {
cookies?: boolean;
localStorage?: boolean;
sessionStorage?: boolean;
path?: string;
cookieFilter?: (cookie: Cookie) => boolean;
refresh?: boolean;
keepFile?: boolean;
}
interface CommonConfig {
// ...
stateOpts: StateOpts;
}This would cover many points at once:
- It would automatically create env variables, consistent with other config options (
testplane_state_opts_keep_file=true) as well as CLI args (`--testplane-state-ops-keep-file=true) - Users could specify default path and then use
getState/saveState/restoreStatewithout args - Users can set their own defaults to other options
- It's consistent with how we approach configuring other commands in testplane
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
0d23218 to
9ed2401
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the user experience point of view, I've tried using these new features, and experienced major issues:
With this config:
beforeAll: async function() {
const browser = await launchBrowser({
desiredCapabilities: {
browserName: 'chrome',
browserVersion: '138.0',
},
});
await browser.url('http://ya.ru/');
await browser.saveState({
keepFile: true,
cookieFilter: (cookie) => cookie.name.includes('ya'),
});
await browser.deleteSession();
},
stateOpts: {
path: 'browser-state.json',
},The file won't save to browser-state.json at all. Looks like stateOpts doesn't merge well with params passed to saveState command.
The other scenario won't work as well:
beforeAll: async function() {
const browser = await launchBrowser({
desiredCapabilities: {
browserName: 'chrome',
browserVersion: '138.0',
},
});
await browser.url('http://ya.ru/');
await browser.saveState({
path: 'browser-state.json',
cookieFilter: (cookie) => cookie.name.includes('ya'),
});
await browser.deleteSession();
},And then in test:
it('snippet testing', async ({browser}) => {
await browser.url('http://ya.ru/');
console.log(await browser.getState());
});And in test the state already doesn't exist. Looks like we remove state file too early.
I suggest to thoroughly test this feature once again from the user point of view.
|
|
||
| if (!currentUrl.origin || currentUrl.origin === "null") { | ||
| logger.error("Before saveState first open page using url command"); | ||
| process.exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have process.exit over here and in other state* commands?
I think it is very wrong, because with process.exit there can be no proper cleanup at all. In cases when we need to urgently crash process, the halt should be used, that first tries to perform cleanup:
Line 296 in 9ed2401
| halt(err: Error, timeout = 60000): void { |
However, I see no reason at all to crash the whole test run in this case, because it's clearly an issue of a concrete test. Shouldn't we just throw an error over here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
|
||
| if (options.keepFile) { | ||
| logger.warn( | ||
| "\x1b[31mPlease be aware that the file containing authorization data will not be automatically deleted after the tests are completed!!!\x1b[0m", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the triple exclamation mark is definitely too much !!!. Also, the message should be actionable — what can I do with this message? I think it should explicitly mention that you should disable the "keepFile" option in saveState command.
bc0e4d4 to
d234f9c
Compare
d234f9c to
48cb472
Compare
Changes:
keepFile: trueoption to the - commandsaveState.