Skip to content

Commit

Permalink
feat: add textarea component (#399)
Browse files Browse the repository at this point in the history
* chore: add textarea component and fix textbox wait_to_be_editable method

* chore: pre-commit fixes

* chore: compliance fix and ui tests added

* chore: pre-commit fixes

* chore: fix ui tests

* ci: pin splunk/addonfactory-test-matrix-action to 1.10

---------

Co-authored-by: Artem Rys <[email protected]>
  • Loading branch information
mkolasinski-splunk and artemrys authored Oct 25, 2023
1 parent 6f8a39d commit 8cc8af7
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- id: matrix
uses: splunk/addonfactory-test-matrix-action@v1
uses: splunk/addonfactory-test-matrix-action@v1.10

fossa-scan:
continue-on-error: true
Expand Down
88 changes: 88 additions & 0 deletions pytest_splunk_addon_ui_smartx/components/controls/textarea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# Copyright 2023 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import platform

from selenium.webdriver.common.keys import Keys

from ..base_component import Selector
from .textbox import TextBox

os_base = platform.system()


class TextArea(TextBox):
"""
Entity-Component: TextBox
"""

def __init__(self, browser, container, encrypted=False):
"""
:param browser: The selenium webdriver
:param container: The locator of the container where the control is located in.
"""
super().__init__(browser, container)
self.elements.update(
{
"input": Selector(
select=container.select + ' textarea[data-test="textbox"]'
)
}
)

def get_value(self):
"""
get value from the textbox
:return: Str The current value of the textbox
"""
return self.input.get_attribute("value")

def get_placeholder_value(self):
"""
get placeholder value from the textbox
:return: Str Value of the placeholder
"""
return self.input.get_attribute("placeholder")

def get_textarea_height(self) -> int:
"""
Get the height of the displayed textarea.
:return: Int Height of the textarea in pixels.
"""
return self.input.size["height"]

def append_value(self, value) -> None:
"""
Appends the specified 'value' to an textarea element
"""
self.input.send_keys(value)

def screenshot(self) -> str:
"""
Creates screenshot of current element
:return: screenshot as base64
"""
return self.input.screenshot_as_base64

def scroll(self, direction: str, scroll_count: int) -> None:
"""
Scrolls the input element in the specified direction.
"""
valid_directions = ["UP", "DOWN"]
if direction not in valid_directions:
raise ValueError("Invalid direction. Use 'UP' or 'DOWN'.")
key = Keys.ARROW_UP if direction == "UP" else Keys.ARROW_DOWN
for _ in range(scroll_count):
self.input.send_keys(key)
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ def wait_to_be_editable(self):
"""

def _wait_for_field_to_be_editable(driver):
return self.is_editable == True
return self.is_editable()

self.wait_for(_wait_for_field_to_be_editable, msg="Field is uneditable")
11 changes: 11 additions & 0 deletions tests/testdata/Splunk_TA_UCCExample/globalConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,17 @@
"help": "The maximum number of results returned by the query.",
"required": false
},
{
"type": "textarea",
"label": "Example Textarea Field",
"field": "example_textarea_field",
"help": "Help message",
"options": {
"rowsMin": 3,
"rowsMax": 15
},
"required": true
},
{
"field": "example_help_link",
"label": "",
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/Example_UccLib/input_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pytest_splunk_addon_ui_smartx.components.controls.checkbox import Checkbox
from pytest_splunk_addon_ui_smartx.components.controls.learn_more import LearnMore
from pytest_splunk_addon_ui_smartx.components.controls.textbox import TextBox
from pytest_splunk_addon_ui_smartx.components.controls.textarea import TextArea
from pytest_splunk_addon_ui_smartx.components.controls.single_select import SingleSelect
from pytest_splunk_addon_ui_smartx.components.controls.multi_select import MultiSelect
from pytest_splunk_addon_ui_smartx.components.controls.message import Message
Expand Down Expand Up @@ -109,6 +110,12 @@ def __init__(self, browser, container):
+ ' [data-test="control-group"][data-name="example_help_link"]'
),
)
self.text_area = TextArea(
browser,
Selector(
select=entity_container.select + ' [data-name="example_textarea_field"]'
),
)
self.title = BaseComponent(browser, Selector(select=' [data-test="title"]'))


Expand Down
75 changes: 75 additions & 0 deletions tests/ui/test_splunk_ta_example_addon_input_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def add_input_one(ucc_smartx_rest_helper):
"singleSelectTest": "two",
"start_date": "2020-12-11T20:00:32.000z",
"disabled": 0,
"example_textarea_field": "line1\nline2",
}
yield input_page.backend_conf.post_stanza(url, kwargs)

Expand Down Expand Up @@ -794,6 +795,7 @@ def test_example_input_one_add_frontend_validation(
input_page.entity1.object.set_value("test_object")
input_page.entity1.object_fields.set_value("test_field")
input_page.entity1.query_start_date.set_value("2020-12-11T20:00:32.000z")
input_page.entity1.text_area.set_value("line1\nline2")
self.assert_util(input_page.entity1.save, True)
input_page.table.wait_for_rows_to_appear(1)
self.assert_util(
Expand Down Expand Up @@ -829,6 +831,7 @@ def test_example_input_one_add_backend_validation(
input_page.entity1.object.set_value("test_object")
input_page.entity1.object_fields.set_value("test_field")
input_page.entity1.query_start_date.set_value("2020-12-11T20:00:32.000z")
input_page.entity1.text_area.set_value("line1\nline2")
self.assert_util(input_page.entity1.save, True)
input_page.table.wait_for_rows_to_appear(1)
value_to_test = {
Expand All @@ -844,6 +847,7 @@ def test_example_input_one_add_backend_validation(
"singleSelectTest": "two",
"start_date": "2020-12-11T20:00:32.000z",
"disabled": 0,
"example_textarea_field": "line1\nline2",
}
backend_stanza = input_page.backend_conf.get_stanza(
"example_input_one://dummy_input"
Expand Down Expand Up @@ -889,6 +893,7 @@ def test_example_input_one_edit_frontend_validation(
input_page.entity1.order_by.set_value("LastDate")
input_page.entity1.limit.set_value("2000")
input_page.entity1.query_start_date.set_value("2020-20-20T20:20:20.000z")
input_page.entity1.text_area.set_value("line3\nline4")
self.assert_util(input_page.entity1.save, True)
input_page.table.wait_for_rows_to_appear(1)
self.assert_util(
Expand Down Expand Up @@ -926,6 +931,7 @@ def test_example_input_one_edit_backend_validation(
input_page.entity1.order_by.set_value("LastDate")
input_page.entity1.limit.set_value("2000")
input_page.entity1.query_start_date.set_value("2020-20-20T20:20:20.000z")
input_page.entity1.text_area.set_value("line3\nline4")
self.assert_util(input_page.entity1.save, True)
input_page.table.wait_for_rows_to_appear(1)
value_to_test = {
Expand All @@ -942,6 +948,7 @@ def test_example_input_one_edit_backend_validation(
"singleSelectTest": "four",
"start_date": "2020-20-20T20:20:20.000z",
"disabled": 0,
"example_textarea_field": "line3\nline4",
}
backend_stanza = input_page.backend_conf.get_stanza(
"example_input_one://dummy_input_one"
Expand Down Expand Up @@ -974,6 +981,7 @@ def test_example_input_one_clone_default_values(
input_page.entity1.query_start_date.get_value, "2020-12-11T20:00:32.000z"
)
self.assert_util(input_page.entity1.limit.get_value, "1000")
self.assert_util(input_page.entity1.text_area.get_value, "line1\nline2")

@pytest.mark.execute_enterprise_cloud_true
@pytest.mark.forwarder
Expand All @@ -990,6 +998,7 @@ def test_example_input_one_clone_frontend_validation(
input_page.entity1.name.set_value("dummy_input_one_Clone_Test")
input_page.entity1.interval.set_value("180")
input_page.entity1.limit.set_value("500")
input_page.entity1.text_area.set_value("line1\nline2")
self.assert_util(input_page.entity1.save, True)
input_page.table.wait_for_rows_to_appear(2)
self.assert_util(
Expand Down Expand Up @@ -1019,6 +1028,7 @@ def test_example_input_one_clone_backend_validation(
input_page.entity1.name.set_value("dummy_input_one_Clone_Test")
input_page.entity1.interval.set_value("180")
input_page.entity1.limit.set_value("500")
input_page.entity1.text_area.set_value("line3\nline4")
self.assert_util(input_page.entity1.save, True)
input_page.table.wait_for_rows_to_appear(2)
value_to_test = {
Expand All @@ -1035,6 +1045,7 @@ def test_example_input_one_clone_backend_validation(
"singleSelectTest": "two",
"start_date": "2020-12-11T20:00:32.000z",
"disabled": 0,
"example_textarea_field": "line3\nline4",
}
backend_stanza = input_page.backend_conf.get_stanza(
"example_input_one://dummy_input_one_Clone_Test"
Expand Down Expand Up @@ -1276,3 +1287,67 @@ def test_example_input_one_delete_valid_prompt_message(
self.assert_util(
prompt_message, 'Are you sure you want to delete "{}" ?'.format(input_name)
)

@pytest.mark.execute_enterprise_cloud_true
@pytest.mark.forwarder
@pytest.mark.input
def test_inputs_textarea_height(
self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper, add_input_one
):
"""
Verifies that textarea height values
"""
input_page = InputPage(ucc_smartx_selenium_helper, ucc_smartx_rest_helper)
input_page.table.edit_row("dummy_input_one")
min_textarea_height = 71
max_textarea_height = 311
long_input = ""
self.assert_util(
min_textarea_height, input_page.entity1.text_area.get_textarea_height
)
for i in range(1, 50):
long_input += f"{str(i)}\n"
input_page.entity1.text_area.append_value(long_input)
self.assert_util(
max_textarea_height, input_page.entity1.text_area.get_textarea_height
)

@pytest.mark.execute_enterprise_cloud_true
@pytest.mark.forwarder
@pytest.mark.input
def test_inputs_textarea_big_input(
self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper, add_input_one
):
"""
Verifies that textarea can handle big inputs
"""
input_page = InputPage(ucc_smartx_selenium_helper, ucc_smartx_rest_helper)
input_page.table.edit_row("dummy_input_one")
big_input = ""
for i in range(1, 1000):
big_input += f"{str(i)}\n"
input_page.entity1.text_area.set_value(big_input)
self.assert_util(big_input, input_page.entity1.text_area.get_value())
self.assert_util(input_page.entity1.save, True)
input_page.table.edit_row("dummy_input_one")
self.assert_util(big_input.strip(), input_page.entity1.text_area.get_value())

@pytest.mark.execute_enterprise_cloud_true
@pytest.mark.forwarder
@pytest.mark.input
def test_inputs_textarea_scroll(
self, ucc_smartx_selenium_helper, ucc_smartx_rest_helper, add_input_one
):
"""
Verifies that textarea height values
"""
input_page = InputPage(ucc_smartx_selenium_helper, ucc_smartx_rest_helper)
input_page.table.edit_row("dummy_input_one")
long_input = ""
screnshot_before = input_page.entity1.text_area.screenshot()
for i in range(1, 50):
long_input += f"{str(i)}\n"
input_page.entity1.text_area.append_value(long_input)
input_page.entity1.text_area.scroll("UP", 40)
screenshot_after = input_page.entity1.text_area.screenshot()
self.assert_util(screnshot_before, screenshot_after, operator="!=")

0 comments on commit 8cc8af7

Please sign in to comment.