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
|
# import os
import inspect
import time
from selenium.webdriver import Keys
from selenium.webdriver.support.wait import WebDriverWait
# sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from support.ui_utils.profiles.page_jump import PageJump
from selenium.webdriver.common.by import By
from support.ui_utils.element_position.profile_element_position import *
from selenium.webdriver.common.action_chains import ActionChains
from datetime import datetime
from selenium.webdriver.support import expected_conditions as EC
from support.api_utils.util_statistics_template import UtilStatisticsTemplate
class CreateStatisticsTemplate():
def __init__(self, driver):
self.driver = driver
self.actions = ActionChains(self.driver)
def create_statistics_template(self, policy_configuration):
data = policy_configuration
template_element_position = {}
page_jump_element_position = template_element_position["page_jump"]
create_element_position = template_element_position["create"]
try:
# 页面跳转
page_jump = PageJump(self.driver)
page_jump.jump_sub_profile_page(page_jump_element_position)
# 点击create
self.driver.find_element(By.XPATH, create_element_position["templateListPage_createButton_posXpath"]).click()
"""
elements = self.driver.find_element(By.XPATH, create_element_position["listPage_profileHandleButton_posXpath"]).click()
if len(elements) > 0:
ele_index = 0
for element in elements:
if ele_index == 0:
element.click()
break
ele_index = ele_index + 1
"""
# 输入name
template_name = data["name"]
#self.driver.find_element(By.ID, create_element_position["templatePage_inputName_posId"]).send_keys(template_name)
self.driver.find_element(By.XPATH, create_element_position["statisticsTemplates_input_Name_posXpath"]).send_keys(template_name)#//input[@class='MuiInput-input css-fqt4w4']
self.data = data
# 循环操作每个chart
charts = data["charts"] # charts数据列表
operation_type = "create"
no_modify = ""
data_index = 0
for i in range(len(charts)):
chart_id = "{}".format(i + 1) # 用于图表排序定位使用
# 点击chart add添加按钮
if operation_type == "create": # 创建时点击添加图表,修改时不点击添加图表
self.driver.find_element(By.XPATH, create_element_position["templates_button_chartAdd_posXpath"]).click()
else: # 修改数据,先点击修改按钮 "Edit"编辑修改
#statisticsTemplates_button_chartEdit_posXpath_1 = create_element_position[
# "templates_button_chartEdit_posXpath"].format(
# replaceChart=chart_id)
#self.driver.find_element(By.XPATH, statisticsTemplates_button_chartEdit_posXpath_1).click()
elements = self.driver.find_elements(By.XPATH, create_element_position[
"listPage_profileHandleButton_posXpath"])
if len(elements) >= 2:
ele_index = 0
for element in elements:
if ele_index == 1:
element.click()
break
ele_index = ele_index + 1
time.sleep(2)
# 页面滚动到最底部
# self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# 内嵌页面滚动条向下滚动到最底部
#time.sleep(2)
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template5,scroll")
div_paper_grid = self.driver.find_element(By.XPATH, create_element_position["templates_div_paperGrid_posXpath"])
self.driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight;", div_paper_grid)
# Visualization Type 操作
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template6,Visualization Type")
self._operate_radio(charts[i], data_index=data_index, no_modify=no_modify,
data_key="visualization_type",
ep_radio=create_element_position["templates_radio_visualizationType_posXpath"],
chart_id=chart_id)
# metrics 操作
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template7,metrics")
#24.10版本默认无Metrics新增空白行,所以首次打开Chart界面选择Visualization Type后先点击Metrics添加按钮
self.driver.find_element(By.XPATH, statisticsTemplates_button_metricsAndDimensionsAdd_posXpath.format(replaceChart=chart_id, repalceLabel="Metrics")).click()
self._operate_metrics_or_dimensions_dropdown(charts[i], data_index=data_index, no_modify=no_modify,
data_key="metrics", chart_id=chart_id)
visualization_type_temp = charts[i]["visualization_type"].split("->")[data_index].strip().lower()
metrics_no_dimension_temp = {"session_identifier_sketch", "client_ip_sketch", "server_ip_sketch'"}
first_metric_temp = charts[i]["metrics"][0].split(":")[0]
# if first_metric_temp not in{"","不修改","刪除"}:#修改数据待补充处理方式
if visualization_type_temp == "table" or visualization_type_temp == "bar" or visualization_type_temp == "line": # 只有table\Bar 图的 有order by操作
if visualization_type_temp == "line" and (first_metric_temp in metrics_no_dimension_temp or len(charts[i]["metrics"]) > 1):
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Line No Dimensions")
else:
# dimensions 操作
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template8,dimensions")
# 24.10版本默认无Dimensions新增空白行,所以首次打开Chart界面选择Visualization Type后先点击Dimensions添加按钮
self.driver.find_element(By.XPATH, statisticsTemplates_button_metricsAndDimensionsAdd_posXpath.format(replaceChart=chart_id, repalceLabel="Dimensions")).click()
self._operate_metrics_or_dimensions_dropdown(charts[i], data_index=data_index, no_modify=no_modify, data_key="dimensions", chart_id=chart_id) # 如果有Order By,则操作
if visualization_type_temp == "table" or visualization_type_temp == "bar": # 只有table\Bar 图的 有order by操作
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template9,Order By")
self._operate_order_by(charts[i], data_index=data_index, no_modify=no_modify,data_key="order_by", chart_id=chart_id)
else:
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "No Order By")
# Row Limit 操作
visualization_type_temp = charts[i]["visualization_type"].split("->")[data_index].strip().lower()
if visualization_type_temp == "line" or visualization_type_temp == "table" or visualization_type_temp == "bar": # line 图的 row limit 操作方式不一样
if visualization_type_temp == "line" and (
first_metric_temp in metrics_no_dimension_temp or len(charts[i]["metrics"]) > 1):
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "No Row Limit")
else:
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template10,No Row Limit")
self._operate_series_limit(charts[i], data_index=data_index, no_modify=no_modify,
data_key="row_limit",
element_position=create_element_position[
"templates_input_other_posXpath"],
chart_id=chart_id)
else:
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "No Row Limit")
"""
elif charts[i]["visualization_type"].split("->")[
data_index].strip().lower() == "table": # table 图的 row limit 操作
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "table---row limit")
self._operate_input(charts[i], data_index=data_index, no_modify=no_modify, data_key="row_limit",
element_position=create_element_position["templates_input_other_posXpath"],
chart_id=chart_id)
"""
# Thresholds - Minimum incoming size 操作
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template11,No Row Limit")
self._operate_input(charts[i], data_index=data_index, no_modify=no_modify, data_key="min_in_size",
element_position=create_element_position["templates_input_thresholds_posXpath"],
chart_id=chart_id)
# Thresholds - Minimum outgoing size 操作
self._operate_input(charts[i], data_index=data_index, no_modify=no_modify, data_key="min_out_size",
element_position=create_element_position["templates_input_thresholds_posXpath"],
chart_id=chart_id)
# 输入chart name
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template12,chart name")
self._operate_input(charts[i], data_index=data_index, no_modify=no_modify, data_key="chart_name",
element_position=create_element_position["templates_input_other_posXpath"],
chart_id=chart_id)
# 点击chart的OK保存按钮
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Click the chart OK save button")
#self.driver.find_element(By.XPATH, create_element_position["templates_button_ChartOK_posXpath"]).click()
chart_ok_btn = self.driver.find_element(By.XPATH, create_element_position["templates_button_chartOK_posXpath"].format(replaceChart=chart_id))
self.driver.execute_script("arguments[0].scrollIntoView();", chart_ok_btn)
self.driver.execute_script("arguments[0].click();", chart_ok_btn)
# 确认创建,点击Template的OK保存按钮
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template14,Template OK")
#self.driver.find_element(By.CSS_SELECTOR, create_element_position["templates_button_oK_posCss"]).click()
self.driver.find_element(By.XPATH, create_element_position["templates_button_oK_posCss"]).click()
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template14,Template warningSaveYes")
#self.driver.find_element(By.CSS_SELECTOR,create_element_position["templates_button_warningSaveYes_posCss"]).click()
"""
warning_save_yes_btn = self.driver.find_element(By.CSS_SELECTOR,create_element_position["templates_button_warningSaveYes_posCss"])
self.driver.execute_script("arguments[0].scrollIntoView();", warning_save_yes_btn)
self.driver.execute_script("arguments[0].click();", warning_save_yes_btn)
"""
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], self.driver.find_element(By.CSS_SELECTOR,
# create_element_position["templates_button_warningSaveYes_posCss"]).is_enabled())
# print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template14,Template warningSaveYes after")
return 200
except Exception as e:
self.error_print_function(inspect.currentframe().f_code.co_name, e)
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Exception: {e}")
raise
#return 400
def _operate_radio(self, chart, data_index=0, no_modify="不修改", data_key="", ep_radio="", chart_id=""):
"""
单选按钮操作
:param data:
:param data_index: 0 -1 创建或修改数据索引
:param no_modify:
:param data_key: 搜索 visualization_type 和 sampling
:param ep_radio: 单选按钮定位
:param chart_id: 图表id
:return:
"""
try:
# 解析输入data数据的数据
data_value: str = self._get_value_from_data(chart, key=data_key, data_index=data_index) # 提取数据 Table
data_value = "_".join(data_value.lower().split()) # Table
if data_value != no_modify: # 判断修改时不修改时跳过操作。
if data_key == "visualization_type": # visualization_type 元素定位重组
replace_type_dict = {'table': 'Table', 'line': 'Line', 'bar': 'Bar', 'histogram': 'Histogram'}
repalceLabel = "Visualization Type"
ep_attackType_radio = ep_radio.format(replaceChart=chart_id, repalceLabel=repalceLabel, replaceType=replace_type_dict[data_value])
# 点击点选按钮
self.driver.find_element(By.XPATH, ep_attackType_radio).click()
"""
else: # sampling 元素定位重组
replace_sampling_dict = {'comprehensive': 'Comprehensive',
'top-k': 'Top-K'} # Comprehensive:***, Top-K:***:***
repalceLabel = "Sampling"
ep_attackType_radio = ep_radio.format(replaceChart=chart_id, repalceLabel=repalceLabel,
replaceSampling=replace_sampling_dict[
data_value.split(":")[0]])
"""
return 200
except Exception as e:
self.error_print_function(inspect.currentframe().f_code.co_name, e)
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Exception: {e}", file=sys.stderr)
raise
#return 400
def _get_value_from_data(self, data, key="", data_index=0):
"""
从data数据中,根据key提取值
:param data:
:param key:
:param data_index: 0 -1
:return:
"""
try:
switch_value: str = data[key].split("->")[data_index].strip() # 用例数据
except Exception as e:
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Exception: {e}")
raise
return switch_value
def _operate_order_by(self, chart, data_index=0, no_modify="不修改", data_key="", chart_id=""):
try:
data_value: str = self._get_value_from_data(chart, key=data_key, data_index=data_index) # 提取数据 Table
if data_value == "":
return 0
elif "Random" == data_value:# 如果是Metrics Type为Distribution的Aggregate Function,则Order By为Random,只读不可操作
# Order By为Random,状态只读不可操作
# //form[contains(@class, 'ly-addform1')]/div[contains(@class, 'template-edit-chart')][1]//label[normalize-space(text())='Order By']/parent::*//input
#order_by_value = self.driver.find_element(By.XPATH, statisticsTemplates_input_posXpath.format(replaceChart = chart_id, repalceLabel = "Order By")).get_attribute("value")
#order_by_status = self.driver.find_element(By.XPATH, statisticsTemplates_input_posXpath.format( replaceChart=chart_id, repalceLabel="Order By")).get_attribute("readonly")
order_by_value = self.driver.find_element(By.XPATH, statisticsTemplates_input_other_posXpath.format(replaceChart=chart_id, repalceLabel="Order By")).get_attribute("value")
order_by_status = self.driver.find_element(By.XPATH, statisticsTemplates_button_other_posXpath.format( replaceChart=chart_id, repalceLabel="Order By")).get_attribute("disabled")
if order_by_value == "Random" and order_by_status == "true":
return 200
else:
raise f"When Fields Metrics Type is distribution, the Order By value should be Random and the status is read-only. The actual value is {order_by_value} and the status is {order_by_status}."
elif data_value != no_modify: # 判断修改时不修改时跳过操作。
dropdown_name = "Order By"
# 如果默认选择项为目标选择项则不操作,否则点击打开Order By 下拉列表重新选择Order By
order_by_value = self.driver.find_element(By.XPATH, statisticsTemplates_input_other_posXpath.format(replaceChart=chart_id, repalceLabel=dropdown_name)).get_attribute("value")
if order_by_value != data_value:
# 组织元素并点击下拉菜单 create_element_position["templates_button_other_posXpath"]
ep_order_by_Select = statisticsTemplates_button_other_posXpath.format(replaceChart=chart_id, repalceLabel=dropdown_name) # 下拉框定位
# 将span替换为label,定位不一样
ep_order_by_Select = ep_order_by_Select.replace("span", "label")
self.driver.find_element(By.XPATH, ep_order_by_Select).click()
# 点击下拉列表的item选项
#ep_metricsAndDimensionsDropdownItem = statisticsTemplates_dropdown_posXpath.format(replaceChart=chart_id, repalceLabel=dropdown_name, replaceDropdownIterm=data_value)
ep_metricsAndDimensionsDropdownItem = statisticsTemplates_dropdown_posXpath.format(replaceDropdownIterm=data_value)
element_dropdown_item = self.driver.find_element(By.XPATH, ep_metricsAndDimensionsDropdownItem)
# 移动元素到页面,在执行点击
#self.actions.move_to_element(element_dropdown_item).perform()
self.driver.execute_script("arguments[0].scrollIntoView();", element_dropdown_item)
self.driver.execute_script("arguments[0].click();", element_dropdown_item)
return 200
except Exception as e:
self.error_print_function(inspect.currentframe().f_code.co_name, e)
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Exception: {e}")
raise
#return 400
def _operate_metrics_or_dimensions_dropdown(self, chart, data_index=0, no_modify="不修改", data_key="",chart_id=""):
"""
操作metrics dimensions函数
:param chart: 每个chart的字典数据
:param data_index:
:param no_modify:
:param data_key: 可取值:metrics dimensions
:param chart_id: chart_id UI页面中chart id序号
:return:
"""
# 24.08版本开始:Metrics和Dimensions字典,前28个既可以为Metrics也可以为Dimensions
util = UtilStatisticsTemplate()
if data_key == "metrics":
code, dropdown_item_metrics_dict = util.get_all_metrics_or_dimensions("metrics")
if code != 200:
# print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Class:CreateStatisticsTemplate;Funcation:_operate_metrics_or_dimensions_dropdown();Exception: Parsing Dimension Error")
return 400
metrics_or_dimensions = chart[data_key] # metrics 数据列表
dropdown_item_dict = dropdown_item_metrics_dict
repalceLabel = "Metrics"
else: # dimensions
code, dropdown_item_dimensions_dict = util.get_all_metrics_or_dimensions("dimensions")
if code != 200:
# print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Class:CreateStatisticsTemplate;Funcation:_operate_metrics_or_dimensions_dropdown();Exception: Parsing Dimension Error")
return 400
metrics_or_dimensions = chart[data_key] # dimensions 数据列表
dropdown_item_dict = dropdown_item_dimensions_dict
repalceLabel = "Dimensions"
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], metrics_or_dimensions)
try:
# print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], 666)
for j in range(len(metrics_or_dimensions)): # 循环操作metrics
# repalceLabel = "Metrics" # 定位重组参数使用
dropdown_item = metrics_or_dimensions[j].strip().split("->")[data_index]#.lower() # 提取数据
#dropdown_item = "_".join(dropdown_item.split()) # outgoing_bytes
drop_item_old = metrics_or_dimensions[j].strip().split("->")[0].lower() # 创建的数据,修改或删除使用
#drop_item_old = "_".join(drop_item_old.split())
if dropdown_item != no_modify: # 编辑遇到不修改时,不处理
if dropdown_item == "": # 修改数据参数中,creat为空
continue
elif dropdown_item == "删除": # 执行删除命令
self.dropdown_del(chart_id=chart_id, dropdown_name=repalceLabel, old_value=drop_item_old,
dropdown_item_dict=dropdown_item_dict)
else: # 新增或修改
if data_index == -1: # 修改数据,修改数据情况
if drop_item_old == "": # ->3.4.3.2的的格式数据,表示修改中的新增
self.dropdown_add(chart_id=chart_id, dropdown_name=repalceLabel,
new_value=dropdown_item, dropdown_item_dict=dropdown_item_dict)
else: # 4.3.4.3->4.5.6.8 表示修改原数据
self.dropdown_modify(chart_id=chart_id, dropdown_name=repalceLabel,
old_value=drop_item_old, new_value=dropdown_item,
dropdown_item_dict=dropdown_item_dict)
else: # 新增数据 4.5.6.3->
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"pass:dropdown_add:{len(metrics_or_dimensions)}")
self.dropdown_add(chart_id=chart_id, dropdown_name=repalceLabel, new_value=dropdown_item, dropdown_item_dict=dropdown_item_dict)
return 200
except Exception as e:
self.error_print_function(inspect.currentframe().f_code.co_name, e)
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Exception: {e}")
raise
#return 400
def _operate_input(self, chart, data_index=0, no_modify="不修改", data_key="", element_position="",
chart_id=""):
"""
页面中输入框类型操作
:param data:
:param data_index:
:param no_modify:
:param data_key: 数据key
:param element_position: 输入框元素定位
:return:
"""
try:
data_value: str = self._get_value_from_data(chart, key=data_key, data_index=data_index) # 提取value数据
if data_value == "": # 无值时不操作
return 0
replaceName = ""
if data_value != no_modify: # 编辑时,有不修改则不用执行
if data_key in ["min_in_size","min_out_size"]:
if data_key == "min_in_size":
repalceLabel = "Minimum Incoming size"
replaceName = "threshold.in_bytes"
elif data_key == "min_out_size": # Minimum outgoing size
repalceLabel = "Minimum Outgoing size"
replaceName = "threshold.out_bytes"
data_value_1 = data_value
element_position_1 = element_position.format(replaceChart=chart_id, repalceLabel=repalceLabel,replaceName=replaceName)
input_value = self.driver.find_element(By.XPATH, element_position_1).get_attribute("value")
if data_value_1 != input_value:
self.driver.find_element(By.XPATH, element_position_1).send_keys(Keys.CONTROL + 'a')
self.driver.find_element(By.XPATH, element_position_1).send_keys(data_value_1)
else: # chart name 输入框
repalceLabel = "Chart Name"
#if repalceLabel == "Chart Name":
data_value = "_".join(data_value.lower().split())
if data_value == "default_name":
# 点击Default Name
element_position_1 = element_position.format(replaceChart=chart_id, repalceLabel=repalceLabel) # input的定位,接下来向上反找,在向下找
#element_position_1 = element_position_1.replace("span","label") # chart name中的定位,需要将span替换为label
#self.driver.find_element(By.XPATH, element_position_1).find_element(By.XPATH, "./parent::*/parent::*//span").click()
#element_dropdown_item = self.driver.find_element(By.XPATH, element_position_1).find_element(By.XPATH,"./parent::*/parent::*//span")
element_dropdown_item = self.driver.find_element(By.XPATH, statisticsTemplates_button_other_posXpath.format(replaceChart=chart_id, repalceLabel=repalceLabel))
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template12,chart name")
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], element_dropdown_item.is_enabled())
self.driver.execute_script("arguments[0].scrollIntoView();", element_dropdown_item)
#self.actions.move_to_element(element_dropdown_item).perform()
self.driver.execute_script("arguments[0].click();", element_dropdown_item)
return 0
elif data_value == "": # 输入框为空
return 0
data_value_1 = data_value
element_position_1 = element_position.format(replaceChart=chart_id, repalceLabel=repalceLabel,replaceName=replaceName)
self.driver.find_element(By.XPATH, element_position_1).send_keys(Keys.CONTROL + 'a')
self.driver.find_element(By.XPATH, element_position_1).send_keys(data_value_1)
# 定位元素中span换成label
#element_position_1 = element_position_1.replace("span", "*")
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], element_position_1)
return 200
except Exception as e:
self.error_print_function(inspect.currentframe().f_code.co_name, e)
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Exception: {e}")
raise
#return 400
def _operate_series_limit(self, chart, data_index=0, no_modify="不修改", data_key="", element_position="",
chart_id=""):
"""
页面中输入框类型操作
:param data:
:param data_index:
:param no_modify:
:param data_key: 数据key
:param element_position: 输入框元素定位
:return:
"""
try:
data_value: str = self._get_value_from_data(chart, key=data_key, data_index=data_index) # 提取value数据
if data_value == "": # 无值时不操作
return 0
if data_value != no_modify: # 编辑时,有不修改则不用执行
if data_key == "row_limit":
if chart["visualization_type"].strip().lower() == "line": # line图的 row limit 改变了
repalceLabel = "Series Limit"
else:
repalceLabel = "Row Limit"
data_value_1 = data_value
element_position_1 = element_position.format(replaceChart=chart_id, repalceLabel=repalceLabel)
# 定位元素中span换成label
#element_position_1 = element_position_1.replace("span", "*")
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], self.driver.find_element(By.XPATH, element_position_1).is_enabled())
#self.driver.execute_script("arguments[0].scrollIntoView();", element_dropdown_item)
#self.driver.execute_script("arguments[0].click();", element_dropdown_item)
#浏览器模式下定位
self.driver.find_element(By.XPATH, element_position_1).click()
#无浏览器模式下定位
#element_position_1 = self.driver.find_element(By.XPATH, element_position_1)
#self.driver.execute_script("arguments[0].scrollIntoView();", element_position_1)
#self.driver.execute_script("arguments[0].click();", element_position_1)
self.driver.find_element(By.XPATH, element_position_1).send_keys(Keys.CONTROL + 'a')
self.driver.find_element(By.XPATH, element_position_1).send_keys(data_value_1)
#element_dropdown_item = self.driver.find_element(By.XPATH, element_position_1). \
#find_element(By.XPATH, f"./ancestor::*[contains(@class, 'el-form-item el-form-item--small')]//*[contains(@class, 'el-select-dropdown__list')]/li/span[normalize-space(text())='{data_value_1}']")
element_dropdown_items = self.driver.find_elements(By.XPATH, statisticsTemplates_after_search_dropdown_posXpath.format(replaceDropdownIterm = data_value_1))
if len(element_dropdown_items) == 1:
element_dropdown_item = self.driver.find_element(By.XPATH, statisticsTemplates_after_search_dropdown_posXpath.format(replaceDropdownIterm = data_value_1))
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "template10,No Row Limit")
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], element_dropdown_item.is_enabled())
#self.actions.move_to_element(element_dropdown_item).perform()
self.driver.execute_script("arguments[0].scrollIntoView();", element_dropdown_item)
self.driver.execute_script("arguments[0].click();", element_dropdown_item)
# self.driver.find_element(By.XPATH, element_position_1).send_keys(data_value_1)
return 200
except Exception as e:
self.error_print_function(inspect.currentframe().f_code.co_name, e)
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Exception: {e}")
raise
#return 400
def dropdown_add(self, chart_id="", dropdown_name="", new_value="", dropdown_item_dict={}):
"""
下拉列表添加内容选项操作
:param chart_id: 新增数据chart id
:param dropdown_name:下拉列表框名称类型,例如Metrics
:param new_value: 下拉列表中新增的值item
:param dropdown_item_dict: 下拉列表新增值item映射的字典
:return:
"""
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], 5555)
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], dropdown_name)
"""
dropdown_aggragate_dict = {"unique_count": "UNIQUE_COUNT",
"sum": "SUM", "rate": "RATE", "bitrate": "BITRATE",
"percentiles_hdr": "PERCENTILES_HDR", "median_hdr": "MEDIAN_HDR",
"p95_percentile_hdr": "P95_PERCENTILE_HDR",
"p99_percentile_hdr": "P99_PERCENTILE_HDR",
"approx_count_distinct_hlld": "APPROX_COUNT_DISTINCT_HLLD"}
"""
try:
if "Metrics" == dropdown_name:
ep_metricsAndDimensionsSelects = statisticsTemplates_input_metricsAndDimensionsSelect_posXpath.format(replaceChart=chart_id, repalceLabel="Metric")
elif "Dimensions" == dropdown_name:
ep_metricsAndDimensionsSelects = statisticsTemplates_input_metricsAndDimensionsSelect_posXpath.format(replaceChart=chart_id, repalceLabel="Dimention")
else:#兼容未来其他选项
ep_metricsAndDimensionsSelects = statisticsTemplates_input_metricsAndDimensionsSelect_posXpath.format(replaceChart=chart_id, repalceLabel=dropdown_name) # 下拉框定位,可能存在多个
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], ep_metricsAndDimensionsSelects, flush=True)
element_metricsAndDimensionsSelects = self.driver.find_elements(By.XPATH, ep_metricsAndDimensionsSelects) # Metrics或Dimensions的数据行数
#element_metricsAndDimensionsAdd = element_metricsAndDimensionsSelects[-1].find_element(By.XPATH, ".//i") # 下拉框元素列表中最后一个为add添加按钮
element_metricsAndDimensionsAdd = self.driver.find_element(By.XPATH, statisticsTemplates_button_metricsAndDimensionsAdd_posXpath.format(replaceChart=chart_id, repalceLabel=dropdown_name))
# 点击添加按钮
# 下拉列表
time.sleep(1)
is_click_add = "yes_click"
for dropdownSelect_item in element_metricsAndDimensionsSelects:
dropdown_input = dropdownSelect_item.find_elements(By.XPATH, ".//div[contains(@class,'w-[146px] MuiBox-root css-1ozlgi5')][1]/div")
dropdown_item_input_value = dropdown_input[0].get_attribute("title")
#dropdown_item_xpath = ""
#if len(dropdownLabel) > 0:
# dropdown_item_xpath = "./div[3]//input"
#else:
# dropdown_item_xpath = "./div[1]//input"
#dropdown_item_input_value = dropdownSelect_item.find_element(By.XPATH, dropdown_item_xpath).get_attribute("value")
if dropdown_item_input_value == "": # 有空数据时,就跳过点击添加按钮
is_click_add = "no_click"
break
if is_click_add == "yes_click":
#time.sleep(2)
element_metricsAndDimensionsAdd.click() # 全部都有数据时,需要点击添加
# 点击空的下拉列表框选项
element_metricsAndDimensionsSelects2 = self.driver.find_elements(By.XPATH, ep_metricsAndDimensionsSelects) # 下拉框元素列表 重新获取一次
#if dropdown_name == "Metrics":
#create_class = element_metricsAndDimensionsSelects2[-1].find_element(By.XPATH, ".//i").get_attribute("class")
#if ("icon-Create1" not in create_class): # 没有添加的元素时
# tmp_element_metricsAndDimensionsSelects2 = element_metricsAndDimensionsSelects2[0:]
# else: # 有添加的元素时
# tmp_element_metricsAndDimensionsSelects2 = element_metricsAndDimensionsSelects2[0:-1]
#else:
# tmp_element_metricsAndDimensionsSelects2 = element_metricsAndDimensionsSelects2[0:-1]
#for dropdownSelect_item in tmp_element_metricsAndDimensionsSelects2:
if len(element_metricsAndDimensionsSelects2) > 0:
tmp_element_metricsAndDimensionsSelects2 = element_metricsAndDimensionsSelects2[-1]
dropdownSelect_item_list = tmp_element_metricsAndDimensionsSelects2.find_elements(By.XPATH, ".//input")# 所有列的集
dropdown_item_input_value = dropdownSelect_item_list[0].get_attribute("value")
"""
dropdownSelect_item_list = dropdownSelect_item.find_elements(By.XPATH, "./div") # 所有列的集合
dropdownLabel = dropdownSelect_item.find_elements(By.XPATH, "./div[3]//input")
dropdown_item_xpath = ""
if len(dropdownLabel) > 0:
dropdown_item_xpath = "./div[3]//input"
else:
dropdown_item_xpath = "./div[1]//input"
dropdown_item_input_value = dropdownSelect_item.find_element(By.XPATH, dropdown_item_xpath).get_attribute("value")
"""
if dropdown_item_input_value == "": # 在空的下拉菜单中添加数据
# 遍历添加每一个列的下拉列表数据
col_n = 0
if dropdown_name == "Metrics":
# 因为metrics需要操作三列
tmp_dropdownSelect_item_list = dropdownSelect_item_list[0:3]
else:
# dimension需要操作一列
tmp_dropdownSelect_item_list = dropdownSelect_item_list[0:1]
for col_dropdownSelect in tmp_dropdownSelect_item_list: # 需要操作的每一个行中列的数量
col_dropdownSelect.find_element(By.XPATH, "./parent::*").click()
# 异常断言判断 "reverse_case": "....", # 主要校验不同chart类型,可以选择不同的metrics # 只是断言使用,无实际页面操作
if "reverse_case" in self.data["charts"][0].keys():
reverse_case_case = self.data["charts"][0]["reverse_case"].strip().lower()
if reverse_case_case == "table_chart_check_metrics" or reverse_case_case == "bar_chart_check_metrics": # 校验table or bar chart 可选择 metrics类型
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Invalid Metric Verification Test Cases for Table and Bar Charts")
info_execpt = "is-disabled"
is_disabled_list = ["Session IDs", "Client IPs", "Server IPs", "Incoming Latency",
"Outgoing Latency", "Latency"]
el_drop_item_class_xpath = "//*[contains(@class, 'Metric')]//div[contains(@class, 'multipleSelect')]//div[@class='el-scrollbar']//li[contains(@class, 'el-select-dropdown__item')]"
drop_items = self.driver.find_elements(By.XPATH, el_drop_item_class_xpath)
for i in drop_items:
item_name = i.find_element(By.XPATH, ".//span").text.strip()
item_class = i.get_attribute("class")
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], item_name, "==>>", item_class)
#if item_name in is_disabled_list:
#pytest_check.is_in(info_execpt, item_class,
# msg="所在行数{}".format(inspect.currentframe().f_lineno))
elif reverse_case_case == "histogram_chart_check_metrics": # 校验histogram chart 可选择 metrics类型
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], "Invalid Metric Verification Test Cases for Histogram Charts")
info_execpt = "is-disabled"
is_disabled_list = ["Incoming Bytes", "Outgoing Bytes ", "Bytes",
'Outgoing Packets','Incoming Packets','Packets',"New C2S Flows",
"New S2C Flows",
"New Incoming Sessions", "New Outgoing Sessions", "Sessions",
"New Unestablished Sessions",
"SYN Packets", "Session IDs", "Client IPs", "Server IPs"]
el_drop_item_class_xpath = "//*[contains(@class, 'Metric')]//div[contains(@class, 'multipleSelect')]//div[@class='el-scrollbar']//li[contains(@class, 'el-select-dropdown__item')]"
drop_items = self.driver.find_elements(By.XPATH, el_drop_item_class_xpath)
for i in drop_items:
item_name = i.find_element(By.XPATH, ".//span").text.strip()
item_class = i.get_attribute("class")
# print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], item_name, "==>>", item_class)
#if item_name in is_disabled_list:
# pytest_check.is_in(info_execpt, item_class,
# msg="所在行数{}".format(inspect.currentframe().f_lineno))
# 从下拉列表中选择Item选项值
if ":" in new_value: # metrics数据,需要操作三列
# 24.08
new_value_list = new_value.split(":")
replaceDropdownIterm = new_value_list[col_n]
if col_n == 0:
metric_temp_list = replaceDropdownIterm.split("+")
for metric_temp in metric_temp_list:
#element_dropdown_item = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(
#(By.XPATH,statisticsTemplates_metrics_dropdown_item_posXpath.format(replaceMetricsField=dropdown_item_dict[metric_temp]))))
#全部ul定位,取最后一个
#temp_element = self.driver.find_elements(By.XPATH, "//ul")
#element_dropdown_item = temp_element[-1].find_element(By.XPATH, ".//*[normalize-space(text())='{repalceLabel}']".format(repalceLabel=dropdown_item_dict[metric_temp]))
time.sleep(2)
element_dropdown_item = self.driver.find_element(By.XPATH, statisticsTemplates_dropdownMetrics_posXpath.format(replaceDropdownIterm=dropdown_item_dict[metric_temp]))
#element_dropdown_item = self.driver.find_element(By.XPATH,statisticsTemplates_metrics_dropdown_item_posXpath.format(replaceMetricsField=dropdown_item_dict[metric_temp]))
# 移动元素到页面,在执行点击
self.driver.execute_script("arguments[0].scrollIntoView();", element_dropdown_item)
self.driver.execute_script("arguments[0].click();", element_dropdown_item)
if col_n == 1:
#element_dropdown_item = col_dropdownSelect.find_element(By.XPATH,f".//div[contains(@class,'el-select-dropdown__wrap')]//span[normalize-space(text())='{replaceDropdownIterm}']")
element_dropdown_item = col_dropdownSelect.find_element(By.XPATH, statisticsTemplates_metrics_function_dropdown_item_posXpath.format(replaceDropdownIterm))
# 移动元素到页面,在执行点击
self.driver.execute_script("arguments[0].scrollIntoView();", element_dropdown_item)
self.driver.execute_script("arguments[0].click();", element_dropdown_item)
elif col_n == 2:
# 输入label值
col_dropdownSelect.clear()
col_dropdownSelect.send_keys(Keys.CONTROL + 'a')
col_dropdownSelect.send_keys(replaceDropdownIterm)
#col_dropdownSelect.find_element(By.XPATH, ".//input").send_keys(Keys.CONTROL + 'a')
#col_dropdownSelect.find_element(By.XPATH, ".//input").clear()
#col_dropdownSelect.find_element(By.XPATH, ".//input").send_keys(replaceDropdownIterm)
col_n += 1
else: # demesions数据操作
col_name = new_value
replaceDropdownIterm = dropdown_item_dict[col_name]
# 24.07及以前
#element_dropdown_item = col_dropdownSelect.find_element(By.XPATH,f".//div[contains(@class,'el-select-dropdown__wrap')]//span[normalize-space(text())='{replaceDropdownIterm}']")
# 24.08
element_dropdown_item = self.driver.find_element(By.XPATH,statisticsTemplates_dimensions_dropdown_item_posXpath.format(replaceDropdownIterm))
self.driver.execute_script("arguments[0].scrollIntoView();", element_dropdown_item)
self.driver.execute_script("arguments[0].click();", element_dropdown_item)
#break
return 200
except Exception as e:
self.error_print_function(inspect.currentframe().f_code.co_name, e)
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Exception: {e}")
raise
#return 400
def dropdown_del(self, chart_id="", dropdown_name="", old_value="", dropdown_item_dict={}):
"""
删除下拉列表选项
:param chart_id:
:param dropdown_name:
:param old_value: 删除的选项值
:param dropdown_item_dict: 同add的方法
:return:
"""
try:
old_value_list = old_value.split(":")
ui_old_value = dropdown_item_dict[old_value_list[0]]
ep_metricsAndDimensionsSelects = statisticsTemplates_input_metricsAndDimensionsSelect_posXpath.format(
replaceChart=chart_id, repalceLabel=dropdown_name) # 下拉框定位,可能存在多个
element_metricsAndDimensionsSelects = self.driver.find_elements(By.XPATH,
ep_metricsAndDimensionsSelects) # 下拉框元素列表
# 需要选择,需要删除的元素
for dropdownSelect_item in element_metricsAndDimensionsSelects[1:-1]: # 类别中第一个和最后一个元素不是选择框元素,这个只遍历选择框元素
#dropdownLabel_item_input_value = dropdownSelect_item.find_element(By.XPATH, "./div[3]//input").get_attribute("value")
#if dropdownLabel_item_input_value == ui_old_value: # 删除该元素
dropdownLabel = dropdownSelect_item.find_elements(By.XPATH, "./div[3]//input")
dropdown_item_xpath = ""
if len(dropdownLabel) > 0:
dropdown_item_xpath = "./div[3]//input"
else:
dropdown_item_xpath = "./div[1]//input"
dropdown_item_input_value = dropdownSelect_item.find_element(By.XPATH, dropdown_item_xpath).get_attribute("value")
if dropdown_item_input_value == "": # 删除该元素
if ":" in old_value: # metrics的删除点击
dropdownSelect_item.find_element(By.XPATH, "./div[4]//i").click() # 点击删除按钮
else: # dimensions的删除点击操作
dropdownSelect_item.find_element(By.XPATH, "./div[3]//i").click() # 点击删除按钮
break
return 200
except Exception as e:
self.error_print_function(inspect.currentframe().f_code.co_name, e)
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Exception: {e}")
raise
#return 400
def dropdown_modify(self, chart_id="", dropdown_name="", old_value="", new_value="", dropdown_item_dict={}):
"""
修改下拉列表选项,更换为新值
:param chart_id:
:param dropdown_name:
:param old_value: 创建的值
:param new_value: 修改的值
:param dropdown_item_dict:
:return:
dropdown_aggragate_dict = {"sum": "SUM", "rate": "RATE", "bitrate": "BITRATE",
"percentiles_hdr": "PERCENTILES_HDR", "median_hdr": "MEDIAN_HDR",
"p95_percentile_hdr": "P95_PERCENTILE_HDR",
"p99_percentile_hdr": "P99_PERCENTILE_HDR",
"approx_count_distinct_hlld": "APPROX_COUNT_DISTINCT_HLLD"}
"""
try:
old_value_list = old_value.split(":")
new_value_list = new_value.split(":")
ep_metricsAndDimensionsSelects = statisticsTemplates_input_metricsAndDimensionsSelect_posXpath.format(
replaceChart=chart_id, repalceLabel=dropdown_name) # 下拉框定位,可能存在多个
element_metricsAndDimensionsSelects = self.driver.find_elements(By.XPATH,
ep_metricsAndDimensionsSelects) # 下拉框元素列表
# 选择需要修改的下拉列表,并重新选择新值
for dropdownSelect_item in element_metricsAndDimensionsSelects[1:-1]: # 类别中第一个和最后一个元素不是选择框元素,这个只遍历选择框元素
dropdownLabel = dropdownSelect_item.find_elements(By.XPATH, "./div[3]//input")
dropdown_item_xpath = ""
if len(dropdownLabel) > 0:
dropdown_item_xpath = "./div[3]//input"
dropdown_item_input_value = dropdownSelect_item.find_element(By.XPATH, dropdown_item_xpath).get_attribute("value")
if dropdown_item_input_value == dropdown_item_dict[old_value_list[2]]: # 删除该元素
dropdownSelect_item.find_element(By.XPATH, ".//div[1]//input").click()
break
else:
dropdown_item_xpath = "./div[1]//input"
dropdown_item_input_value = dropdownSelect_item.find_element(By.XPATH,dropdown_item_xpath).get_attribute("value")
if dropdown_item_input_value == dropdown_item_dict[old_value_list[0]]: # 删除该元素
dropdownSelect_item.find_element(By.XPATH, ".//div[1]//input").click()
break
#dropdownLabel_item_input_value = dropdownSelect_item.find_element(By.XPATH, "./div[3]//input").get_attribute("value")
#if dropdownLabel_item_input_value == dropdown_item_dict[old_value_list[2]]: # 删除该元素
#dropdownSelect_item.find_element(By.XPATH, ".//div[1]//input").click()
#break
# 点击下拉列表的的新item选项
ep_metricsAndDimensionsDropdownItem = statisticsTemplates_dropdown_posXpath.format(replaceChart=chart_id,
repalceLabel=dropdown_name,
replaceDropdownIterm=
dropdown_item_dict[
new_value_list[0]])
element_dropdown_item = self.driver.find_element(By.XPATH, ep_metricsAndDimensionsDropdownItem)
# 移动元素到页面,在执行点击
#self.actions.move_to_element(element_dropdown_item).perform()
self.driver.execute_script("arguments[0].scrollIntoView();", element_dropdown_item)
self.driver.execute_script("arguments[0].click();", element_dropdown_item)
# Metrics列数据,还需要修改Aggregate label数据
if dropdown_name == "Metrics":
# 操作aggregate数据
dropdownSelect_item.find_element(By.XPATH, "./div[2]//input").click() # 点击选择框
ep_aggregateItem = statisticsTemplates_dropdown_posXpath.format(replaceChart=chart_id, repalceLabel=dropdown_name, replaceDropdownIterm=new_value_list[1])
#dropdown_aggragate_dict[new_value_list[1]])
self.driver.find_element(By.XPATH, ep_aggregateItem).click()
# 操作label数据
dropdownSelect_item.find_element(By.XPATH, "./div[3]//input").clear() # label输入框数据
dropdownSelect_item.find_element(By.XPATH, "./div[3]//input").send_keys(new_value_list[2])
return 200
except Exception as e:
self.error_print_function(inspect.currentframe().f_code.co_name, e)
#print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Class:CreateStatisticsTemplate;Funcation:dropdown_add();Exception: {e}")
raise
#return 400
def error_print_function(self, function, error):
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3],
f"Class:{self.__class__.__name__},Function:{function}Error: {error}", flush=True)
if __name__ == '__main__':
metric_temp_list = "Bytes Sent".split("+")
print(len(metric_temp_list))
for metric in metric_temp_list:
print(metric)
metric_temp_list = "Bytes Sent+Bytes Reviced".split("+")
print(len(metric_temp_list))
for metric in metric_temp_list:
print(metric)
|