Skip to content

Commit 8b7c921

Browse files
authored
fix: Entity.save() returns error or warning message if found (#385)
* fix: Entity.save() returns error or warning message if found * refactor: error / warning messages are not actually on the page when save is okay
1 parent 7fb42be commit 8b7c921

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

pytest_splunk_addon_ui_smartx/components/controls/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_msg(self):
5252

5353
def wait_loading(self):
5454
"""
55-
Wait till the message appears and then dissapears
55+
Wait till the message appears and then disappears
5656
:return: Str The text message after waiting
5757
"""
5858
try:

pytest_splunk_addon_ui_smartx/components/entity.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
from typing import Union
1617

17-
import time
18-
from abc import abstractmethod
19-
18+
import selenium.common
2019
from selenium.webdriver.common.by import By
2120

22-
from ..pages.page import Page
2321
from .base_component import BaseComponent, Selector
2422
from .controls.button import Button
2523
from .controls.message import Message
2624
from .dropdown import Dropdown
2725

26+
import warnings
27+
2828

2929
class Entity(BaseComponent):
3030
"""
@@ -91,23 +91,33 @@ def is_error_closed(self):
9191
except:
9292
return True
9393

94-
def save(self, expect_error=False, expect_warning=False):
94+
def save(
95+
self, expect_error: bool = False, expect_warning: bool = False
96+
) -> Union[str, bool]:
9597
"""
96-
Save the configuration
97-
:param expect_error: if True, the error message will be fetched.
98-
:param expoect_warning: If True, the warning message will be fetched.
99-
:returns: If expect_error or expect_warning is True, then it will return the message appearing on page.
100-
Otherwise, the function will return True if the configuration was saved properly
98+
Attempts to save configuration. If error or warning messages are found, return them instead.
10199
"""
100+
warnings.warn(
101+
"expect_error and expect_warning are deprecated and will be removed in the future versions.",
102+
DeprecationWarning,
103+
stacklevel=2,
104+
)
102105
self.save_btn.wait_to_be_clickable()
103106
self.save_btn.click()
104-
if expect_error:
105-
return self.get_error()
106-
elif expect_warning:
107-
return self.get_warning()
108-
else:
109-
self.loading.wait_loading()
110-
return True
107+
try:
108+
error_message = self.get_error()
109+
except selenium.common.exceptions.TimeoutException:
110+
error_message = ""
111+
if error_message != "":
112+
return error_message
113+
try:
114+
warning_message = self.get_warning()
115+
except selenium.common.exceptions.TimeoutException:
116+
warning_message = ""
117+
if warning_message != "":
118+
return warning_message
119+
self.loading.wait_loading()
120+
return True
111121

112122
def cancel(self):
113123
"""

0 commit comments

Comments
 (0)