Page 1 of 1

Unable to attach PDF report using Ranorex task in Azure DevOps

Posted: Tue Jul 06, 2021 4:48 pm
by raygoel
Hi,

I am running a test suite using Azure DevOps and Ranorex task. The tests run fine and the report gets attached as an artifact. However, the report shows up as .rxzlog file. I have included Report to PDF module in the teardown section and it works fine locally. I have two questions:

1. When using an Azure agent to run Ranorex tests, where are the report files stored on the agent? Are they retained or are they deleted automatically once they are uploaded as an artifact?

2. Is there a way to find out if the Report to PDF module triggered successfully when running the tests through Azure pipeline?

Any help is appreciated. The stakeholders who want to view this report do not have Ranorex studio installed on their machines and there is no way for them to open rxzlog files.

Thanks,
Ray

Re: Unable to attach PDF report using Ranorex task in Azure DevOps

Posted: Fri Jul 09, 2021 10:16 pm
by Jacob
Hi raygoel,

By default, the pdf is generated and placed into the Report folder. For an Azure Agent job, this is typically stored in the Azure Agent's directory. The most recent copy of the test is stored until the test is run again from the agent. For me, this path is:

Code: Select all

C:\Azure\AzureAgent\_work\1\s\Reports
This is because I have an Azure directory where I installed the Azure Agent (in a folder called AzureAgent) on the root of my C: drive. All temporary files are stored in _work\1\s. From there, the structure will depend on where you set your Report directory in the Ranorex Settings for that solution (or if you change the directory via the command line when the Azure Agent runs the job).

To your second point. Another possibility would be to use the EmailModule in the automation helpers to attach the generated PDF and send it via email to the necessary DL. I hope this information helps!

--Jacob

Re: Unable to attach PDF report using Ranorex task in Azure DevOps

Posted: Tue Jul 13, 2021 12:03 pm
by mrt
Hey,

I have the same issue of not being able to get a PDF report attached as build artifact.
The rxzlog is pretty much useless there, because no one who watches the pipeline result has Ranorex installed, so noone could view the report file.
By default, the pdf is generated and placed into the Report folder.
Hmm.
In my local studio installation, there is a Reports folder inside bin/Debug.
But for pipeline agent directory, there is no reports folder at all inside ..\_work\1\s.
I have just added the official Ranorex build task.

When checking the pipeline output I noticed that Ranorex builds everything in its temp folder located in
C:\Users\myuser\AppData\Local\Temp\2\Ranorex\BuildTask\8b7278c9-6c0a-4754-ac6a-2dd66f3ff22b\
where I could also find the PDF reports (directly in this folder, no 'Reports' subfolder).

But, how do I get this PDF report attached to the pipeline artifacts?

@Jacob
Are you using the official Ranorex Studio build task as mentioned here:
https://www.ranorex.com/help/latest/int ... -pipeline/
or did you create the pipeline with all tasks on your own?

Did you set any special attributes in the TestSuite properties for the Report?
I have not checked the "Single Report" inside there:
2021-07-13 12_59_57-E2E_1_Project_Workflow properties.png
but when I check it, then (and only then) a 'Reports' is created inside the AppData/Local/Temp dir...which does not help either.

Please enlighten us. :D

thanks, BR mrt

Re: Unable to attach PDF report using Ranorex task in Azure DevOps

Posted: Wed Jul 14, 2021 9:05 am
by odklizec
Hi guys,

Well, if you want to attach the rxzlog (PDF or whatever file) to test summary, then I'm afraid, it's not an easy task ;) Here is the PowerShell script I'm using...

