Skip to content
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

Provide API to dump and restore state #3286

Closed
link89 opened this issue Jan 8, 2019 · 10 comments
Closed

Provide API to dump and restore state #3286

link89 opened this issue Jan 8, 2019 · 10 comments
Labels
STATE: Stale An outdated issue that will be automatically closed by the Stale bot. TYPE: enhancement The accepted proposal for future implementation.

Comments

@link89
Copy link
Contributor

link89 commented Jan 8, 2019

What is your Test Scenario?

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.

What are you suggesting?

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!

@miherlosev miherlosev self-assigned this Jan 9, 2019
@miherlosev
Copy link
Contributor

Hi @link89
 
TestCafe has several built-in mechanisms which control the web page state.

  • The Roles feature manages the localStorage and sessionStorage states.
  • The Disable page reloads feature allows you to
    control test page reloading during test execution.
  • Test and fixture hook allows you to perform initialization and clean up actions for your tests (this feature covers your use case with database state sharing).
     
    Implementation of the API you described makes sense if there are a lot of other use cases which the current TestCafe API doesn't cover. Could you please elaborate on such use cases?

@miherlosev miherlosev added the TYPE: question The issue contains a question that won't be addressed. label Jan 9, 2019
@link89
Copy link
Contributor Author

link89 commented Jan 9, 2019

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

Scenario 1: reach verify point directly if dumped data existed

// 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.

Scenario 2: what can be done by Role can also implement using these API

// 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) 

@miherlosev miherlosev added TYPE: proposal and removed TYPE: question The issue contains a question that won't be addressed. labels Jan 11, 2019
@miherlosev
Copy link
Contributor

Thank you for the detailed explanation. I've marked this issue as a suggestion.

@AndreyBelym AndreyBelym added TYPE: enhancement The accepted proposal for future implementation. and removed TYPE: proposal labels Feb 6, 2019
@misu-moriya
Copy link

Any update?
I also would like to reuse data in IndexedDB among different tests.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Feb 26, 2020
@AlexSkorkin
Copy link
Collaborator

Once we get any results, we will post them here.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Feb 26, 2020
@chriswwalz
Copy link

chriswwalz commented Oct 6, 2020

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

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Oct 6, 2020
@Farfurix Farfurix removed the STATE: Need response An issue that requires a response or attention from the team. label Oct 8, 2020
@github-actions
Copy link

github-actions bot commented Nov 3, 2021

This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.

@github-actions github-actions bot added the STATE: Stale An outdated issue that will be automatically closed by the Stale bot. label Nov 3, 2021
@github-actions
Copy link

We're closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.

@AdrienLemaire
Copy link

AdrienLemaire commented Mar 4, 2022

Can we re-open this issue please ? This is one of @miherlosev suggestions for working with firebase #4939 (comment)

I am unable to get a TestCafe + Firebase + Browserstack flow working (testcafe not supporting signInWithPopup with cloud browsers, and firebase not working with signInWithRedirect if removing indexedDB) . This issue could have been an alternative to get something working.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 4, 2022
@alexfi1in
Copy link
Contributor

The case with supporting Firebase for Role is described in a separate issue – #2420.

The enhancement described in this issue is very abstract. Also, there are no other cases when it's necessary. So, this issue can be closed.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATE: Stale An outdated issue that will be automatically closed by the Stale bot. TYPE: enhancement The accepted proposal for future implementation.
Projects
None yet
Development

No branches or pull requests

9 participants