-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathUiPathRunTest.ps1
More file actions
397 lines (334 loc) · 16.8 KB
/
UiPathRunTest.ps1
File metadata and controls
397 lines (334 loc) · 16.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<#
.SYNOPSIS
Test a given package or run a test set
.DESCRIPTION
Test a given package or run a test set in orchestrator
.PARAMETER project_path
The path to a test package file.
.PARAMETER input_path
The full path to a JSON input file. Only required if the entry-point workflow has input parameters and you want to pass them from command line.
.PARAMETER testset
The name of the test set to execute. The test set should use the latest version of the test cases. If the test set does not belong to the default folder (organization unit) it must be prefixed with the folder name, e.g. AccountingTeam\TestSet
.PARAMETER orchestrator_url
Required. The URL of the Orchestrator instance.
.PARAMETER orchestrator_tenant
Required. The tenant of the Orchestrator instance.
.PARAMETER result_path
Results file path
.PARAMETER accountForApp
The Orchestrator CloudRPA account name. Must be used together with id, secret and scope(s) for external application.
.PARAMETER applicationId
The external application id. Must be used together with account, secret and scope(s) for external application.
.PARAMETER applicationSecret
The external application secret. Must be used together with account, id and scope(s) for external application.
.PARAMETER applicationScope
The space-separated list of application scopes. Must be used together with account, id and secret for external application.
.PARAMETER orchestrator_user
Required. The Orchestrator username used for authentication. Must be used together with the password.
.PARAMETER orchestrator_pass
Required. The Orchestrator password used for authentication. Must be used together with the username
.PARAMETER UserKey
Required. The Orchestrator OAuth2 refresh token used for authentication. Must be used together with the account name and client id.
.PARAMETER account_name
Required. The Orchestrator CloudRPA account name. Must be used together with the refresh token and client id.
.PARAMETER folder_organization_unit
The Orchestrator folder (organization unit).
.PARAMETER environment
The environment to deploy the package to. Must be used together with the project path. Required when not using a modern folder.
.PARAMETER timeout
The time in seconds for waiting to finish test set executions. (default 7200)
.PARAMETER out
Type of result file
.PARAMETER language
The orchestrator language.
.PARAMETER disableTelemetry
Disable telemetry data.
.PARAMETER uipathCliFilePath
if not provided, the script will auto download the cli from uipath public feed. the script was testing on version 22.10.8432.18709. if provided, it is recommended to have cli version 22.10.8432.18709
.PARAMETER attachRobotLogs
Attaches Robot Logs for each testcases along with Junit Test Report.
.PARAMETER repositoryUrl
Repository url where project is versioned.
.PARAMETER repositoryCommit
Repository commit where the project was built from.
.PARAMETER repositoryBranch
Repository branch where the project was built from.
.PARAMETER repositoryType
VCS system repository type.
.PARAMETER projectUrl
Automation Hub idea URL.
.PARAMETER identityUrl
Url of your identity server. This is only required for PaaS deployments.
.EXAMPLE
SYNTAX
.\UiPathRunTest.ps1 <orchestrator_url> <orchestrator_tenant> [-input_path <input_path>] [-project_path <package>] [-testset <testset>] [-orchestrator_user <orchestrator_user> -orchestrator_pass <orchestrator_pass>] [-UserKey <auth_token> -account_name <account_name>] [-accountForApp <account_for_app> -applicationId <application_id> -applicationSecret <application_secret> -applicationScope <applicationScope>] [-environment <environment>] [-folder_organization_unit <folder_organization_unit>] [-language <language>]
Examples:
.\UiPathRunTest.ps1 -orchestrator_url "https://uipath-orchestrator.myorg.com" -orchestrator_tenant default -orchestrator_user admin -orchestrator_pass 123456 -testset "MyRobotTests"
.\UiPathRunTest.ps1 -orchestrator_url "https://uipath-orchestrator.myorg.com" -orchestrator_tenant default -orchestrator_user admin -orchestrator_pass 123456 -project_path "C:\UiPath\Project\project.json" -environment TestingEnv
.\UiPathRunTest.ps1 -orchestrator_url "https://uipath-orchestrator.myorg.com" -orchestrator_tenant default -orchestrator_user admin -orchestrator_pass 123456 -project_path "C:\UiPath\Project\project.json" -folder_organization_unit MyFolder
.\UiPathRunTest.ps1 -orchestrator_url "https://uipath-orchestrator.myorg.com" -orchestrator_tenant default -orchestrator_user admin -orchestrator_pass 123456 -project_path "C:\UiPath\Project\project.json" -folder_organization_unit MyFolder -environment MyEnvironment
.\UiPathRunTest.ps1 -orchestrator_url "https://uipath-orchestrator.myorg.com" -orchestrator_tenant default -accountForApp myAccountForExternalApp -applicationId myExternalAppId -applicationSecret myExternalAppSecret -applicationScope "OR.Folders.Read OR.Settings.Read" -testset "MyRobotTests"
.\UiPathRunTest.ps1 -orchestrator_url "https://uipath-orchestrator.myorg.com" -orchestrator_tenant default -UserKey a7da29a2c93a717110a82 -account_name myAccount -testset "MyRobotTests"
.\UiPathRunTest.ps1 -orchestrator_url "https://uipath-orchestrator.myorg.com" -orchestrator_tenant default -UserKey a7da29a2c93a717110a82 -account_name myAccount -project_path "C:\UiPath\Project\project.json" -environment TestingEnv --out junit
.\UiPathRunTest.ps1 -orchestrator_url "https://uipath-orchestrator.myorg.com" -orchestrator_tenant default -UserKey a7da29a2c93a717110a82 -account_name myAccount -project_path "C:\UiPath\Project\project.json" -environment TestingEnv -result_path "C:\results.json" -out uipath -language en-US
.\UiPathRunTest.ps1 -orchestrator_url "https://uipath-orchestrator.myorg.com" -orchestrator_tenant default -UserKey a7da29a2c93a717110a82 -account_name myAccount -project_path "C:\UiPath\Project\project.json" -environment TestingEnv -result_path "C:\results.json" -input_path "C:\UiPath\Project\input-params.json" -out uipath -language en-US
#>
Param (
#Required
[string] $orchestrator_url = "", #Required. The URL of the Orchestrator instance.
[string] $orchestrator_tenant = "", #Required. The tenant of the Orchestrator instance.
[string] $project_path = "", #The path to a test package file.
[string] $input_path = "", #The full path to a JSON input file. Only required if the entry-point workflow has input parameters and you want to pass them from command line.
[string] $testset = "", #The name of the test set to execute. The test set should use the latest version of the test cases. If the test set does not belong to the default folder (organization unit) it must be prefixed with the folder name, e.g. AccountingTeam\TestSet
[string] $result_path = "", #Results file path
#External Apps (Option 1)
[string] $accountForApp = "", #The Orchestrator CloudRPA account name. Must be used together with id, secret and scope(s) for external application.
[string] $applicationId = "", #Required. The external application id. Must be used together with account, secret and scope(s) for external application.
[string] $applicationSecret = "", #Required. The external application secret. Must be used together with account, id and scope(s) for external application.
[string] $applicationScope = "", #Required. The space-separated list of application scopes. Must be used together with account, id and secret for external application.
#API Access - (Option 2)
[string] $account_name = "", #Required. The Orchestrator CloudRPA account name. Must be used together with the refresh token and client id.
[string] $UserKey = "", #Required. The Orchestrator OAuth2 refresh token used for authentication. Must be used together with the account name and client id.
#On prem - Required
[string] $orchestrator_user = "", #Required. The Orchestrator username used for authentication. Must be used together with the password.
[string] $orchestrator_pass = "", #Required. The Orchestrator password used for authentication. Must be used together with the username
[string] $folder_organization_unit = "", #The Orchestrator folder (organization unit).
[string] $language = "", #-l, --language The orchestrator language.
[string] $environment = "", #The environment to deploy the package to. Must be used together with the project path. Required when not using a modern folder.
[string] $disableTelemetry = "", #-y, --disableTelemetry Disable telemetry data.
[string] $timeout = "", # The time in seconds for waiting to finish test set executions. (default 7200)
[string] $out = "", #Type of result file
[string] $traceLevel = "",
[string] $uipathCliFilePath = "", #if not provided, the script will auto download the cli from uipath public feed. the script was testing on version 23.10.8753.32995.
[string] $SpecificCLIVersion = "", #CLI version to auto download if uipathCliFilePath not provided. Default is "23.10.8753.32995" where the script was last tested,
[string] $attachRobotLogs = "", #Attaches Robot Logs for each testcases along with Junit Test Report.
[string] $repositoryUrl = "", #Repository url where project is versioned.
[string] $repositoryCommit = "", # Repository commit where the project was built from.
[string] $repositoryBranch = "", # Repository branch where the project was built from.
[string] $repositoryType = "", # VCS system repository type.
[string] $projectUrl = "", # Automation Hub idea URL.
[string] $identityUrl = "", #Url of your identity server. This is only required for PaaS deployments.
[Parameter(ValueFromRemainingArguments = $true)]
$remainingArgs
)
function WriteLog
{
Param ($message, [switch] $err)
$now = Get-Date -Format "G"
$line = "$now`t$message"
$line | Add-Content $debugLog -Encoding UTF8
if ($err)
{
Write-Host $line -ForegroundColor red
} else {
Write-Host $line
}
}
#Running Path
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
#log file
$debugLog = "$scriptPath\orchestrator-test-run.log"
#Validate provided cli folder (if any)
if($uipathCliFilePath -ne ""){
$uipathCLI = "$uipathCliFilePath"
if (-not(Test-Path -Path $uipathCLI -PathType Leaf)) {
WriteLog "UiPath cli file path provided does not exist in the provided path $uipathCliFilePath.`r`nDo not provide uipathCliFilePath paramter if you want the script to auto download the cli from UiPath Public feed"
exit 1
}
}else{
#Verifying UiPath CLI installation
if($SpecificCLIVersion -ne ""){
$cliVersion = $SpecificCLIVersion;
}
else{
$cliVersion = "23.10.8753.32995"; #CLI Version (Script was tested on this latest version at the time)
}
$uipathCLI = "$scriptPath\uipathcli\$cliVersion\tools\uipcli.exe"
if (-not(Test-Path -Path $uipathCLI -PathType Leaf)) {
WriteLog "UiPath CLI does not exist in this folder. Attempting to download it..."
try {
if (-not(Test-Path -Path "$scriptPath\uipathcli\$cliVersion" -PathType Leaf)){
New-Item -Path "$scriptPath\uipathcli\$cliVersion" -ItemType "directory" -Force | Out-Null
}
#Download UiPath CLI
#Invoke-WebRequest "https://www.myget.org/F/uipath-dev/api/v2/package/UiPath.CLI/$cliVersion" -OutFile "$scriptPath\\uipathcli\\$cliVersion\\cli.zip";
Invoke-WebRequest "https://uipath.pkgs.visualstudio.com/Public.Feeds/_apis/packaging/feeds/1c781268-d43d-45ab-9dfc-0151a1c740b7/nuget/packages/UiPath.CLI.Windows/versions/$cliVersion/content" -OutFile "$scriptPath\\uipathcli\\$cliVersion\\cli.zip";
Expand-Archive -LiteralPath "$scriptPath\\uipathcli\\$cliVersion\\cli.zip" -DestinationPath "$scriptPath\\uipathcli\\$cliVersion";
WriteLog "UiPath CLI is downloaded and extracted in folder $scriptPath\uipathcli\\$cliVersion"
if (-not(Test-Path -Path $uipathCLI -PathType Leaf)) {
WriteLog "Unable to locate uipath cli after it is downloaded."
exit 1
}
}
catch {
WriteLog ("Error Occured : " + $_.Exception.Message) -err $_.Exception
exit 1
}
}
}
WriteLog "-----------------------------------------------------------------------------"
WriteLog "uipcli location : $uipathCLI"
#END Verifying UiPath CLI installation
$ParamList = New-Object 'Collections.Generic.List[string]'
if($orchestrator_url -eq "" -or $orchestrator_tenant -eq "")
{
WriteLog "Fill the required paramters (orchestrator_url, orchestrator_tenant)"
exit 1
}
#required parameters (Authintication)
if($accountForApp -eq "" -or $applicationId -eq "" -or $applicationSecret -eq "" -or $applicationScope -eq "")
{
if($account_name -eq "" -or $userKey -eq "")
{
if($orchestrator_user -eq "" -or $orchestrator_pass -eq "")
{
WriteLog "Fill the required paramters (External App OAuth, API Access, or Username & Password)"
exit 1
}
}
}
if($project_path -eq "" -and $testset -eq "")
{
WriteLog "Either TestSet or Project path is required to fill"
exit 1
}
#Building uipath cli paramters
$ParamList.Add("test")
$ParamList.Add("run")
$ParamList.Add($orchestrator_url)
$ParamList.Add($orchestrator_tenant)
if($project_path -ne ""){
$ParamList.Add("--project-path")
$ParamList.Add("`"$project_path`"")
}
if($input_path -ne ""){
$ParamList.Add("--input_path")
$ParamList.Add("`"$input_path`"")
}
if($testset -ne ""){
$ParamList.Add("--testset")
$ParamList.Add($testset)
}
if($result_path -ne ""){
$ParamList.Add("--result_path")
$ParamList.Add("`"$result_path`"")
}
if($accountForApp -ne ""){
$ParamList.Add("--accountForApp")
$ParamList.Add($accountForApp)
}
if($applicationId -ne ""){
$ParamList.Add("--applicationId")
$ParamList.Add($applicationId)
}
if($applicationSecret -ne ""){
$ParamList.Add("--applicationSecret")
$ParamList.Add($applicationSecret)
}
if($applicationScope -ne ""){
$ParamList.Add("--applicationScope")
$ParamList.Add("`"$applicationScope`"")
}
if($account_name -ne ""){
$ParamList.Add("--accountName")
$ParamList.Add($account_name)
}
if($UserKey -ne ""){
$ParamList.Add("--token")
$ParamList.Add($UserKey)
}
if($orchestrator_user -ne ""){
$ParamList.Add("--username")
$ParamList.Add($orchestrator_user)
}
if($orchestrator_pass -ne ""){
$ParamList.Add("--password")
$ParamList.Add($orchestrator_pass)
}
if($folder_organization_unit -ne ""){
$ParamList.Add("--organizationUnit")
$ParamList.Add("`"$folder_organization_unit`"")
}
if($environment -ne ""){
$ParamList.Add("--environment")
$ParamList.Add($environment)
}
if($timeout -ne ""){
$ParamList.Add("--timeout")
$ParamList.Add($timeout)
}
if($out -ne ""){
$ParamList.Add("--out")
$ParamList.Add($out)
}
if($language -ne ""){
$ParamList.Add("--language")
$ParamList.Add($language)
}
if($traceLevel -ne ""){
$ParamList.Add("--traceLevel")
$ParamList.Add($traceLevel)
}
if($disableTelemetry -ne ""){
$ParamList.Add("--disableTelemetry")
$ParamList.Add($disableTelemetry)
}
if($attachRobotLogs -ne ""){
$ParamList.Add("--attachRobotLogs")
$ParamList.Add("`"$attachRobotLogs`"")
}
if($repositoryUrl -ne ""){
$ParamList.Add("--repositoryUrl")
$ParamList.Add("`"$repositoryUrl`"")
}
if($repositoryCommit -ne ""){
$ParamList.Add("--repositoryCommit")
$ParamList.Add("`"$repositoryCommit`"")
}
if($repositoryBranch -ne ""){
$ParamList.Add("--repositoryBranch")
$ParamList.Add("`"$repositoryBranch`"")
}
if($repositoryType -ne ""){
$ParamList.Add("--repositoryType")
$ParamList.Add("`"$repositoryType`"")
}
if($projectUrl -ne ""){
$ParamList.Add("--projectUrl")
$ParamList.Add("`"$projectUrl`"")
}
if($identityUrl -ne ""){
$ParamList.Add("--identityUrl")
$ParamList.Add("`"$identityUrl`"")
}
#mask sensitive infos before loging
$ParamMask = New-Object 'Collections.Generic.List[string]'
$ParamMask.AddRange($ParamList)
$secretIndex = $ParamMask.IndexOf("--password");
if($secretIndex -ge 0){
$ParamMask[$secretIndex + 1] = ("*" * 15)
}
$secretIndex = $ParamMask.IndexOf("--token");
if($secretIndex -ge 0){
$ParamMask[$secretIndex + 1] = $userKey.Substring(0, [Math]::Min($userKey.Length, 4)) + ("*" * 15)
}
$secretIndex = $ParamMask.IndexOf("--applicationId");
if($secretIndex -ge 0){
$ParamMask[$secretIndex + 1] = $applicationId.Substring(0, [Math]::Min($applicationId.Length, 4)) + ("*" * 15)
}
$secretIndex = $ParamMask.IndexOf("--applicationSecret");
if($secretIndex -ge 0){
$ParamMask[$secretIndex + 1] = ("*" * 15)
}
#log cli call with parameters
WriteLog "Executing $uipathCLI $ParamMask"
#call uipath cli
& "$uipathCLI" $ParamList.ToArray()
if($LASTEXITCODE -eq 0)
{
WriteLog "Done!"
Exit 0
}else {
WriteLog "Unable to run test. Exit code $LASTEXITCODE"
Exit 1
}