Code: Select all

  - task: PowerShell@2
    displayName: Attach Ranorex report to test summary
    env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken)
    inputs:
      continueOnError: true
      targetType: 'inline'
      script: |
        #$AzureDevOpsPAT = "YourPersonalAccessToken"
        #$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)"))}
        $AzureDevOpsAuthenicationHeader = @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
        # Build Id
        Write-Host "buildID: $(Build.BuildId)"
        $url = 'https://PathToYourAzureProject/_apis/test/ResultDetailsByBuild?buildId=$(Build.BuildId)'
        $response = Invoke-RestMethod -Uri $url -Headers $AzureDevOpsAuthenicationHeader -Method Get
        Write-Host "response = $($response)"
        # get test run Id
        $testRunId = $($response.resultsForGroup.results[0].testRun.id)
        Write-host "test run number = $($testRunId)"
        # convert file to base64 string
        $base64string = [System.Convert]::ToBase64String([IO.File]::ReadAllBytes("$(System.DefaultWorkingDirectory)\Reports\$(rxzlogFile)"))
        Write-host "Converted string = $($base64string)"
        # create request body
        $BuildReqBody= @{stream=$base64string;fileName="$(rxzlogFile)";comment="Ranorex report";attachmentType="GeneralAttachment"}
        $BuildReqBodyJson = $BuildReqBody | ConvertTo-Json -Compress
        # attach report to test run
        $htmlReportFile = Invoke-RestMethod -Uri "https://PathToYourAzureProject/_apis/test/Runs/$testRunId/attachments?api-version=6.0-preview.1" -Method Post -ContentType 'application/json' -Body $BuildReqBodyJson -Headers $AzureDevOpsAuthenicationHeader
It was a painful experience to find out correct voodoo spells ;)

Re: Unable to attach PDF report using Ranorex task in Azure DevOps

Posted: Wed Jul 14, 2021 10:40 am
by mrt
Hmm ok, I wanted to avoid such usage of scripts, because later on I will have to maintain them. :D
From a quick look I also noticed that you read from
System.DefaultWorkingDirectory)\Reports\
which I am afraid will fail, because I have no "Reports" in the DefaultWorkingDirectory.

Attaching the rxzlog is easy, it is done automatically by the official ranorex build task:
pipeline.png
artifacts.png
I would rather prefer a "Copy files" and Publish files pipeline task for attaching the PDF report to the summary, it is easier to maintain I would say.
It should be possible, the manual pipeline configuration (without the official build task) seems to do it in that way.
But I have way to little experience with ADO to be able to adjust this to my needs...

Edit: something weird is going on when trying to attach 2 pictures to the post, I cannot delete the double attachment, sorry ...

Re: Unable to attach PDF report using Ranorex task in Azure DevOps

Posted: Wed Jul 14, 2021 11:15 am
by odklizec
Hi,

Well, I was not quite sure about where exactly you want to attach the file. The solution I'm using attaches Ranorex report to Test Plans >> Runs:
TestRuns.png

Re: Unable to attach PDF report using Ranorex task in Azure DevOps

Posted: Tue Aug 03, 2021 12:22 pm
by mrt
Hey,

yes, but you are just uploading the rxlog (resp. rxzlog) file, but no PDF, right?

When I watch the Azure output of the official Ranorex task, the report is created in the "BuildTask" directory, which changes from run to run and looks like:

Code: Select all

C:\Users\myuser\AppData\Local\Temp\Ranorex\BuildTask\bd34b1f6-fa4d-44a6-97b0-16c82129e04f\myreport.rxzlog
Also then the PDF is created directly beside this report,
and also the upload to the Azure build artifacts is done from this directory.

So, what I currently do is:
  • Let the build task upload the rxzlog from the directory in AppData\Local
  • Download the rxzlog from Azure to System.ArtifactsDirectory
  • Run manual PDF convert to (re)create the PDF
  • Upload the PDF to Azure
This works, but it is inefficient (needs 3 extra tasks in the pipeline and upload/downloads back and forth)
and painful (even just to describe these steps :lol: ), because the PDF is already there, I just can't access it.

Does anyone have an idea how to get the BuildTask folder mentioned above dynamically, so I can just upload the PDF that is already there?

thanks!

Re: Unable to attach PDF report using Ranorex task in Azure DevOps

Posted: Fri Nov 18, 2022 2:45 am
by Baxter
Since the buildtask folder is dynamic, the only solution i found was set ranorex to publish the PDF to a static directory (overwrite previous file) and use another azure devops task called "publish pipeline artifacts", to publish that whole directory to the artifacts. see images attached...

Re: Unable to attach PDF report using Ranorex task in Azure DevOps

Posted: Fri Nov 18, 2022 6:53 pm
by Baxter
so currently with Ranorex 10.4, if you chose to include Video in the PDF report, the pipelines will fail to output the pdf report to the artifacts. This is a bug with Ranorex, has nothing to do with AZURE. I'll post it to the bug section.

Re: Unable to attach PDF report using Ranorex task in Azure DevOps

Posted: Fri Nov 18, 2022 7:36 pm
by Baxter
Here's how it displays in the artifacts section