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 a way to pass settings from runner to fixtures #2431

Closed
fpoppinga opened this issue May 17, 2018 · 4 comments
Closed

Provide a way to pass settings from runner to fixtures #2431

fpoppinga opened this issue May 17, 2018 · 4 comments
Labels
AREA: server FREQUENCY: level 2 SYSTEM: runner TYPE: enhancement The accepted proposal for future implementation.
Milestone

Comments

@fpoppinga
Copy link

Feature Request

Provide a way to pass configuration from Runner to test fixtures.

What is the current behavior?

There is no way to pass any information from the TestCafé runner to the actual tests.

What is the expected behavior?

For our use case, we want to provide different configuration from various sources to the tests on a per-execution basis. This means that e.g. configuration files as proposed here are not a viable option.

It would be great, if you could pre-fill the fixture context fixtureCtx from the TestCafé runner, like so:

const tc = await createTestCafe();
const runner = tx.createRunner();

await runner
  .src(myFiles)
  .browsers(myBrowsers)
  .fixtureContext({
    mySetting: getSomeValueSomehow()
  })
  .run();

resulting in this test fixtures:

fixture("My fixture")
  .before(fixtureCtx => {
    // fixtureCtx now equals 
    // {mySetting: ...}
  });
@miherlosev miherlosev added this to the Planned milestone May 17, 2018
@miherlosev miherlosev added TYPE: enhancement The accepted proposal for future implementation. SYSTEM: runner AREA: server labels May 17, 2018
@AndreyBelym
Copy link
Contributor

Hi @fpoppinga, you can use process.env to pass strings from runner to test code.

@fpoppinga
Copy link
Author

@AndreyBelym, yes I know, but in my opinion a) process.env is not meant to be used this way, b) this works rather badly for more complex configuration data.

@Asuza
Copy link

Asuza commented Mar 30, 2020

I too would like to see this feature. I see no other good way to run the same test from two or more different runners with different configuration options. process.env does technically work, but it's hacky and can cause the test to get settings from the wrong runner.

@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 30, 2020
@AlexanderMoiseev AlexanderMoiseev removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 31, 2020
@AndreyBelym AndreyBelym added STATE: Stale An outdated issue that will be automatically closed by the Stale bot. FREQUENCY: level 2 and removed STATE: Stale An outdated issue that will be automatically closed by the Stale bot. labels Oct 19, 2020
@Artem-Babich
Copy link
Contributor

Hi, you can use userVariables to pass additional data to the tests. You can define them in the configuration file as well as in your runner code:
createTestCafe({userVariables: { url: 'test' }})

import { userVariables } from 'testcafe';

fixture `Test user variables`

test('Type text', async t => {
    await t.expect(userVariables.url).eql('test')
});

Feel free to reopen this issue if this approach cannot be used in your usage scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AREA: server FREQUENCY: level 2 SYSTEM: runner TYPE: enhancement The accepted proposal for future implementation.
Projects
None yet
Development

No branches or pull requests

6 participants