-
Notifications
You must be signed in to change notification settings - Fork 1k
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
TestReport customisation: How to get java method names at runtime for adding them in reports instead of TestNames #579
Comments
@cedricrefresh : Kindly please suggest a way |
To store data between methods you could use class TestClass {
final Object[] args;
@Factory(dataProvider="itenary")
TestClass(Object[] args) {this.args = args}
@Test
void homePage() ...;
@Test(dependsOn="homePage")
searchPage(data) ...;
@Test(dependsOn="searchPage")
bookingPage(data) ... ;
} But there exists another approaches, e.g. change method name in ITestResult, etc. |
@VladRassokhin : thanks for replying , i'm trying this and will update on the same. |
@VladRassokhin : I tried using Factory but it doesn't serve my purpose, here is my code
and the output is-
rather my desired output is [Since I want all the tests should run for the same data in one cycle]-
Please correct me if I have used Factory in wrong manor, also as per definition, factory is generally used for load testing to load same test multiple times, so I'm wondering how does it can fit my requirement ! |
My requirement is , when a test fails, so related enclosing method name should be displayed in test report |
@nullin @VladRassokhin @lukasj : anyone felt need of this and tried ! |
@cbeust : i'm naive at this, a little idea will help me achieve the custom requirement and if this feature is straight forward added in lib will definitely make it more usable . |
Using "ITestResult" also returns "testName" declared in testng xml file but not the java method called from the testMethod where the code had failed.
|
You can try: |
@juherr : this too returns "testBooking" the name of annoted method rather I'm looking for name like "homePage" or "searchPage" etc from wherever the call is transfered to the respective listener method (onTestFailure / onTestSuccess / onTestSkipped) |
@p00j4 Could you create a little and runnable project? That will be easier to understand. |
@juherr : thanks for taking time out, here is the code- https://github.com/p00j4/customReoprt |
Ok, I understand now. I never have to use it, but maybe FluentLenium could help you too. |
@p00j4 This piece of code will always give you the method name which is running currently inside @test method, like - homePage. And to get the current method name where exactly test case got failed you can use below code- |
Hi Cedric,
Thanks for writing this awesome piece.
I have a query....
At run time, how can I get the java method names called under a testMethod
ex. ITestContext/ITestResult exposes the testMethods mentioned in testNg.xml file [ but I want to get java methods which are not annotated and being called from any test annotated method].
Need:
@test(dataProvider="itenary")
public void testBooking(StringArray data){
homePage(data);
searchPage(data);
bookingPage(data);
}
Now if a test fails in bookingPage() flow then I want to show the method name bookingPage() in test report but not testBooking() [so that my report becomes more narrowed to understand which function caused the fail in entire booking flow testing]
similarly for all other methods
[but as per my current understanding I can just show the test method name]
What I tried: thought to have different tests for all above 3 methods but since I need same data from dataprovider to be passed in all, so It can't be possible.
Can you please suggest, any alternative or a object which exposes methods at run time , so that I can make my reports more relevant.
The text was updated successfully, but these errors were encountered: