-
Notifications
You must be signed in to change notification settings - Fork 659
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
Comments
Reference: #2823 |
Just curious do we have a timeline for this feature? |
@sophiecdd |
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. |
I should point out that I've seen the command line pattern option, Even if we used the If you can see a way around this, I'm open to suggestions. |
@icfantv 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 hope this helps :) |
@devmondo we are using would you like me to update the typings or is this an "unpublished" API and thus, fragile? |
@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 |
@devmondo did you happen to get your example working in typescript without jumping through all kinds of hoops? |
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
console.log(t.testRun.test.name); |
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. |
Hi @xorxero Thank you for sharing your test cases. We will take them into account when designing an API for this feature. |
bumping could really use this |
Release v3.0.0-rc.1 addresses this. |
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.
The text was updated successfully, but these errors were encountered: