|
13 | 13 | # See the License for the specific language governing permissions and |
14 | 14 | # limitations under the License. |
15 | 15 | # |
| 16 | +from typing import Union |
16 | 17 |
|
17 | | -import time |
18 | | -from abc import abstractmethod |
19 | | - |
| 18 | +import selenium.common |
20 | 19 | from selenium.webdriver.common.by import By |
21 | 20 |
|
22 | | -from ..pages.page import Page |
23 | 21 | from .base_component import BaseComponent, Selector |
24 | 22 | from .controls.button import Button |
25 | 23 | from .controls.message import Message |
26 | 24 | from .dropdown import Dropdown |
27 | 25 |
|
| 26 | +import warnings |
| 27 | + |
28 | 28 |
|
29 | 29 | class Entity(BaseComponent): |
30 | 30 | """ |
@@ -91,23 +91,33 @@ def is_error_closed(self): |
91 | 91 | except: |
92 | 92 | return True |
93 | 93 |
|
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]: |
95 | 97 | """ |
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. |
101 | 99 | """ |
| 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 | + ) |
102 | 105 | self.save_btn.wait_to_be_clickable() |
103 | 106 | 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 |
111 | 121 |
|
112 | 122 | def cancel(self): |
113 | 123 | """ |
|
0 commit comments