Skip to content

Commit efd575b

Browse files
feat: add file component (#438)
This PR adds support of File component. UCC doc ref: https://splunk.github.io/addonfactory-ucc-generator/entity/components/#file
1 parent 49b85e3 commit efd575b

File tree

12 files changed

+243
-2
lines changed

12 files changed

+243
-2
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#
2+
# Copyright 2024 Splunk Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
from ..base_component import Selector
17+
from .base_control import BaseControl
18+
from selenium.common.exceptions import TimeoutException
19+
20+
21+
class File(BaseControl):
22+
"""
23+
Entity-Component: File
24+
"""
25+
26+
def __init__(self, browser, container) -> None:
27+
"""
28+
:param browser: The selenium webdriver
29+
:param container: The locator of the container where the control is located in.
30+
"""
31+
super().__init__(browser, container)
32+
self.elements.update(
33+
{
34+
"input": Selector(select=container.select + " input"),
35+
"support_message": Selector(
36+
select=container.select
37+
+ ' [data-test="file"] [data-test="file-supports"]'
38+
),
39+
"error_text": Selector(
40+
select=container.select + ' [data-test="file"] [data-test="help"]'
41+
),
42+
"selected": Selector(
43+
select=container.select + ' [data-test="item"] [data-test="label"]'
44+
),
45+
"cancel_selected": Selector(
46+
select=container.select + ' [data-test="remove"]'
47+
),
48+
}
49+
)
50+
51+
def set_value(self, value: str) -> None:
52+
"""
53+
set value of the File input
54+
"""
55+
self.wait_for("input")
56+
self.input.send_keys(value)
57+
58+
def get_value(self) -> str:
59+
"""
60+
get the name of the selected file
61+
:return: Str The name of the selected file
62+
"""
63+
try:
64+
return self.selected.get_attribute("innerText").strip()
65+
except TimeoutException:
66+
pass
67+
return ""
68+
69+
def get_support_message(self) -> str:
70+
"""
71+
get the file support message
72+
:return: Str file support message
73+
"""
74+
return self.support_message.get_attribute("innerText").strip()
75+
76+
def get_error_text(self) -> str:
77+
"""
78+
get the file validation error text
79+
:return: Str error message of the file validation
80+
"""
81+
try:
82+
return self.error_text.get_attribute("innerText").strip()
83+
except TimeoutException:
84+
pass
85+
return ""
86+
87+
def cancel_selected_value(self) -> bool:
88+
"""
89+
Cancels the currently selected value in the File component
90+
:return: Bool whether canceling the selected item was successful, else raises an error
91+
"""
92+
self.wait_to_be_clickable("cancel_selected")
93+
self.cancel_selected.click()
94+
return True

tests/testdata/Splunk_TA_UCCExample/globalConfig.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@
4242
"help": "Enter a unique name for this account.",
4343
"required": true
4444
},
45+
{
46+
"type": "file",
47+
"label": "Example File",
48+
"help": "Upload example file",
49+
"field": "example_file",
50+
"options": {
51+
"fileSupportMessage": "Example Support message",
52+
"supportedFileTypes": ["conf", "txt"],
53+
"maxFileSize": 1,
54+
"useBase64Encoding": false
55+
},
56+
"validators": [
57+
{
58+
"type": "regex",
59+
"pattern": "^Example*"
60+
}
61+
],
62+
"encrypted": true,
63+
"required": true
64+
},
4565
{
4666
"type": "singleSelect",
4767
"label": "Example Environment",

tests/ui/Example_UccLib/account.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pytest_splunk_addon_ui_smartx.components.controls.multi_select import MultiSelect
1010
from pytest_splunk_addon_ui_smartx.components.controls.checkbox import Checkbox
1111
from pytest_splunk_addon_ui_smartx.components.controls.textbox import TextBox
12+
from pytest_splunk_addon_ui_smartx.components.controls.file import File
1213
from pytest_splunk_addon_ui_smartx.components.controls.learn_more import LearnMore
1314
from pytest_splunk_addon_ui_smartx.components.controls.toggle import Toggle
1415
from pytest_splunk_addon_ui_smartx.components.controls.message import Message
@@ -40,6 +41,10 @@ def __init__(self, browser, container):
4041
self.name = TextBox(
4142
browser, Selector(select='[data-test="control-group"][data-name="name"]')
4243
)
44+
self.file = File(
45+
browser,
46+
Selector(select='[data-test="control-group"][data-name="example_file"]'),
47+
)
4348
self.environment = SingleSelect(
4449
browser,
4550
Selector(select='[data-test="control-group"][data-name="custom_endpoint"]'),

tests/ui/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def add_account(ucc_smartx_rest_helper):
2424
"redirect_url": "",
2525
"endpoint": "",
2626
"example_help_link": "",
27+
"example_file": "Example file content",
2728
}
2829
yield account.backend_conf.post_stanza(url, kwargs)
2930
account.backend_conf.delete_all_stanzas()

0 commit comments

Comments
 (0)