Skip to content

Page object methods that use test controller throw error when called in before #2572

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

Closed
qualityshepherd opened this issue Jun 28, 2018 · 4 comments
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot.

Comments

@qualityshepherd
Copy link

Are you requesting a feature or reporting a bug?

Either a bug with my brain or the app... or perhaps a feature request :)

What is the current behavior?

I'm calling a page object method goto that builds/alters an url and then uses await t.navigateTo(url) to goto the page. This works fine within a test or beforeEach, but not in a before. It throws:

Cannot implicitly resolve the test run in the context of which the test controller action should be executed. Use test function's 't'
      argument instead.

What is the expected behavior?

I can kinda see why this might be, but I want this to work. Writing tests this way allows me to decouple tests from one another, especially ones with long, slow, setups. Ie. in my before, I'd login, setup any data I need, then run a number of tests. Calling this in one of the tests couples all tests to that test. I could use the beforeOnce hack as noted in #1345... but... hacky.

How would you reproduce the current behavior (if this is a bug)?

myPageObject method

async goto(url) {
    // url building magic here
    await t.navigateTo(url);
}

Test

...
fixture `Url Sadness`
    .before(async t => {
        await myPageObject.goto(url);
    }
    
#### Provide the test code and the tested page URL (if applicable)

Tested page URL:

Test code
:point_up:

### Specify your

* operating system: macos latests
* testcafe version: 0.20.3
* node.js version: latest lts
@AndreyBelym
Copy link
Contributor

Hi @qualityshepherd, the fixture.before and fixture.after hooks are designed for server-side test environment setup actions and are executed before a test page is loaded in a browser. It means you can't use a test controller in these hooks, check the documentation.

@AndreyBelym
Copy link
Contributor

You can take this approach to execute fixture.beforeEach only once.

@qualityshepherd
Copy link
Author

Yeah, that would be the hacky I spoke of above... figured.

@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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot.
Projects
None yet
Development

No branches or pull requests

2 participants