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

before & after hooks for a fixture #903

Closed
vutenkov opened this issue Oct 20, 2016 · 10 comments
Closed

before & after hooks for a fixture #903

vutenkov opened this issue Oct 20, 2016 · 10 comments
Assignees
Labels
API MODIFICATION LEVEL: non-breaking changes AREA: server STATE: Auto-locked An issue has been automatically locked by the Lock bot. SYSTEM: API SYSTEM: runner TYPE: enhancement The accepted proposal for future implementation.
Milestone

Comments

@vutenkov
Copy link

Are you requesting a feature or reporting a bug?

Requesting a feature.

What is the current behavior?

There is no ability to run some setup/tear down code before/after all tests in a fixture.

What is the expected behavior?

To have such the ability.

Provide the test code and the tested page URL (if applicable)

Test code

fixture('My cool fixture')
    .before(() => {
        // do something that needs to be done once _before_ all tests
    })
    .after(() => {
        // do something that needs to be done once _after_ all tests
    })
@inikulin inikulin added TYPE: enhancement The accepted proposal for future implementation. SYSTEM: API SYSTEM: runner AREA: server labels Oct 20, 2016
@inikulin inikulin added this to the Planned features milestone Oct 20, 2016
@inikulin inikulin modified the milestones: Sprint #3, Planned features Dec 9, 2016
@inikulin inikulin self-assigned this Jan 2, 2017
@inikulin inikulin modified the milestones: Planned features, Sprint #3 Jan 9, 2017
@inikulin
Copy link
Contributor

inikulin commented Jan 9, 2017

I was hoping to implement this feature in current sprint, however once I've got my hands on it, it appeared that it's not as simple as it seems. Most problems are related to consistency with fixture.beforeEach, test.after, etc. hooks. Those hooks are run in each browser for each test run for the test, also they have a test controller object t provided. It seems that it's not a case for fixture.before and fixture.after hooks. I can't figure out a scenario there we'll need to run it on page. While fixture.beforeEach hooks are usable e.g. to perform authentication, for fixture.before it doesn't makes sense, since test state is not shared between tests. More likely fixture.before will be sued to deal with database or website itself and should be run before any test page is loaded, so made action will take effect on loaded page. Also, unlike e.g. test.before such hook should be run only once. With all those things in mind, I propose the following:

  • Call new hooks fixture.setup, fixture.teardown, test.setup, test.teardown to make them distinguishable from after... and before.. hooks.

  • Those hooks will be run once for each test or fixture, and in case of setup hooks, before tested page is loaded for the first time.

  • Each new hook will accept ctx object that can be used to share data between hooks. ctx object passed to before... and after... hooks will have setup ctx as a prototype, so you'll be able to access and modify properties created by setup hook in tests, but properties added in test will not be seen e.g. by teardown hook.

\cc @DevExpress/testcafe @vladimirutenkov

@helen-dikareva
Copy link
Collaborator

Setup and teardown will executed once for fixture/test and before.../after... will executed each time in quarantine mode , is that right?

@inikulin
Copy link
Contributor

inikulin commented Jan 9, 2017

@helen-dikareva If we have a test that run in 3 browsers, before/after will be executed 3 times, once per each browser. setup/teardown will be executed only once unrelated to the number of browsers specified for the task.

@helen-dikareva
Copy link
Collaborator

ok, I see

@kirovboris
Copy link
Collaborator

The teardown handler will be run after a fixture or test passed/failed in all browsers, right?
+1 in this case. In my opinion it's still not clear, that it will be run once, e.g. if I write test.setup first time, i'll expect it will execute several times, because I'll met the famous term setup and will be think, that it's occur for every test run, in other words for each browser. If I met term e.g. setupOnce instead of setup, I'd would tried to know what does it do.

@inikulin
Copy link
Contributor

inikulin commented Jan 9, 2017

@kirovboris How about fixture.beforeAll and fixture.afterAll? But test.setup/teardown doesn't fit in this paradigm then.

@kirovboris
Copy link
Collaborator

kirovboris commented Jan 9, 2017

From these two options (beforeAll/afterAll and setup/teardown) I prefer the second one. We already have beforeEach ...test, so beforeAll will be associated with tests for me as well, not browsers.

@inikulin
Copy link
Contributor

inikulin commented Jan 9, 2017

We already have beforeEach ...test, so beforeAll will be associated with tests for me as well, not browsers.

Indeed, it has nothing to do with browsers, so it will be correct association

@inikulin inikulin modified the milestones: Sprint #4, Planned features Jan 23, 2017
@inikulin
Copy link
Contributor

inikulin commented Jan 31, 2017

TODO

  • Basic functionality
  • Skipped tests
  • Shared context object

@lock
Copy link

lock bot commented Mar 28, 2019

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

@lock lock bot added the STATE: Auto-locked An issue has been automatically locked by the Lock bot. label Mar 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 28, 2019
kirovboris pushed a commit to kirovboris/testcafe-phoenix that referenced this issue Dec 18, 2019
…) (DevExpress#1214)

* Implement fixture.before and fixture.after hooks (closes DevExpress#903)

* Fix functional test

* Make linter happy

* Try fix tests

* Try fix tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API MODIFICATION LEVEL: non-breaking changes AREA: server STATE: Auto-locked An issue has been automatically locked by the Lock bot. SYSTEM: API SYSTEM: runner TYPE: enhancement The accepted proposal for future implementation.
Projects
None yet
Development

No branches or pull requests

6 participants