0

How to get the test name from the below line using powershell script?

<UnitTestResult executionId="200af923-6299-5624-0558-933a879a4851" testId="0908f758-64a1-ad61-6b63-9acfda6ddf9c" testName="atmentRelatedInformationComponent setTreatmentRowItem: should not set the report Id  to the IReport model if report id is missing or isReportAvailable" computerName="INBLRH11651WSPR" duration="00:00:00.011" startTime="2021-06-15T17:50:00.642Z" endTime="2021-06-15T17:50:00.642Z" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d"/>
1
  • 1
    What have you tried, and how has what you've tried failed? Ideally, you should provide a minimal reproducible example of what you've tried, and include specific information on how it failed, with error messages and/or erroneous output. Stack Overflow is not a code-writing service; the best questions are those which provide useful information so that those who answer can guide you to devising your own correct answer. See How to Ask a Good Question. Commented Jun 28, 2021 at 13:17

1 Answer 1

2

The input string is technically a complete XML document, so you could do:

$xml = [xml]@'
<UnitTestResult executionId="200af923-6299-5624-0558-933a879a4851" testId="0908f758-64a1-ad61-6b63-9acfda6ddf9c" testName="atmentRelatedInformationComponent setTreatmentRowItem: should not set the report Id  to the IReport model if report id is missing or isReportAvailable" computerName="INBLRH11651WSPR" duration="00:00:00.011" startTime="2021-06-15T17:50:00.642Z" endTime="2021-06-15T17:50:00.642Z" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d"/>
'@

# This will result in the test name
$xml.UnitTestResult.testName
Sign up to request clarification or add additional context in comments.

3 Comments

@AvinVerma Then do it once for each line.
This line is a part of one trx file, there is multiple lines like that in the file.
Is there any way to get test name without converting it into xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.