Skip to content

Commit

Permalink
fix: Entity.save() returns error or warning message if found (#385)
Browse files Browse the repository at this point in the history
* fix: Entity.save() returns error or warning message if found

* refactor: error / warning messages are not actually on the page when save is okay
  • Loading branch information
artemrys authored Sep 15, 2023
1 parent 7fb42be commit 8b7c921
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_msg(self):

def wait_loading(self):
"""
Wait till the message appears and then dissapears
Wait till the message appears and then disappears
:return: Str The text message after waiting
"""
try:
Expand Down
44 changes: 27 additions & 17 deletions pytest_splunk_addon_ui_smartx/components/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from typing import Union

import time
from abc import abstractmethod

import selenium.common
from selenium.webdriver.common.by import By

from ..pages.page import Page
from .base_component import BaseComponent, Selector
from .controls.button import Button
from .controls.message import Message
from .dropdown import Dropdown

import warnings


class Entity(BaseComponent):
"""
Expand Down Expand Up @@ -91,23 +91,33 @@ def is_error_closed(self):
except:
return True

def save(self, expect_error=False, expect_warning=False):
def save(
self, expect_error: bool = False, expect_warning: bool = False
) -> Union[str, bool]:
"""
Save the configuration
:param expect_error: if True, the error message will be fetched.
:param expoect_warning: If True, the warning message will be fetched.
:returns: If expect_error or expect_warning is True, then it will return the message appearing on page.
Otherwise, the function will return True if the configuration was saved properly
Attempts to save configuration. If error or warning messages are found, return them instead.
"""
warnings.warn(
"expect_error and expect_warning are deprecated and will be removed in the future versions.",
DeprecationWarning,
stacklevel=2,
)
self.save_btn.wait_to_be_clickable()
self.save_btn.click()
if expect_error:
return self.get_error()
elif expect_warning:
return self.get_warning()
else:
self.loading.wait_loading()
return True
try:
error_message = self.get_error()
except selenium.common.exceptions.TimeoutException:
error_message = ""
if error_message != "":
return error_message
try:
warning_message = self.get_warning()
except selenium.common.exceptions.TimeoutException:
warning_message = ""
if warning_message != "":
return warning_message
self.loading.wait_loading()
return True

def cancel(self):
"""
Expand Down

0 comments on commit 8b7c921

Please sign in to comment.