In order to save time in test execution, we may try to reuse state cross different tests.
Testcafe have provided a feature name "Role". But this feature is just for login scenarios.
I hope that we could have some low level API to dump and restore states.
My suggestions is testcafe should provide two API: dumpState, restoreState
When I calling const state: String = await t.dumpState(), testcafe should collect necessary information and serialize it.
Then when I need to using the state dumped by other tests, I just need to call await t.restoreState(state). And testcafe should restore browser to the point that await t.dumpState() is called.
This design will provide enough flexibility for developer to using the state in their test cases. For example, when I using testcafe for integration testing, I can even persist state to database so that I can share state cross run!
Hi @link89
聽
TestCafe has several built-in mechanisms which control the web page state.
localStorage and sessionStorage states.Hi @miherlosev
The API I want to have should be able to dump all data will be persisted in browser, includes: Cookies, Session Storage, Local storage, indexedDB (I am not sure if we can even persist state of websocket connection.), so Role is not enough.
Disable page reloads looks good but the API is not clear to me.
As a developer, I think a simple and clean API can be applied to more scenarios (potentially). Here is some examples.
Suppose we have following API:
resetState(): reset browser to init state
dumpState(): String: dump all date persisted in browsers (include testcafe context)
restoreState(data: String): restore persisted data and testcafe context according to dumped data
// Pseudocode, statefile can be replaced by S3 or db
if (fileExists('statefile')) {
await t.restore('statefile');
} else {
// start to prepare scenario before reach test point
// ... a lot of steps ...
// end of prepare
writeFile(await t.dumpState(), 'statefile');
}
assert(...)
We only need to run this case once, which will save a lot of time when every case is triggered 100+ times everyday.
// Pseudocode
// user1's context
await login(user1)
await sendMessageTo(user2, 'hello world')
// switch to user2's context
const state1 = await t.dumpState()
await t.resetState()
await login(user2)
// assertion
await shouldReceivedMessage('hello world').from(user1)
await sendMessageTo(user1, 'hello world')
// switch back to user1's context
const state2 = await t.dumpState()
await t.restore(state1)
// assertion
await shouldReceivedMessage('hello world').from(user2)
Thank you for the detailed explanation. I've marked this issue as a suggestion.
Any update?
I also would like to reuse data in IndexedDB among different tests.
Once we get any results, we will post them here.
Just going to bump this as this as this is something that's hampered our use of TestCafe since it's hard to make it work nicely with Firebase auth
Most helpful comment
Any update?
I also would like to reuse data in IndexedDB among different tests.