-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVansahNode.cs
More file actions
789 lines (656 loc) · 33.5 KB
/
VansahNode.cs
File metadata and controls
789 lines (656 loc) · 33.5 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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
using Newtonsoft.Json.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json.Nodes;
namespace Vansah
{
public class VansahNode
{
//--------------------------- ENDPOINTS -------------------------------------------------------------------------------
// The API version to be used for requests. This ensures compatibility with the specific version of the Vansah API.
private static string api_Version = "v1";
/// <summary>
/// The default URL for the Vansah API. This URL is used unless another URL is specified via the SetVansahURL property.
/// </summary>
private static string default_Vansah_URL = "https://prod.vansahnode.app";
/// <summary>
/// The actual URL used for the Vansah API requests. It defaults to the default_Vansah_URL but can be overridden using the SetVansahURL property.
/// </summary>
private static string vansah_URL = default_Vansah_URL;
/// <summary>
/// Sets a custom URL for the Vansah API. If a null value is provided, it defaults back to the predefined URL ("https://prod.vansahnode.app").
/// </summary>
public string SetVansahURL
{
set
{
vansah_URL = value ?? default_Vansah_URL;
}
}
// Endpoint for adding a test run. Constructs the URL dynamically based on the Vansah URL and API version.
private static string add_Test_Run => $"{vansah_URL}/api/{api_Version}/run";
// Endpoint for adding a test log. Constructs the URL dynamically, allowing for the addition of logs to a test run.
private static string add_Test_Log => $"{vansah_URL}/api/{api_Version}/logs";
// Endpoint for updating a test log. The specific log ID will be appended during the request to target a specific log.
private static string update_Test_Log => $"{vansah_URL}/api/{api_Version}/logs/";
// Endpoint for removing a test log. Similar to update, the log ID is appended to this base URL in the actual request.
private static string remove_Test_Log => $"{vansah_URL}/api/{api_Version}/logs/";
// Endpoint for removing a test run. The run ID will be appended to this URL to specify which run to remove.
private static string remove_Test_Run => $"{vansah_URL}/api/{api_Version}/run/";
// Endpoint to retrieve test scripts based on the test case. This is used to list scripts associated with a case.
private static string test_Script => $"{vansah_URL}/api/{api_Version}/testCase/list/testScripts";
//--------------------------- INFORM YOUR UNIQUE VANSAH TOKEN HERE ---------------------------------------------------
/// <summary>
/// The Vansah API token used for authenticating requests. This should be set to your unique token provided by Vansah.
/// </summary>
private string vansahToken = "Your Token Here";
/// <summary>
/// Sets the Vansah API token for use in authenticating requests. If a null value is provided, the token is set to a default message indicating that the token is not properly set.
/// </summary>
public string SetVansahToken
{
set
{
vansahToken = value ?? "Vansah Connect Token is not properly set";
}
}
//--------------------------- INFORM IF YOU WANT TO UPDATE VANSAH HERE -----------------------------------------------
// Controls whether results are sent to Vansah. "0" means no results will be sent; "1" means results will be sent.
private static readonly string updateVansah = "1";
//--------------------------------------------------------------------------------------------------------------------
// Public and private properties and fields used for configuring test runs and logs:
/// <summary>
/// Gets or sets the unique identifier for the test folder in Vansah. This is mandatory unless a JiraIssueKey is provided.
/// </summary>
public string TestFolderID { get; set; }
/// <summary>
/// Gets or sets the JIRA issue key associated with the test. This is mandatory unless TestFolderID is provided.
/// </summary>
public string JiraIssueKey { get; set; }
/// <summary>
/// Gets or sets the name of the sprint associated with the test. This field is mandatory.
/// </summary>
public string SprintName { get; set; }
//The internal caseKey ID (e.g., "TEST-C1") used for identifying the test case. This is a mandatory field.
private string? caseKey;
/// <summary>
/// Gets or sets the release or version key from JIRA associated with the test. This field is mandatory.
/// </summary>
public string release_Name { get; set; }
/// <summary>
/// Gets or sets the environment ID from Vansah for the JIRA app (e.g., "SYS" or "UAT"). This field is mandatory.
/// </summary>
public string environment_Name { get; set; }
// The result of the test expressed as an integer (e.g., 0 = N/A, 1 = FAIL, 2 = PASS, 3 = Not tested). Mandatory.
private int resultKey;
// Boolean indicating whether a screenshot of the webpage to be tested should be uploaded. Default is false.
private bool uploadScreenshot = false;
// Textual comment about the actual result of the test.
private string comment;
// The order of the test step within the test case. This is used to identify the sequence of test steps.
private int step_Order;
// A unique identifier for the test run, generated by an API request.
private string test_Run_Identifier;
// A unique identifier for the test log, generated by an API request.
private string test_Log_Identifier;
// Path to the file to be used for screenshot upload. This is internally managed.
private string file;
// The base64-encoded string of the file specified for upload. This is used when attaching screenshots to logs.
private string base64FilefromUser;
// The number of test rows. This could be used for iterating over multiple test cases or steps.
private int testRows;
// The HttpClient used for making API requests to Vansah. It is configured with necessary headers and authorization.
private HttpClient httpClient;
// A mapping from string representations of test results to their corresponding integer codes.
private Dictionary<string, int> resultAsName = new Dictionary<string, int>();
/// <summary>
/// Initializes a new instance of the <see cref="VansahNode"/> class with specific test folder and JIRA issue identifiers.
/// </summary>
/// <param name="testFolders">The test folder identifier. Used to categorize tests within Vansah.</param>
/// <param name="jiraIssue">The JIRA issue key. Links the tests to a specific JIRA issue.</param>
public VansahNode(string testFolders, string jiraIssue)
{
TestFolderID = testFolders;
JiraIssueKey = jiraIssue;
// Initialize test result mapping
resultAsName.Add("NA", 0);
resultAsName.Add("FAILED", 1);
resultAsName.Add("PASSED", 2);
resultAsName.Add("UNTESTED", 3);
}
/// <summary>
/// Default constructor. Initializes a new instance of the <see cref="VansahNode"/> class without initial test folder or JIRA issue identifiers.
/// </summary>
public VansahNode()
{
// Initialize test result mapping
resultAsName.Add("NA", 0);
resultAsName.Add("FAILED", 1);
resultAsName.Add("PASSED", 2);
resultAsName.Add("UNTESTED", 3);
}
/// <summary>
/// Creates a new test run identifier for a specified JIRA issue. This identifier is used for subsequent testing actions related to the JIRA issue.
/// </summary>
/// <param name="testCase">The test case identifier associated with the JIRA issue.</param>
public void AddTestRunFromJiraIssue(string testCase)
{
caseKey = testCase;
ConnectToVansahRest("AddTestRunFromJiraIssue");
}
/// <summary>
/// Creates a new test run identifier for a specified test folder. This identifier is used for subsequent testing actions related to the test folder.
/// </summary>
/// <param name="testCase">The test case identifier associated with the test folder.</param>
public void AddTestRunFromTestFolder(string testCase)
{
caseKey = testCase;
ConnectToVansahRest("AddTestRunFromTestFolder");
}
/// <summary>
/// Adds a new test log for the specified test case. This method does not include a screenshot.
/// </summary>
/// <param name="result">The result of the test step. It uses predefined integer values (e.g., 0 = N/A, 1 = Fail, 2 = Pass, 3 = Not tested).</param>
/// <param name="Comment">A comment or description of the test result.</param>
/// <param name="testStepRow">The order or index of the test step within the test case.</param>
public void AddTestLog(int result, string Comment, int testStepRow)
{
resultKey = result;
comment = Comment;
step_Order = testStepRow;
uploadScreenshot = false;
ConnectToVansahRest("AddTestLog");
}
/// <summary>
/// Adds a new test log for the specified test case, including a path to a screenshot file.
/// </summary>
/// <param name="result">The result of the test step. It uses predefined integer values (e.g., 0 = N/A, 1 = Fail, 2 = Pass, 3 = Not tested).</param>
/// <param name="Comment">A comment or description of the test result.</param>
/// <param name="testStepRow">The order or index of the test step within the test case.</param>
/// <param name="screenshotPath">The file path to the screenshot to be uploaded. The screenshot should illustrate the test result.</param>
public void AddTestLog(int result, string Comment, int testStepRow, string screenshotPath)
{
resultKey = result;
comment = Comment;
step_Order = testStepRow;
Console.WriteLine(Validatefile(screenshotPath));
ConnectToVansahRest("AddTestLog");
}
/// <summary>
/// Adds a new test log for the specified test case. This overload allows specifying the result as a string.
/// </summary>
/// <param name="result">The result of the test step as a string (e.g., "PASS", "FAIL"). The string is case-insensitive.</param>
/// <param name="Comment">A comment or description of the test result.</param>
/// <param name="testStepRow">The order or index of the test step within the test case.</param>
public void AddTestLog(string result, string Comment, int testStepRow)
{
resultKey = resultAsName.GetValueOrDefault(result.ToUpper(), 0);
comment = Comment;
step_Order = testStepRow;
uploadScreenshot = false;
ConnectToVansahRest("AddTestLog");
}
/// <summary>
/// Adds a new test log for the specified test case, including a path to a screenshot file. This overload allows specifying the result as a string.
/// </summary>
/// <param name="result">The result of the test step as a string (e.g., "PASS", "FAIL"). The string is case-insensitive.</param>
/// <param name="Comment">A comment or description of the test result.</param>
/// <param name="testStepRow">The order or index of the test step within the test case.</param>
/// <param name="screenshotPath">The file path to the screenshot to be uploaded. The screenshot should illustrate the test result.</param>
public void AddTestLog(string result, string Comment, int testStepRow, string screenshotPath)
{
resultKey = resultAsName.GetValueOrDefault(result.ToUpper(), 0);
comment = Comment;
step_Order = testStepRow;
Console.WriteLine(Validatefile(screenshotPath));
ConnectToVansahRest("AddTestLog");
}
/// <summary>
/// Creates a new test run and log for a specified test case linked to a JIRA issue. This is useful for test cases without steps, where only the overall result matters.
/// </summary>
/// <param name="testCase">The test case identifier.</param>
/// <param name="result">The overall test result as a string (e.g., "PASS", "FAIL"). The string is case-insensitive.</param>
public void AddQuickTestFromJiraIssue(string testCase, string result)
{
// Converts the string result to its corresponding integer value.
caseKey = testCase;
resultKey = resultAsName.GetValueOrDefault(result.ToUpper(), 0);
ConnectToVansahRest("AddQuickTestFromJiraIssue");
}
/// <summary>
/// Creates a new test run and log for a specified test case associated with a test folder. Useful for cases without steps, focusing on the overall result.
/// </summary>
/// <param name="testCase">The test case identifier.</param>
/// <param name="result">The overall test result as a string (e.g., "PASS", "FAIL"). The string is case-insensitive.</param>
public void AddQuickTestFromTestFolders(string testCase, string result)
{
// Converts the string result to its corresponding integer value.
caseKey = testCase;
resultKey = resultAsName.GetValueOrDefault(result.ToUpper(), 0);
ConnectToVansahRest("AddQuickTestFromTestFolders");
}
/// <summary>
/// Creates a new test run and log for a specified test case linked to a JIRA issue. This is useful for test cases without steps, where only the overall result matters.
/// </summary>
/// <param name="testCase">The test case identifier.</param>
/// <param name="result">The overall test result as an integer (0 = N/A, 1 = Fail, 2 = Pass, 3 = Not tested).</param>
public void AddQuickTestFromJiraIssue(string testCase, int result)
{
// Directly uses the integer result value.
caseKey = testCase;
resultKey = result;
ConnectToVansahRest("AddQuickTestFromJiraIssue");
}
/// <summary>
/// Creates a new test run and log for a specified test case associated with a test folder. Useful for cases without steps, focusing on the overall result.
/// </summary>
/// <param name="testCase">The test case identifier.</param>
/// <param name="result">The overall test result as an integer (0 = N/A, 1 = Fail, 2 = Pass, 3 = Not tested).</param>
public void AddQuickTestFromTestFolders(string testCase, int result)
{
// Directly uses the integer result value.
caseKey = testCase;
resultKey = result;
ConnectToVansahRest("AddQuickTestFromTestFolders");
}
/// <summary>
/// Deletes the test run created by the AddTestRunFromJiraIssue or AddTestRunFromTestFolder methods.
/// </summary>
public void RemoveTestRun()
{
ConnectToVansahRest("RemoveTestRun");
}
/// <summary>
/// Deletes a test log identifier created by any AddTestLog method variant.
/// </summary>
public void RemoveTestLog()
{
ConnectToVansahRest("RemoveTestLog");
}
/// <summary>
/// Updates a test log with a new result and comment. This variant does not include a screenshot.
/// </summary>
/// <param name="result">The updated result of the test as an integer (e.g., 0 = N/A, 1 = Fail, 2 = Pass, 3 = Not tested).</param>
/// <param name="Comment">The updated comment or description of the test result.</param>
public void UpdateTestLog(int result, string Comment)
{
resultKey = result;
comment = Comment;
uploadScreenshot = false;
ConnectToVansahRest("UpdateTestLog");
}
/// <summary>
/// Updates a test log with a new result and comment, and includes a path to a screenshot file.
/// </summary>
/// <param name="result">The updated result of the test as an integer.</param>
/// <param name="Comment">The updated comment or description of the test result.</param>
/// <param name="screenshotPath">The file path to the screenshot to be uploaded, illustrating the test result.</param>
public void UpdateTestLog(int result, string Comment, string screenshotPath)
{
resultKey = result;
comment = Comment;
Console.WriteLine(Validatefile(screenshotPath));
ConnectToVansahRest("UpdateTestLog");
}
/// <summary>
/// Updates a test log with a new result and comment. This variant allows specifying the result as a string.
/// </summary>
/// <param name="result">The result of the test step as a string (e.g., "PASS", "FAIL").</param>
/// <param name="Comment">The updated comment or description of the test result.</param>
public void UpdateTestLog(string result, string Comment)
{
resultKey = resultAsName.GetValueOrDefault(result.ToUpper(), 0);
comment = Comment;
uploadScreenshot = false;
ConnectToVansahRest("UpdateTestLog");
}
/// <summary>
/// Updates a test log with a new result and comment, including a path to a screenshot file. This variant allows specifying the result as a string.
/// </summary>
/// <param name="result">The result of the test step as a string.</param>
/// <param name="Comment">The updated comment or description of the test result.</param>
/// <param name="screenshotPath">The file path to the screenshot to be uploaded.</param>
public void UpdateTestLog(string result, string Comment, string screenshotPath)
{
resultKey = resultAsName.GetValueOrDefault(result.ToUpper(), 0);
comment = Comment;
Console.WriteLine(Validatefile(screenshotPath));
ConnectToVansahRest("UpdateTestLog");
}
/// <summary>
/// Connects to the Vansah REST API to perform various operations such as adding, removing, and updating test runs and logs.
/// This method dynamically constructs the request based on the specified type and sends it to the Vansah API.
/// </summary>
/// <param name="type">The type of operation to perform, which determines the endpoint to be called and the request body to be sent.</param>
/// <remarks>
/// This method handles the construction of HTTP requests, including setting headers, building the request body, and handling responses.
/// Supported types include "AddTestRunFromJiraIssue", "AddTestRunFromTestFolder", "AddTestLog", "AddQuickTestFromJiraIssue",
/// "AddQuickTestFromTestFolders", "RemoveTestRun", "RemoveTestLog", and "UpdateTestLog". Depending on the operation,
/// additional properties such as test run and log identifiers, result codes, comments, and screenshot paths might be utilized.
/// </remarks>
private void ConnectToVansahRest(string type)
{
if (updateVansah == "1")
{
httpClient = new HttpClient();
HttpResponseMessage response = null;
JsonObject requestBody;
HttpContent Content;
//Adding headers
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("Authorization", vansahToken);
if (uploadScreenshot)
{
base64FilefromUser = ConvertImageToBase64(file);
}
if (type == "AddTestRunFromJiraIssue")
{
requestBody = new();
requestBody.Add("case", TestCase());
requestBody.Add("asset", JiraIssueAsset());
if (Properties().Count != 0) { requestBody.Add("properties", Properties()); }
httpClient.BaseAddress = new Uri(add_Test_Run);
Content = new StringContent(requestBody.ToJsonString(), Encoding.UTF8, "application/json" /* or "application/json" in older versions */);
response = httpClient.PostAsync("", Content).Result;
}
if (type == "AddTestRunFromTestFolder")
{
requestBody = new();
requestBody.Add("case", TestCase());
requestBody.Add("asset", TestFolderAsset());
if (Properties().Count != 0) { requestBody.Add("properties", Properties()); }
//Console.WriteLine(requestBody);
httpClient.BaseAddress = new Uri(add_Test_Run);
Content = new StringContent(requestBody.ToJsonString(), Encoding.UTF8, "application/json" /* or "application/json" in older versions */);
response = httpClient.PostAsync("", Content).Result;
}
if (type == "AddTestLog")
{
requestBody = AddTestLogProp();
if (uploadScreenshot)
{
JsonArray array = new();
array.Add(AddAttachment(FileName()));
requestBody.Add("attachments", array);
}
//Console.WriteLine(requestBody.ToJsonString());
httpClient.BaseAddress = new Uri(add_Test_Log);
Content = new StringContent(requestBody.ToJsonString(), Encoding.UTF8, "application/json" /* or "application/json" in older versions */);
response = httpClient.PostAsync("", Content).Result;
}
if (type == "AddQuickTestFromJiraIssue")
{
requestBody = new();
requestBody.Add("case", TestCase());
requestBody.Add("asset", JiraIssueAsset());
if (Properties().Count != 0)
{
requestBody.Add("properties", Properties());
}
requestBody.Add("result", resultObj(resultKey));
if (uploadScreenshot)
{
JsonArray array = new();
array.Add(AddAttachment(FileName()));
requestBody.Add("attachments", array);
}
httpClient.BaseAddress = new Uri(add_Test_Run);
Content = new StringContent(requestBody.ToJsonString(), Encoding.UTF8, "application/json" /* or "application/json" in older versions */);
response = httpClient.PostAsync("", Content).Result;
}
if (type == "AddQuickTestFromTestFolders")
{
requestBody = new();
requestBody.Add("case", TestCase());
requestBody.Add("asset", TestFolderAsset());
if (Properties().Count != 0)
{
requestBody.Add("properties", Properties());
}
requestBody.Add("result", resultObj(resultKey));
if (uploadScreenshot)
{
JsonArray array = new();
array.Add(AddAttachment(FileName()));
requestBody.Add("attachments", array);
}
httpClient.BaseAddress = new Uri(add_Test_Run);
Content = new StringContent(requestBody.ToJsonString(), Encoding.UTF8, "application/json" /* or "application/json" in older versions */);
response = httpClient.PostAsync("", Content).Result;
}
if (type == "RemoveTestRun")
{
httpClient.BaseAddress = new Uri(remove_Test_Run + test_Run_Identifier);
response = httpClient.DeleteAsync("").Result;
}
if (type == "RemoveTestLog")
{
httpClient.BaseAddress = new Uri(remove_Test_Log + test_Log_Identifier);
response = httpClient.DeleteAsync("").Result;
}
if (type == "UpdateTestLog")
{
requestBody = new();
requestBody.Add("result", resultObj(resultKey));
requestBody.Add("actualResult", comment);
if (uploadScreenshot)
{
JsonArray array = new();
array.Add(AddAttachment(FileName()));
requestBody.Add("attachments", array);
}
httpClient.BaseAddress = new Uri(update_Test_Log + test_Log_Identifier);
Content = new StringContent(requestBody.ToJsonString(), Encoding.UTF8, "application/json" /* or "application/json" in older versions */);
response = httpClient.PutAsync("", Content).Result;
}
if (response.IsSuccessStatusCode)
{
var responseMessage = response.Content.ReadAsStringAsync().Result;
var obj = JObject.Parse(responseMessage);
if (type == "AddTestRunFromJiraIssue")
{
test_Run_Identifier = obj.SelectToken("data.run.identifier").ToString();
Console.WriteLine($"Test Run has been created Successfully RUN ID : {test_Run_Identifier}");
}
if (type == "AddTestRunFromTestFolder")
{
test_Run_Identifier = obj.SelectToken("data.run.identifier").ToString();
Console.WriteLine($"Test Run has been created Successfully RUN ID : {test_Run_Identifier}");
}
if (type == "AddTestLog")
{
test_Log_Identifier = obj.SelectToken("data.log.identifier").ToString();
Console.WriteLine($"Test Log has been Added to a test Step Successfully LOG ID : {test_Log_Identifier}");
}
if (type == "AddQuickTestFromJiraIssue")
{
test_Run_Identifier = obj.SelectToken("data.run.identifier").ToString();
string message = obj.SelectToken("message").ToString();
Console.WriteLine($"Quick Test : {message}");
}
if (type == "AddQuickTestFromTestFolders")
{
test_Run_Identifier = obj.SelectToken("data.run.identifier").ToString();
string message = obj.SelectToken("message").ToString();
Console.WriteLine($"Quick Test : {message}");
}
if (type == "RemoveTestLog")
{
Console.WriteLine($"Test Log has been removed from a test Step Successfully LOG ID : {test_Log_Identifier}");
}
if (type == "RemoveTestRun")
{
Console.WriteLine($"Test Run has been removed Successfully for the testCase : {caseKey} RUN ID : {test_Run_Identifier}");
}
if (type == "UpdateTestLog")
{
Console.WriteLine($"Test Log has been updated Successfully LOG ID : {test_Log_Identifier}");
}
response.Dispose();
}
else
{
var responseMessage = response.Content.ReadAsStringAsync().Result;
var obj = JObject.Parse(responseMessage);
Console.WriteLine(obj.SelectToken("message").ToString());
response.Dispose();
}
}
else
{
Console.WriteLine("Sending Test Results to Vansah TM for JIRA is Disabled");
}
}
//JsonObject - Test Run Properties
private JsonObject Properties()
{
JsonObject environment = new();
environment.Add("name", environment_Name);
JsonObject release = new();
release.Add("name", release_Name);
JsonObject sprint = new();
sprint.Add("name", SprintName);
JsonObject Properties = new();
if (SprintName != null)
{
if (SprintName.Length >= 2)
{
Properties.Add("sprint", sprint);
}
}
if (release_Name != null)
{
if (release_Name.Length >= 2)
{
Properties.Add("release", release);
}
}
if (environment_Name != null)
{
if (environment_Name.Length >= 2)
{
Properties.Add("environment", environment);
}
}
return Properties;
}
//JsonObject - To Add TestCase Key
private JsonObject TestCase()
{
JsonObject testCase = new();
if (caseKey != null)
{
if (caseKey.Length >= 2)
{
testCase.Add("key", caseKey);
}
}
else
{
Console.WriteLine("Please Provide Valid TestCase Key");
}
return testCase;
}
//JsonObject - To Add Result ID
private JsonObject resultObj(int result)
{
JsonObject resultID = new();
resultID.Add("id", result);
return resultID;
}
//JsonObject - To Add JIRA Issue name
private JsonObject JiraIssueAsset()
{
JsonObject asset = new();
if (JiraIssueKey != null)
{
if (JiraIssueKey.Length >= 2)
{
asset.Add("type", "issue");
asset.Add("key", JiraIssueKey);
}
}
else
{
Console.WriteLine("Please Provide Valid JIRA Issue Key");
}
return asset;
}
//JsonObject - To Add TestFolder ID
private JsonObject TestFolderAsset()
{
JsonObject asset = new();
if (TestFolderID != null)
{
if (TestFolderID.Length >= 2)
{
asset.Add("type", "folder");
asset.Add("identifier", TestFolderID);
}
}
else
{
Console.WriteLine("Please Provide Valid TestFolder ID");
}
return asset;
}
//JsonObject - To AddTestLog
private JsonObject AddTestLogProp()
{
JsonObject testRun = new();
testRun.Add("identifier", test_Run_Identifier);
JsonObject stepNumber = new();
stepNumber.Add("number", step_Order);
JsonObject testResult = new();
testResult.Add("id", resultKey);
JsonObject testLogProp = new();
testLogProp.Add("run", testRun);
testLogProp.Add("step", stepNumber);
testLogProp.Add("result", testResult);
testLogProp.Add("actualResult", comment);
return testLogProp;
}
//JsonObject - To Add Add Attachments to a Test Log
private JsonObject AddAttachment(string[] file)
{
JsonObject attachmentsInfo = new();
attachmentsInfo.Add("name", file[0]);
attachmentsInfo.Add("extension", file[1]);
attachmentsInfo.Add("file", base64FilefromUser);
return attachmentsInfo;
}
private string[] FileName()
{
string fileName = Path.GetFileNameWithoutExtension(file);
string fileExtension = Path.GetExtension(file);
string[] file_Name = { fileName, fileExtension };
return file_Name;
}
private string Validatefile(String filePath)
{
bool ispresent = File.Exists(filePath);
if (ispresent)
{
uploadScreenshot = true;
file = filePath;
return "Screenshot file is getting uploaded";
}
return "Provided Screenshot File cannot be located \nPlease provide correct filePath";
}
private string ConvertImageToBase64(string imagePath)
{
try
{
byte[] imageBytes = File.ReadAllBytes(imagePath);
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
return null;
}
}
}
}