-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCG_DEMO_FineTuning_Nividia.py
2030 lines (1672 loc) · 103 KB
/
TCG_DEMO_FineTuning_Nividia.py
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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
######### 1. Load requiered libraries #######################
import sys
import os
import re
import requests
import openpyxl
import docx2txt
import ast
from datetime import datetime
import docx
import pandas as pd
from docx import Document
from docx.shared import Inches, Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.enum.table import WD_TABLE_ALIGNMENT
from prettytable import PrettyTable
from PyPDF2 import PdfReader
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt, QSize, QThread, QTimer
from PyQt5.QtGui import QPixmap, QFont, QColor, QPalette, QPixmap, QBrush
from PyQt5.QtWidgets import (QApplication, QMainWindow, QProgressDialog,
QVBoxLayout, QHBoxLayout, QWidget, QGroupBox, QLabel, QPushButton,
QFrame, QHBoxLayout, QWidget, QFileDialog, QMessageBox, QDialog, QTextEdit,
QSpinBox, QDialogButtonBox, QComboBox, QProgressBar, QSpacerItem, QSizePolicy,
QGridLayout, QLineEdit)
##########################################################################
######### UI Temp Classes #######################
## CustomButton - Creates a QPushButton with the desired styling.
class StyledButton(QPushButton):
def __init__(self, text,width=200,height=35,background_color="#29465B"):
self.background_color= background_color
self.width = width
self.height = height
super().__init__(text)
self.setFixedSize(self.width, self.height)
self.setStyleSheet(f"""
background-color: {self.background_color};
color: white; font-weight: bold; border-radius: 5px;
""")
## CustomLogoLabel - Creates a QLabel for logo images.
class StyledBox(QGroupBox):
def __init__(self, width, height):
super().__init__()
self.setFixedSize(width, height)
self.setStyleSheet("""
QGroupBox {
background-color: #488AC7;
border-radius: 5px;
color: white;
}
""")
### Custom LayoutBox
class ButtonDialogStyle:
def __init__(self, background_color="#488AC7", border_color="white", border_width="3px",
border_radius="5px", padding="10px 25px", button_background_color="white",
button_border_color="white", button_border_radius="5px", button_padding="5px 15px",
button_hover_color="lightgrey", button_pressed_color="lightgrey",min_height="1.3em"):
self.background_color = background_color
self.border_color = border_color
self.border_width = border_width
self.border_radius = border_radius
self.padding = padding
self.button_background_color = button_background_color
self.button_border_color = button_border_color
self.button_border_radius = button_border_radius
self.button_padding = button_padding
self.button_hover_color = button_hover_color
self.button_pressed_color = button_pressed_color
self.min_height = min_height
def set_style(self, dialog):
dialog.setStyleSheet(f"""
QDialog {{
border-radius: {self.border_radius};
background-color: {self.background_color};
border: {self.border_width} solid {self.border_color};
min-height: {self.min_height};
padding: {self.padding};
}}
QPushButton {{
background-color: {self.button_background_color};
border: 2px solid {self.button_border_color};
border-radius: {self.button_border_radius};
min-height: {self.min_height};
padding: {self.button_padding};
}}
QPushButton:hover {{
background-color: {self.button_hover_color};
}}
QPushButton:pressed {{
background-color: {self.button_pressed_color};
}}
""")
class ProgressDialogStyle:
def __init__(self, background_color="#488AC7", border_color="white", border_width="3px",
border_radius="5px", padding="10px 25px", label_color="white", label_font_weight="bold",
progress_background_color="white", progress_text_align="right", progress_color="black",
progress_chunk_background_color="#46C646", progress_chunk_font_weight="bold"):
self.background_color = background_color
self.border_color = border_color
self.border_width = border_width
self.border_radius = border_radius
self.padding = padding
self.label_color = label_color
self.label_font_weight = label_font_weight
self.progress_background_color = progress_background_color
self.progress_text_align = progress_text_align
self.progress_color = progress_color
self.progress_chunk_background_color = progress_chunk_background_color
self.progress_chunk_font_weight = progress_chunk_font_weight
def set_style(self, dialog):
dialog.setStyleSheet(f"""
QProgressDialog {{
border-radius: {self.border_radius};
background-color: {self.background_color};
border: {self.border_width} solid {self.border_color};
min-height: 1.3em;
padding: {self.padding};
}}
QProgressDialog QLabel {{
color: {self.label_color};
font-weight: {self.label_font_weight};
}}
QProgressDialog QProgressBar {{
background-color: {self.progress_background_color};
text-align: {self.progress_text_align};
color: {self.progress_color};
}}
QProgressDialog QProgressBar::chunk {{
background-color: {self.progress_chunk_background_color};
font-weight: {self.progress_chunk_font_weight};
}}
""")
class MainWindow(QMainWindow):
# static variables:
text = None
# req_temp = None
# usr_story = None
# generic_doc = None
req_response_data = None
generate_test_response_data = None
gen_tst_case = None
gen_tst_req = None
summary_response = None
req_txt = None
test_cases = None
#upload_to_opkey = None
### All UI Buttons
upload_button = False
summary_button = False
generate_test_requirements_button = False
generate_test_cases_button = False
generate_automation_scripts_button = False
user_input_button = False
upload_to_opkey_button = False
export_file_button = False
requirements_import_button = False
clear_button = False
exit_button = False
## User Input Option Button (Default Value)
delivery_team_user_input = '...'
generate_test_type_user_input = '...' ## by defaulf wil be empty string
priority_user_input = "..."
milestone_user_input = "..."
get_link_1 = "https://demo.labs.opkeyone.com/api/OpkeyAuth/GetListOfAssignedProject"
post_link_1 = "https://demo.labs.opkeyone.com/api/OpkeyAuth/[email protected]&loginsource=TCG"
post_link_2 = "https://demo.labs.opkeyone.com/api/OpkeyAuth/SelectProject?projectId=9e188d9d-29eb-4dc5-af85-d39638f9e3df"
post_link_3 = "https://demo.labs.opkeyone.com/Automation/ExecuteOracleTestCreationQuery"
api_key = "5SOEH6MWEPX6NZ4IX0"
# Init function used to design UI
def __init__(self):
super().__init__()
# Get the current working directory
current_path = os.getcwd()
# Set the title for the main window
self.setWindowTitle("Developer: KPMG Team")
# Maximize the window size on launch
self.setWindowState(Qt.WindowMaximized)
# Create a QPalette object to set the background image
palette = QPalette()
bg_image_path = os.path.join(current_path, "UI_Temp", "BG-1.jpg")
bg_image = QPixmap(bg_image_path)
palette.setBrush(QPalette.Background, QBrush(bg_image))
# Apply the customized palette to the main window
self.setPalette(palette)
# Create a QVBoxLayout for the main layout
layout = QVBoxLayout()
# Create a top box group and a horizontal layout for the box
main_top_box_group = QGroupBox()
# main_top_box_group.setFixedSize(1900, 110)
main_top_box_group.setStyleSheet("QGroupBox {background-color: transparent; border: transparent;}")
main_top_box_layout = QHBoxLayout(main_top_box_group)
top_box_group = StyledBox(1900, 100)
top_box_layout = QHBoxLayout(top_box_group)
top_box_layout.setAlignment(Qt.AlignCenter) ### remove if KMPG logo needs to be left
# Add KPMG logo QLabel using CustomLogoLabel
kpmg_logo_label = QLabel()
kpmg_logo_path = os.path.join(current_path, "UI_Temp", "kpmg-logo-2.png")
kpmg_logo_pixmap = QPixmap(kpmg_logo_path)
kpmg_logo_label.setPixmap(kpmg_logo_pixmap.scaledToHeight(int(top_box_group.height() * 1.5), Qt.SmoothTransformation))
top_box_layout.addWidget(kpmg_logo_label, alignment=Qt.AlignLeft)
top_box_layout.addSpacing(620)
# Add the HP logo QLabel using CustomLogoLabel
# hp_logo_label = QLabel()
# hp_logo_path = os.path.join(current_path, "UI_Temp", "hp-logo-4.png")
# hp_logo_pixmap = QPixmap(hp_logo_path)
# hp_logo_label.setPixmap(hp_logo_pixmap.scaledToHeight(top_box_group.height() * 0.7, Qt.SmoothTransformation))
# top_box_layout.addWidget(hp_logo_label, alignment=Qt.AlignLeft|Qt.AlignCenter)
# Add a QLabel widget for the heading and add it to the layout
heading = QLabel("KPMG Test Generator")
heading.setFont(QFont("KPMG Bold", 30, QFont.Bold))
heading.setStyleSheet("color: white;")
top_box_layout.addWidget(heading, alignment= Qt.AlignLeft|Qt.AlignCenter)
top_box_layout.addSpacing(800) # Adding a gap of 20 pixels between buttons
# Add the top box to the main layout with center alignment
# layout.addWidget(top_box_group, alignment=Qt.AlignTop)
# main_top_box_layout.addWidget(top_box_group, alignment=Qt.AlignTop) #-------
# Add the disclaimer label to the layout
disclaimer_label = QLabel()
disclaimer_path = os.path.join(current_path, "UI_Temp", "disclaimer.png")
disclaimer_pixmap = QPixmap(disclaimer_path)
disclaimer_label.setPixmap(disclaimer_pixmap.scaledToHeight(int(top_box_group.height() * .5), Qt.SmoothTransformation))
disclaimer_label.setToolTip(""" Please note that the Test Case Generator Tool is a software tool designed for generating test cases quickly and efficiently from raw requirements.
It is intended for use by software developers and testers who have experience in programming and application development.
While the tool is designed to simplify and streamline the test case generation process,
it is still necessary for users to have a good understanding of their application's requirements and functionality.
The generated test cases should be reviewed and validated by an experienced tester before being executed on any application or software system.
The tool assumes no responsibility for errors or issues that may arise from the use of generated test cases or automation scripts.
The Test Case Generator Tool can help to save lot of time and reduce human errors in the software testing process,
making it an essential tool for software developers and testers
""")
# Set font weight to bold
disclaimer_font = QFont()
disclaimer_font.setBold(True)
disclaimer_label.setFont(disclaimer_font)
# Set border style and width
disclaimer_label.setStyleSheet("color: black; font: bold")
# layout.addWidget(disclaimer_label, alignment= Qt.AlignTop | Qt.AlignRight )
# main_top_box_layout.addWidget(disclaimer_label, alignment= Qt.AlignBottom | Qt.AlignRight ) #-----
top_box_layout.addWidget(disclaimer_label, alignment= Qt.AlignBottom | Qt.AlignRight )
#Add the maintop box in layout
# layout.addWidget(main_top_box_group, alignment=Qt.AlignTop) #---------
layout.addWidget(top_box_group, alignment=Qt.AlignTop)
# # Create a QLabel widget for the subheading and add it to the layout
# sub_heading = QLabel("A US Digital LightHouse GenAI Innovation")
# sub_heading.setFont(QFont("KPMG Bold", 15, QFont.Bold))
# sub_heading.setStyleSheet("color: black;")
# # sub_heading.setAlignment(Qt.AlignCenter)
# layout.addWidget(sub_heading, alignment= Qt.AlignCenter | Qt.AlignTop )
# # box_layout.addWidget(sub_heading, alignment=Qt.AlignCenter)
hbox = QHBoxLayout()
MainWindow.upload_button = StyledButton(text="Upload Requirement")
hbox.addWidget(MainWindow.upload_button)
MainWindow.upload_button.clicked.connect(self.upload_document)
MainWindow.summary_button = StyledButton(text="Provide Summary")
hbox.addWidget(MainWindow.summary_button)
MainWindow.summary_button.clicked.connect(self.provide_summary)
MainWindow.generate_test_requirements_button = StyledButton(text="Structure Test Requirements",width=250)
hbox.addWidget(MainWindow.generate_test_requirements_button)
MainWindow.generate_test_requirements_button.clicked.connect(self.generate_test_requirements)
MainWindow.generate_test_cases_button = StyledButton(text="Generate Test Cases",width=200)
hbox.addWidget(MainWindow.generate_test_cases_button)
# As intial diabled the button
MainWindow.generate_test_cases_button.setEnabled(False)
MainWindow.generate_test_cases_button.setStyleSheet("background-color: #B6B6B4; color: white; font-weight: bold; border-radius: 5px;")
MainWindow.generate_test_cases_button.clicked.connect(self.test_type)
# MainWindow.generate_automation_scripts_button = StyledButton(text="Create Automation Scripts",width=230)
# hbox.addWidget(MainWindow.generate_automation_scripts_button)
# # As intial diabled the button
# MainWindow.generate_automation_scripts_button.setEnabled(False)
# MainWindow.generate_automation_scripts_button.setStyleSheet("background-color: #B6B6B4; color: white; font-weight: bold; border-radius: 5px;")
# MainWindow.generate_automation_scripts_button.clicked.connect(self.create_automation_scripts)
MainWindow.user_input_button = StyledButton(text="User Inputs")
hbox.addWidget(MainWindow.user_input_button)
MainWindow.user_input_button.clicked.connect(self.user_input)
MainWindow.export_file_button = StyledButton(text="Export",width=180)
hbox.addWidget(MainWindow.export_file_button)
MainWindow.export_file_button.clicked.connect(self.export_button)
MainWindow.upload_to_opkey_button = StyledButton(text="Upload To Opkey",background_color="#B6B6B4")
hbox.addWidget(MainWindow.upload_to_opkey_button)
MainWindow.upload_to_opkey_button.setEnabled(False)
MainWindow.upload_to_opkey_button.clicked.connect(self.upload_to_opkey_function)
### Add Layout
layout.addLayout(hbox)
layout.setAlignment(hbox, Qt.AlignCenter)
self.display_pane = QVBoxLayout()
self.display_pane.setSpacing(10)
self.display_pane.setAlignment(Qt.AlignTop)
self.summary_label = QTextEdit()
self.summary_label.setReadOnly(True)
self.summary_label.setStyleSheet("color: black; background-color: white;")
self.display_pane.addWidget(self.summary_label)
display_frame = QFrame()
display_frame.setLineWidth(3)
display_frame.setFrameShape(QFrame.Box)
display_frame.setFrameShadow(QFrame.Sunken)
display_frame.setFixedSize(1500, 600)
display_frame.setLayout(self.display_pane)
layout.addWidget(display_frame, alignment=Qt.AlignCenter)
##
dbox = QHBoxLayout()
dbox.addSpacing(100) # Adding a gap of 20 pixels between buttons
MainWindow.requirements_import_button = StyledButton(text="Requirements Import",width=230,background_color="#B6B6B4")
dbox.addWidget(MainWindow.requirements_import_button)
MainWindow.generate_automation_scripts_button = StyledButton(text="Create Automation Scripts",width=230)
dbox.addWidget(MainWindow.generate_automation_scripts_button)
# As intial diabled the button
MainWindow.generate_automation_scripts_button.setEnabled(False)
MainWindow.generate_automation_scripts_button.setStyleSheet("background-color: #B6B6B4; color: white; font-weight: bold; border-radius: 5px;")
MainWindow.generate_automation_scripts_button.clicked.connect(self.create_automation_scripts)
dbox.addSpacing(2500) # Adding a gap of 20 pixels between buttons
MainWindow.clear_button = StyledButton(text="New Scenario",width=200)
dbox.addWidget(MainWindow.clear_button)
MainWindow.clear_button.clicked.connect(self.clear_display)
exit_button = StyledButton(text="Exit",width=150)
dbox.addWidget(exit_button)
exit_button.clicked.connect(self.exit_application)
dbox.addSpacing(100) # Adding a gap of 20 pixels between buttons
layout.addLayout(dbox)
layout.setAlignment(dbox, Qt.AlignLeft)
# footer_text = QLabel("This software is the exclusive property of KPMG Lighthouse [Group Name], and unauthorized copying or illicit usage is strictly prohibited. Any violation of these terms may result in legal action.")
footer_text = QLabel("For Internal Use Only")
footer_text.setAlignment(Qt.AlignCenter)
footer_text.setFont(QFont("Arial", 9))
footer_text.setStyleSheet("color: black;")
layout.addWidget(footer_text)
central_widget = QWidget()
central_widget.setLayout(layout)
self.setCentralWidget(central_widget)
# method defining T&C popup
def show_popup(self):
MainWindow.gen_tst_case = False
popup_dialog = QDialog(self)
popup_dialog.setWindowTitle("TCG 1.0")
popup_dialog.setStyleSheet("background-color: black;")
# Set fixed size for the QDialog
popup_dialog.setFixedSize(900, 450)
vbox = QVBoxLayout()
popup_dialog.setLayout(vbox)
heading_label = QLabel("Please read carefully")
heading_label.setFont(QFont("KPMG Bold", 30))
heading_label.setStyleSheet("color: red;")
heading_label.setAlignment(Qt.AlignCenter)
vbox.addWidget(heading_label)
message_text = '''\
This tool, a US Lighthouse GenAI Innovation, assists in generating test cases from requirements and subsequently transforming them into automation scripts. Before using this tool, it's crucial to thoroughly comprehend the requirements. After generating the test cases, a manual review must be conducted. Ensure that you input the ideal number of test cases to achieve a 100% requirement coverage. Please note that the Large Language Model's response could vary due to its nature. Please use your skepticism and professional judgement when using results from this tool in any deliverable.
If you disagree with any of these terms, please exit the program. For any inquiries, feel free to contact the <[email protected]>.
'''
message_label = QLabel(message_text)
message_label.setFont(QFont("Arial", 9))
message_label.setStyleSheet("color: red;")
message_label.setAlignment(Qt.AlignCenter)
message_label.setWordWrap(True)
vbox.addWidget(message_label)
hbox = QHBoxLayout()
hbox.addStretch()
accept_button = QPushButton("Accept")
accept_button.setStyleSheet("background-color: lightblue;")
hbox.addWidget(accept_button)
accept_button.clicked.connect(popup_dialog.accept)
reject_button = QPushButton("Reject")
reject_button.setStyleSheet("background-color: lightblue;")
hbox.addWidget(reject_button)
reject_button.clicked.connect(popup_dialog.reject)
hbox.addStretch()
vbox.addLayout(hbox)
result = popup_dialog.exec_()
if result == QDialog.Accepted:
return True
else:
return False
# Method defining document upload button functionality
def upload_document(self):
dialog = QDialog(self)
dialog.resize(600, 150)
dialog.setWindowTitle("Select the type of Document")
vbox = QVBoxLayout()
dialog.setLayout(vbox)
dialog_style =ButtonDialogStyle()
dialog_style.set_style(dialog)
doc_combo = QComboBox()
doc_combo.setMinimumWidth(200)
doc_combo.setStyleSheet("background-color: white; border-radius: 5px; min-height: 1.3em; padding: 3px 10px")
doc_combo.move(60, 30)
doc_combo.addItem("(default) Select the type of document...")
doc_combo.addItem("PDF")
doc_combo.addItem("Word")
doc_combo.addItem("Text")
doc_combo.addItem("Excel")
# doc_combo.addItem("PPT")
vbox.addWidget(doc_combo)
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
vbox.addWidget(button_box)
button_box.accepted.connect(dialog.accept)
button_box.rejected.connect(dialog.reject)
result = dialog.exec_()
######################
if result == QDialog.Accepted:
doc_type = doc_combo.currentText()
# if doc_type!="(default) Select the type of document...":
options = QFileDialog.Options()
options |= QFileDialog.ReadOnly
if doc_type=="Word":
file_name, _ = QFileDialog.getOpenFileName(self, "Open Document", "", "Word Documents (*.docx; *.doc)", options=options)
elif doc_type=="PDF":
file_name, _ = QFileDialog.getOpenFileName(self, "Open Document", "", "PDF Documents (*.pdf;)", options=options)
elif doc_type=="Text":
file_name, _ = QFileDialog.getOpenFileName(self, "Open Document", "", "Text Documents (*.txt;)", options=options)
elif doc_type=="Excel":
file_name, _ = QFileDialog.getOpenFileName(self, "Open Document", "", "Excel/CSV Documents (*.xlsx;*.csv;)", options=options)
elif doc_type=="PPT":
file_name, _ = QFileDialog.getOpenFileName(self, "Open Document", "", "PPT Documents (*.pptx;)", options=options)
if file_name:
MainWindow.text = self.extract_text(file_name)
if MainWindow.text:
progress_dialog = QProgressDialog("Uploading document...", None, 0, 100 , self)
progress_dialog.resize(400,100)
progress_style = ProgressDialogStyle()
progress_style.set_style(progress_dialog)
progress_dialog.setWindowTitle("In progress")
progress_dialog.setWindowModality(Qt.ApplicationModal)
progress_dialog.setAutoClose(False)
progress_dialog.setAutoReset(False)
progress_dialog.setMinimumDuration(0)
progress_dialog.forceShow()
for progress in range(0, 101, 3):
progress_dialog.setValue(progress)
QApplication.processEvents()
progress_dialog.setLabelText(f"Please wait while the document is uploading...")
QApplication.instance().processEvents()
QThread.msleep(60)
# self.send_text_to_gpt(MainWindow.text)
progress_dialog.close()
QMessageBox.information(self, "Success", "Document successfully uploaded!")
MainWindow.upload_button.setEnabled(False)
MainWindow.upload_button.setStyleSheet("background-color: green; color: white; font-weight: bold; border-radius: 5px;")
else:
QMessageBox.critical(self, "Error", "Error extracting text from the document!")
else:
QMessageBox.warning(self, "Warning", "Please select the type of document")
# # Method defining how uploaded content is extracted
def extract_text(self, file_name):
_, file_extension = os.path.splitext(file_name)
if file_extension == '.pdf':
with open(file_name, 'rb') as file:
reader = PdfReader(file)
ext_text = '\n'.join(page.extract_text() for page in reader.pages)
elif file_extension == '.docx':
ext_text = docx2txt.process(file_name)
elif file_extension == '.txt':
with open(file_name, "r") as file:
ext_text = file.read()
# print("--------------------------")
# print(ext_text)
elif file_extension == '.xlsx':
df = pd.read_excel(file_name)
ext_text = df.to_string(index=False, header=True) # Convert DataFrame content to a formatted
else:
ext_text = None
return ext_text
def send_text_to_gpt(self, text):
self.api_key = "73c315ba0bc44e6abffd10b189dc3199"
self.url = "https://gpt-llm-4.openai.azure.com/openai/deployments/gpt-4/chat/completions?api-version=2023-03-15-preview"
#self.api_key = "d4595b37d235460395fa78721602c87b"
#self.url = "https://oai-kgsgpt-testapp.openai.azure.com/openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-03-15-preview"
conversation_history_with_prompt = f"""You are an expert in analyzing functional requirements.
Understand the extracted text.
Provide summary in not less than 500 words.
Summary should be crisp.
Display numbers if possible from the extracted text.
Dont create numbers on your own: {text}"""
headers = {"api-key": self.api_key}
query_data = {
"messages": [
{"role": "system", "content": conversation_history_with_prompt}
],
"temperature": 0,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
"max_tokens": 4096,
"stop": None,
}
MainWindow.summary_response = requests.post(self.url, headers=headers, json=query_data, verify=False)
print('Summary Response:',MainWindow.summary_response)
print(str(MainWindow.summary_response))
summary_response_data = MainWindow.summary_response.json()
self.store_gpt_response_data(summary_response_data)
'''async def send_chunk_to_gpt(url, headers, query_data):
response = await requests.post(url, headers=headers, json=query_data)
response_data = response.json()
#self.store_gpt_response_data(response_data)
return response_data'''
'''async def send_text_to_gpt(text, batch_size=5):
api_key = "d4595b37d235460395fa78721602c87b"
url = "https://gpt-llm-4.openai.azure.com/openai/deployments/gpt-4/chat/completions?api-version=2023-03-15-preview"
headers = {"api-key": api_key}
conversation_history_with_prompt = f"You are an expert in analyzing functional requirements. Understand the extracted text. Provide summary in not less than 500 words. Summary should be crisp. Display numbers if possible from the extracted text. Dont create numbers on your own: {text}"
query_data = {"messages": [{"role": "system", "content": conversation_history_with_prompt}],
"temperature": 0, "top_p": 1, "frequency_penalty": 0, "presence_penalty": 0,
"max_tokens": 4096, "stop": None}
num_chunks = math.ceil(len(text) / (4096 // 2))
chunk_size = math.ceil(len(text) / num_chunks)
chunks = []
for i in range(0, len(text), chunk_size):
chunks.append(text[i:i + chunk_size])
results = []
for i in range(0, len(chunks), batch_size):
batch = chunks[i:i + batch_size]
query_data["messages"][0]["content"] = conversation_history_with_prompt + ' '.join(batch)
results.extend(await asyncio.gather(*[send_chunk_to_gpt(url, headers, query_data) for _ in range(len(batch))]))
response_data = results.json()
#self.store_gpt_response_data(response_data)
return response_data'''
def provide_summary(self):
if MainWindow.text==None:
QMessageBox.warning(self, "Warning", "Please upload a document first!")
else:
progress_dialog = QProgressDialog("Summary getting created...", None, 0, 100 , self)
progress_dialog.resize(400,100)
progress_style = ProgressDialogStyle()
progress_style.set_style(progress_dialog)
progress_dialog.setWindowTitle("In progress")
progress_dialog.setWindowModality(Qt.ApplicationModal)
progress_dialog.setAutoClose(False)
progress_dialog.setAutoReset(False)
progress_dialog.setMinimumDuration(0)
progress_dialog.forceShow()
for progress in range(0, 101, 3):
progress_dialog.setValue(progress)
QApplication.processEvents()
progress_dialog.setLabelText(f"Please wait while the summary is being created...")
QApplication.instance().processEvents()
QThread.msleep(100)
self.send_text_to_gpt(MainWindow.text)
progress_dialog.close()
if hasattr(self, "response_data"):
summary_message = f"Response from Advisory GPT at {datetime.now().strftime('%m/%d/%Y %I:%M %p')}:\n\n"
summary_text = self.response_data["choices"][0]["message"]["content"]
print("summart text", summary_text)
if '200' in str(MainWindow.summary_response):
MainWindow.gen_tst_case = False
else:
summary_text = "Response not recieved. Please check GPT URL"
MainWindow.gen_tst_case = False
final_summary_text = f"{summary_message} {summary_text}"
self.summary_label.setPlainText(final_summary_text)
self.summary_label.setStyleSheet("color: black; background-color: white;")
MainWindow.summary_button.setEnabled(False)
MainWindow.summary_button.setStyleSheet("background-color: green; color: white; font-weight: bold; border-radius: 5px;")
MainWindow.generate_test_cases_button.setEnabled(True)
MainWindow.generate_test_cases_button.setStyleSheet("background-color: #29465B; color: white; font-weight: bold; border-radius: 5px;")
# MainWindow.generate_automation_scripts_button.setEnabled(True)
# MainWindow.generate_automation_scripts_button.setStyleSheet("background-color: #29465B; color: white; font-weight: bold; border-radius: 5px;")
# else:
# QMessageBox.warning(self, "Warning", "Please upload a document first!")
def generate_test_requirements(self):
# MainWindow.generate_test_cases_button.setEnabled(True)
# MainWindow.gen_tst_req = True
if MainWindow.text==None:
QMessageBox.warning(self, "Warning", "Please upload a document first!")
else:
progress_dialog1 = QProgressDialog("Generating test requirements...", None, 0, 100, self)
progress_dialog1.resize(400,100)
progress_style = ProgressDialogStyle()
progress_style.set_style(progress_dialog1)
progress_dialog1.setWindowTitle("In progress")
progress_dialog1.setWindowModality(Qt.ApplicationModal)
progress_dialog1.setAutoClose(False)
progress_dialog1.setAutoReset(False)
progress_dialog1.setMinimumDuration(0)
progress_dialog1.forceShow()
for progress in range(0, 101, 3):
progress_dialog1.setValue(progress)
QApplication.processEvents()
progress_dialog1.setLabelText(f"Please wait while the test requirements are being generated...")
QApplication.instance().processEvents()
QThread.msleep(100)
#self.send_text_to_gpt(MainWindow.text)
self.api_key = "73c315ba0bc44e6abffd10b189dc3199"
self.url = "https://gpt-llm-4.openai.azure.com/openai/deployments/gpt-4/chat/completions?api-version=2023-03-15-preview"
#self.api_key = "d4595b37d235460395fa78721602c87b"
#self.url = "https://oai-kgsgpt-testapp.openai.azure.com/openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-03-15-preview"
'''
conversation_history_with_prompt = f"""You are an expert in analyzing functional and non functional test case requirements. Understand the below text.
-----
{MainWindow.text}
-----
Generate all possible functional and non functional test Requirements in detail.
Requirements should be non-ambiguous and should be point wise.
Each test case should be associated with a test case ID and should be in the below format:
-----------
<Test case ID>: <Test requirement 1>
<test case ID>: <Test requirement 2>
-----------
A line should separate the functional and non functional requirements."""
'''
'''
conversation_history_with_prompt = f"""You are an expert in analyzing functional and non functional test case requirements. Understand the below text.
-----
{MainWindow.text}
-----
Generate all possible functional and non functional test Requirements in detail.
A line should separate the functional and non functional requirements.
Each requirement should have a unique requirement ID and the requirements should be non-ambiguous and should be point wise.
For each requirement, all possible sub requirements need to be generated point wise.
There can be one or more sub requirements under each requirement.
There should be no ambiguity or repitions.
Each sub requirement should be associated with a unique test case ID.
Do not generate any code.
The output should be in plain text, point wise and prescise
The output must be of the below format:
-----------
Requirement 1: <requirement ID> <Requirement description>
<Test case ID>: <Sub-equirement 1 description>
<test case ID>: <Sub-equirement 2 description>
Requirement 2: <requirement ID> <Requirement description>
<Test case ID>: <Sub-equirement 1 description>
<test case ID>: <Sub-equirement 2 description>
-----------
The sub requirements descriptions must be related to the main requirement description
There can be one or many sub requirements under each requirement.
Requirements and sub requirements need to make sense and needs to be properly grouped."""
'''
conversation_history_with_prompt = f"""As a proficient analyst of functional and non-functional test case requirements, your task is to comprehend the following text and generate suitable requirements.
-----
{MainWindow.text}
-----
Prepare a comprehensive list of all possible functional and non-functional requirements in meticulous detail. Specific instructions:
1. Maintain a distinct partition for functional and non-functional requirements.
2. Each requirement should possess a unique ID, allowing for simpler identification and no possibility of duplicate entries.
3. Formulate the requirements in a manner that avoids any ambiguity- they should aim to be concise, precise and clearly stated.
4. Within each requirement, you must generate a list of all possible sub-requirements. Assign a unique test case ID to each sub-requirement.
5. Avoid generating any code.
6. Your output should be formatted in plain text and must abode by the following pattern:
-----------
Requirement 1: <requirement ID> <Requirement description>
<Test case ID>: <Sub-requirement 1 description>
<Test case ID>: <Sub-requirement 2 description>
Requirement 2: <requirement ID> <Requirement description>
<Test case ID>: <Sub-requirement 1 description>
<Test case ID>: <Sub-requirement 2 description>
-----------
7. Ensure the description of each sub-requirement is directly relevant to the main requirement.
8. There may be multiple sub-requirements under each main requirement.
9. Requirements and sub requirements must make sense and be properly categorized under each respective group.
"""
headers = {"api-key": self.api_key}
query_data = {
"messages": [
{"role": "system", "content": conversation_history_with_prompt}
],
"temperature": 0,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
"max_tokens": 4096,
"stop": None,
}
req_response = requests.post(self.url, headers=headers, json=query_data, verify=False)
MainWindow.req_response_data = req_response.json()
self.store_gpt_response_data(MainWindow.req_response_data)
if hasattr(self, "response_data"):
progress_dialog1.close()
summary_message = f"Response from Advisory GPT at {datetime.now().strftime('%m/%d/%Y %I:%M %p')}:\n\n"
choices = self.response_data.get("choices", [])
'''
if choices:
MainWindow.gen_tst_case = False
summary_text = choices[0]["message"]["content"]
else:
summary_text = "Response not recieved. Please check GPT URL"
'''
if '200' in str(req_response):
MainWindow.gen_tst_case = False
summary_text = MainWindow.req_response_data["choices"][0]["message"]["content"]
else:
summary_text = "Response not recieved. Please check GPT URL"
MainWindow.req_txt = summary_text
summary_text = f"{summary_message} {summary_text}"
self.summary_label.setPlainText(summary_text)
self.summary_label.setStyleSheet("color: black; background-color: white;")
MainWindow.generate_test_requirements_button.setEnabled(False)
MainWindow.generate_test_requirements_button.setStyleSheet("background-color: green; color: white; font-weight: bold; border-radius: 5px;")
MainWindow.generate_test_cases_button.setEnabled(True)
MainWindow.generate_test_cases_button.setStyleSheet("background-color: #29465B; color: white; font-weight: bold; border-radius: 5px;")
MainWindow.generate_automation_scripts_button.setEnabled(False)
MainWindow.generate_automation_scripts_button.setStyleSheet("background-color: #B6B6B4; color: white; font-weight: bold; border-radius: 5px;")
MainWindow.summary_button.setEnabled(False)
MainWindow.summary_button.setStyleSheet("background-color: green; color: white; font-weight: bold; border-radius: 5px;")
# else:
# QMessageBox.warning(self, "Warning", "Please upload a document first!")
def generate_test_cases(self, prompt):
# # For example:
# for progress_val in range(0, 101, 3):
# QApplication.processEvents()
# progress = QProgressBar(self)
# if progress:
# progress.setValue(progress_val)
# QApplication.instance().processEvents()
# QThread.msleep(100)
if hasattr(self, "response_data"):
self.api_key = "73c315ba0bc44e6abffd10b189dc3199"
self.url = "https://gpt-llm-4.openai.azure.com/openai/deployments/gpt-4/chat/completions?api-version=2023-03-15-preview"
#self.api_key = "d4595b37d235460395fa78721602c87b"
#self.url = "https://oai-kgsgpt-testapp.openai.azure.com/openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-03-15-preview"
headers = {"api-key": self.api_key}
query_data = {
"messages": [
{"role": "system", "content": "You are a helpful assistant that generate testcases to validate different oracle applications"},
{"role": "user", "content": prompt}
],
"temperature": 0,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
"max_tokens": 4096,
"stop": None,
}
response = requests.post(self.url, headers=headers, json=query_data, verify=False)
print("Generate test cases Response:",response)
MainWindow.generate_test_response_data = response.json()
#print("Response_data:",response_data)
if '200' in str(response):
MainWindow.gen_tst_case = True
self.functional_test_cases = MainWindow.generate_test_response_data["choices"][0]["message"]["content"]
else:
test_cases_text = "Response not recieved. Please check GPT URL"
MainWindow.test_cases = self.functional_test_cases
test_cases_message = f"Test Cases generated by Advisory GPT at {datetime.now().strftime('%m/%d/%Y %I:%M %p')}:\n\n"
test_cases_text = f"{test_cases_message} {self.functional_test_cases}"
self.summary_label.setPlainText(test_cases_text)
#self.summary_label.setPlainText(str(table))
self.summary_label.setStyleSheet("color: black; background-color: white;")
MainWindow.generate_test_cases_button.setEnabled(False)
MainWindow.generate_test_cases_button.setStyleSheet("background-color: green; color: white; font-weight: bold; border-radius: 5px;")
MainWindow.generate_automation_scripts_button.setEnabled(True)
MainWindow.generate_automation_scripts_button.setStyleSheet("background-color: #29465B; color: white; font-weight: bold; border-radius: 5px;")
MainWindow.upload_to_opkey_button.setEnabled(True)
MainWindow.upload_to_opkey_button.setStyleSheet("background-color: #29465B; color: white; font-weight: bold; border-radius: 5px;")
MainWindow.generate_test_requirements_button.setEnabled(False)
MainWindow.generate_test_requirements_button.setStyleSheet("background-color: green; color: white; font-weight: bold; border-radius: 5px;")
else:
QMessageBox.warning(self, "Warning", "Please upload a document first!")
def test_type(self):
test_dialog = QDialog(self)
test_dialog.resize(600, 150)
dialog_style =ButtonDialogStyle()
dialog_style.set_style(test_dialog)
test_dialog.setWindowTitle("Select the type of test case")
vbox = QVBoxLayout()
test_dialog.setLayout(vbox)
# label = QLabel("Select the type of test case:")
# vbox.addWidget(label)
combo = QComboBox()
combo.setMinimumWidth(200)
combo.setStyleSheet("background-color: white; border-radius: 5px; min-height: 1.3em; padding: 3px 10px")
combo.move(60, 30)
combo.addItem("(default) Select the type of testing...")
combo.addItem("Functional Test Cases")
combo.addItem("Non-Functional Test Cases")
combo.addItem("Unit Test Cases")
combo.addItem("Performance Test Cases")
combo.addItem("Regression Test Cases")
combo.addItem("Integration Test Cases")
combo.addItem("Smoke Test Cases")
combo.addItem("Security Test Cases")
combo.addItem("End-to-end Test Cases")
vbox.addWidget(combo)
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
vbox.addWidget(button_box)
button_box.accepted.connect(test_dialog.accept)
button_box.rejected.connect(test_dialog.reject)
result = test_dialog.exec_()
if result == QDialog.Accepted:
test_type = combo.currentText()
MainWindow.generate_test_type_user_input = test_type
progress_dialog2 = QProgressDialog("generating_test_cases...", None, 0, 100, self)
progress_dialog2.resize(400,100)
progress_style = ProgressDialogStyle()
progress_style.set_style(progress_dialog2)
progress_dialog2.setWindowTitle("In progress")
progress_dialog2.setWindowModality(Qt.ApplicationModal)
progress_dialog2.setAutoClose(False)
progress_dialog2.setAutoReset(False)
progress_dialog2.setMinimumDuration(0)
progress_dialog2.forceShow()
for progress in range(0, 101, 3):
progress_dialog2.setValue(progress)
QApplication.processEvents()
progress_dialog2.setLabelText(f"Please wait while the test cases are generating..")
QApplication.instance().processEvents()
QThread.msleep(150)
if MainWindow.gen_tst_req and (test_type=="Functional Test Cases" or test_type=="Non-Functional Test Cases"):
prompt=''
if test_type!="(default) Select the type of testing...":
#self.send_text_to_gpt(MainWindow.text)
# prompt=f"""You are an expert test engineer. Generate only the {test_type} in detail from the below text:
# ---------------
# {MainWindow.req_txt}
# ---------------
# The requirement ID in the response should should be the same as in the above text.
# The requirement description in the response should should be the same as in the above text.
# The test case ID in the response should should be the same as in the above text.
# The number of test cases generated should be in the same as mentioned in the above text and should be in the same order as well.
# Each test case should have: 'Requirement ID', 'Requirement Description',Test Case ID', 'Description', 'Detailed Steps', and 'Expected Results'.
# The Detailed Steps should be as descriptive as possible and should be mentioned point wise.
# Each test case should be separated.
# Do not generate a code.
# Sample test case:
# 1. Requirement ID: <this should match with the requirement ID in the above text>
# Requirement Description: <this should match with the requirement description in the above text>
# Test Case ID: <this should match with the test case ID in the above text>
# Description:
# Detailed Steps:
# Expected Result:
# All generated test cases should strictly adhere to above format.
# """
prompt = f"""As a seasoned test engineer with a focus on SAP FIORI applications, your task is to generate {test_type} intuitively and meticulously. Use the following text as your source:
---------------
{MainWindow.req_txt}
---------------
Balance consistency and relevance in your output. Ensure that the 'Requirement ID', 'Requirement Description' and 'Test Case ID' in your response match exactly with the information given in the text.
The test cases you generate should correlate with the numbers mentioned in the text, maintaining their order. Each case should provide information on 'Requirement ID', 'Requirement Description', 'Test Case ID', a clear 'Description', 'Detailed Steps', and 'Expected Results'.
Strive for descriptiveness and clarity in the 'Detailed Steps' section and split this information into points for easier comprehension. Don't forget to differentiate each test case clearly.
Note that no additional code should be generated – we're solely focusing on the analysis and construction of test cases.
Sample testcase:
Requirement ID: FR1
Requirement Description: Order Processing
Test Case ID: TC1
Description: Verify the functionality of sales order creation.
Detailed Steps:
1.1. Launch the application.
1.2. Enter the sales representative username and password in the respective fields.