Unable to Add class, test and nested step
saurabhsrivastava2009 opened this issue · 14 comments
Hi Team,
I am following the below structure to add data in ReportPortal, but after the all the data is getting added to the suite.
public static LaunchCreatedResponse _launchUuid;
public static TestItemCreatedResponse _testItemSuiteUuid;
public static TestItemCreatedResponse _testItemClassUuid;
public static TestItemCreatedResponse _testItemTestUuid;
public static TestItemCreatedResponse _testItemNestedUuid;
//Step 1 - Start Launch - Working
public async Task<LaunchCreatedResponse> StartLaunch()
{
Console.WriteLine("Starting the Launch");
if (!_currentProduct.Equals(_productPlatformName))
{
_currentProduct = _productPlatformName;
var launchResponse = await _service.Launch.StartAsync(new StartLaunchRequest
{
Name = Environment.GetEnvironmentVariable("RP_LAUNCH_NAME"),
Description = "Master Job Link:" + _masterJobLink + "\n" + "Product Job Link:" + _productJobLink,
Attributes = new List<ItemAttribute>()
{
new ItemAttribute { Key = "environment", Value = _environment },
new ItemAttribute { Key = "jobName", Value = _jobName }
},
Mode = LaunchMode.Default,
});
_launchUuid = launchResponse;
}
return _launchUuid;
}
//Step 2- Add Suite - Working
public async Task<TestItemCreatedResponse> AddSuite(LaunchCreatedResponse launchCreatedResponse)
{
var testItemSuite = await _service.TestItem.StartAsync(new StartTestItemRequest
{
LaunchUuid = launchCreatedResponse.Uuid,
Name = _productPlatformName,
Type = TestItemType.Suite,
Description = "This is the Suite for " + _productPlatformName
}
);
_testItemTestUuid = testItemSuite;
return _testItemTestUuid;
}
//Step 3 - Add items insise suite
public async Task<TestItemCreatedResponse> AddClass(LaunchCreatedResponse launchCreatedResponse,
TestItemCreatedResponse testItemCreatedResponseSuite)
{
string className = TestContext.CurrentContext.Test.ClassName;
_currentClassName = className;
if (!_currentClassName.Equals(_previousClassName))
{
var testItemClass = await _service.TestItem.StartAsync(new StartTestItemRequest
{
LaunchUuid = launchCreatedResponse.Uuid,
UniqueId = testItemCreatedResponseSuite.Uuid,
Name = className,
Type = TestItemType.Test,
Description = "CLASS_DESCRIPTION"
}
);
_previousClassName = className;
_testItemClassUuid = testItemClass;
}
return _testItemClassUuid;
}
Calling methods
Task<LaunchCreatedResponse> launchResponse = ReportPortalHelper.StartLaunch();
Task<TestItemCreatedResponse> suiteResponse = ReportPortalHelper.AddSuite(launchResponse.Result);
Task<TestItemCreatedResponse> classResponse = ReportPortalHelper.AddClass(launchResponse.Result, suiteResponse.Result);
Here step 1 and 2 are working as expected, but the step 3 is adding the item inside the launch instead of suite. Is there some key that I'm missing?
Thanks in advance!
I think you should use https://github.com/reportportal/client-net/blob/e32d461ec035c79bfcdeca1197ab48f463c0a30a/src/ReportPortal.Client/Abstractions/Resources/ITestItemResource.cs#L95C39-L95C39
where uuid
is a parent for your test.
Hi @nvborisenko
Thanks, that was indeed the solution and it worked.
But now the finish launch is not working. All the other closing/finishing stage is working, whereas launch finish is not working.
I'm using the following code to finish the launch and suite
public static async Task CloseSuiteAndLaunch(LaunchCreatedResponse launchCreatedResponse,
TestItemCreatedResponse testItemCreatedResponseSuite)
{
await _service.TestItem.FinishAsync(testItemCreatedResponseSuite.Uuid, new FinishTestItemRequest
{
LaunchUuid = launchCreatedResponse.Uuid,
});
await _service.TestItem.FinishAsync(launchCreatedResponse.Uuid, new FinishTestItemRequest());
}
As per the docs, I guess this is the way to go, but still can you let me know if I'm missing something here as well?
Thanks in advance :)
Any errors?
You probably forgot to finish a test before finishing suite.
@nvborisenko
I'm finishing all the test after adding them in the same method.
something like this
public static async Task<TestItemCreatedResponse> AddTest(LaunchCreatedResponse launchCreatedResponse,
TestItemCreatedResponse testItemCreatedResponseClass, string description, Status status)
{
string testName =
TestContext.CurrentContext.Test.Name.Contains("(") || TestContext.CurrentContext.Test.Name.Contains(" ")
? TestContext.CurrentContext.Test.MethodName
: TestContext.CurrentContext.Test.Name;
TestCaseCollection.Add(description, testName);
var testItemTest = await _service.TestItem.StartAsync(testItemCreatedResponseClass.Uuid,
new StartTestItemRequest
{
LaunchUuid = launchCreatedResponse.Uuid,
Name = testName,
Type = TestItemType.Step,
Description = description
}
);
_testItemTestUuid = testItemTest;
//Add nested item
var testItemNested = await _service.TestItem.StartAsync(testItemTest.Uuid,
new StartTestItemRequest
{
LaunchUuid = launchCreatedResponse.Uuid,
Name = testName,
Type = TestItemType.Step,
HasStats = false,
Description = description
}
);
_testItemNestedUuid = testItemNested;
//close nested item and test item
CloseNestedAndTestStep(launchCreatedResponse, testItemNested, testItemTest, status);
return _testItemNestedUuid;
}
private static async Task CloseNestedAndTestStep(LaunchCreatedResponse launchCreatedResponse,
TestItemCreatedResponse testItemCreatedResponseNested, TestItemCreatedResponse testItemCreatedResponseTest,
Status status)
{
await _service.TestItem.FinishAsync(testItemCreatedResponseNested.Uuid, new FinishTestItemRequest
{
Status = status,
LaunchUuid = launchCreatedResponse.Uuid
});
await _service.TestItem.FinishAsync(testItemCreatedResponseTest.Uuid, new FinishTestItemRequest
{
Status = status,
LaunchUuid = launchCreatedResponse.Uuid
});
}
Any errors? What is a problem?
It doesn't throw any error as I can see in logs, it closes the suite but not the launch. I have to force close it via UI
You don't await CloseNestedAndTestStep
method invocation.
sorry didn't get you. Can you explain a bit more
//close nested item and test item
await CloseNestedAndTestStep(launchCreatedResponse, testItemNested, testItemTest, status);
You missed await
keyword.
okay, let me try with that
@nvborisenko it did not work. :(
Then create simple project with code to reproduce your issue.
@nvborisenko I debugged the code and it seems like there is a bug in code
For finishing a launch the endpoint should be v1/{{launchUuid}}/finish
whereas here the URI is resolved as an item as can be seen in below screenshot v1/{{projectName}}/item/{{launchUuid}}
The code I'm using for finishing a launch is
public static async Task FinishLaunch(LaunchCreatedResponse launchCreatedResponse)
{
await _service.TestItem.FinishAsync(launchCreatedResponse.Uuid, new FinishTestItemRequest());
}
If you want to finish launch, then use _service.Launch.FinishAsync
, not TestItem.FinishAsync()
.
More complex examples are located here: https://github.com/reportportal/client-net/tree/develop/test/ReportPortal.Client.IntegrationTests
Feel free to open new issue if some example doesn't work. Thanks.