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

Allow to use test and fixture names inside hooks and test bodies #2826

Closed
AndreyBelym opened this issue Sep 6, 2018 · 14 comments
Closed

Allow to use test and fixture names inside hooks and test bodies #2826

AndreyBelym opened this issue Sep 6, 2018 · 14 comments
Assignees
Labels
AREA: server FREQUENCY: level 2 SYSTEM: API TYPE: enhancement The accepted proposal for future implementation.

Comments

@AndreyBelym
Copy link
Contributor

Are you requesting a feature or reporting a bug?

Feature

What is the current behavior?

You can't access current test and fixture name from the test code.

What is the expected behavior?

Current test and fixture name can be retrieved by the code running in before/after hooks and the test body function.

@jiteshsojitra
Copy link

Reference: #2823

@sophiecdd
Copy link

Just curious do we have a timeline for this feature?

@LavrovArtem
Copy link
Contributor

LavrovArtem commented Dec 4, 2018

@sophiecdd
I'm unable to provide you with any time frame as any personal estimate may be misleading. Once we get any results, I assure you that we will notify you.

@AndreyBelym AndreyBelym added TYPE: enhancement The accepted proposal for future implementation. and removed TYPE: proposal labels Feb 6, 2019
@AndreyBelym AndreyBelym added this to Test API Suggestions in Enhancements processing Mar 1, 2019
@icfantv
Copy link

icfantv commented Aug 13, 2019

Hi, any update on this? We're doing image snapshot testing in TC and currently this is limiting us to one snapshot test per file since we're using the test file name to name the snapshot image files. The workaround of using a wrapper function is just not going to scale effectively, though, we could create a utility function that does it implicitly...

At face value, this appears to be a trivial feature. I'm happy to look into this and submit a PR if you guys can point me in the right direction.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Aug 13, 2019
@icfantv
Copy link

icfantv commented Aug 13, 2019

I should point out that I've seen the command line pattern option, -p, and I 1) I don't feel this is necessarily the right way to be doing this, but more importantly, 2) we're generating a baseline image (one that ends in -baseline.png if one doesn't yet exist and a snapshot image (one that ends in -snapshot.png if it does so we can compare/diff the two images.

Even if we used the -p flag, there's no way for us to test for the existence of the baseline image file without knowing the test name in the test.

If you can see a way around this, I'm open to suggestions.

@devmondo
Copy link

devmondo commented Aug 13, 2019

@icfantv
you can certainly get the fixture and test name in code, but it is not in the API typings

you can do it like this:

fixture `Fixture 1`
    .page `https://google.com`;

test('Test 1', async t => {
    console.log(t.testRun.test.name);
    console.log(t.testRun.test.testFile.currentFixture.name);
  });

we do it to also use the name in logging, screenshots, etc...

also, you are not limited to the runner screenshot, you can use t.takeScreenshot to take a screenshot at any given time, we do that to use it with allure reporting.

hope this helps :)

@icfantv
Copy link

icfantv commented Aug 13, 2019

@devmondo we are using t.takeScreenshot and specifying the image path. but your solution is perfect and should work accordingly. thanks!

would you like me to update the typings or is this an "unpublished" API and thus, fragile?

@devmondo
Copy link

@icfantv, glad it helped :)

i am not part of the testcafe team, and I think this is not intended for public API, which makes sense because it has soo much info about the whole process.

but I think it is really a good idea if the testcafe team can expose a meta-object on the test and fixture api to get this sort of info, something like t.info or t.metaInfo.

@miherlosev miherlosev removed the STATE: Need response An issue that requires a response or attention from the team. label Aug 14, 2019
@icfantv
Copy link

icfantv commented Aug 22, 2019

@devmondo did you happen to get your example working in typescript without jumping through all kinds of hoops?

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Aug 22, 2019
@miherlosev miherlosev removed the STATE: Need response An issue that requires a response or attention from the team. label Aug 23, 2019
@devmondo
Copy link

devmondo commented Aug 23, 2019

@icfantv

basically you have to add custom typing to your project, something like

declare global {
    interface TestController {
        testRun: {
            name: string;
        };
    }
}

https://www.typescriptlang.org/docs/handbook/declaration-merging.html

or if you are lazy :) add
// @ts-ignore

// @ts-ignore
console.log(t.testRun.test.name);

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Aug 23, 2019
@Dmitry-Ostashev Dmitry-Ostashev removed the STATE: Need response An issue that requires a response or attention from the team. label Aug 26, 2019
@xorxero
Copy link

xorxero commented Aug 26, 2020

why is this not a thing? this is basic functionality. we can selectively run beforeEach logic or only a subet of the beforeEach logic based on test name...

the meta we assign to the test should also be available through the test controller in the before each hook.

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

Hi @xorxero

Thank you for sharing your test cases. We will take them into account when designing an API for this feature.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Aug 27, 2020
@AndreyBelym AndreyBelym added STATE: Stale An outdated issue that will be automatically closed by the Stale bot. and removed STATE: Stale An outdated issue that will be automatically closed by the Stale bot. labels Oct 19, 2020
@jasongornall
Copy link

bumping could really use this

@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 2, 2021
@Farfurix Farfurix removed the STATE: Need response An issue that requires a response or attention from the team. label Feb 3, 2021
@Artem-Babich Artem-Babich self-assigned this May 29, 2023
Enhancements processing automation moved this from Test API Suggestions to Closed Jun 7, 2023
@github-actions
Copy link

github-actions bot commented Jun 8, 2023

Release v3.0.0-rc.1 addresses this.

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: API TYPE: enhancement The accepted proposal for future implementation.
Projects
No open projects
Development

No branches or pull requests