Skip to content

entity

Entity(browser, container, add_btn=None, is_single_page=False)

Bases: BaseComponent

Entity form to add/edit the configuration. The instance of the class expects that the entity is already open. The instance of the class holds all the controls in the entity and provides the generic interaction that can be done with the entity

Parameters:

Name Type Description Default
browser

The selenium webdriver

required
container

Container in which the Entity is located. Of type dictionary: {“by”:…, “select”:…}

required
add_btn

The locator of add_button with which the entity will be opened

None
is_single_page

Boolean indicating whether the selected tab is single entity form or not like proxy and logging.

False
Source code in pytest_splunk_addon_ui_smartx/components/entity.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def __init__(self, browser, container, add_btn=None, is_single_page=False):
    """
    :param browser: The selenium webdriver
    :param container: Container in which the Entity is located. Of type dictionary: {"by":..., "select":...}
    :param add_btn: The locator of add_button with which the entity will be opened
    :param is_single_page: Boolean indicating whether the selected tab is single entity form or not like proxy and logging.
    """
    self.browser = browser
    super().__init__(browser, container)

    # Controls
    self.save_btn = Button(browser, Selector(select=container.select + " .saveBtn"))
    self.loading = Message(
        browser,
        Selector(select=container.select + ' button[data-test="wait-spinner"]'),
    )
    if not is_single_page:
        self.add_btn = add_btn
    self.msg_error = Message(
        browser, Selector(select='div[data-test-type="error"]')
    )
    self.msg_warning = Message(
        browser, Selector(select='div[data-test-type="warning"]')
    )
    self.msg_markdown = Message(
        browser, Selector(select='[data-test="msg-markdown"]')
    )
    self.cancel_btn = Button(
        browser,
        Selector(select=container.select + ' [data-test="button"][label="Cancel"]'),
    )
    self.close_btn = Button(
        browser, Selector(select=container.select + ' button[data-test="close"]')
    )
    if self.add_btn == None:
        self.create_new_input = Dropdown(
            browser, Selector(by=By.ID, select="addInputBtn")
        )

cancel()

Cancel the entity :return: True if done properly

Source code in pytest_splunk_addon_ui_smartx/components/entity.py
122
123
124
125
126
127
128
129
def cancel(self):
    """
    Cancel the entity
        :return: True if done properly
    """
    self.cancel_btn.click()
    self.save_btn.wait_until("container")
    return True

close()

Close the entity :return: True if done properly

Source code in pytest_splunk_addon_ui_smartx/components/entity.py
131
132
133
134
135
136
137
138
def close(self):
    """
    Close the entity
        :return: True if done properly
    """
    self.close_btn.click()
    self.save_btn.wait_until("container")
    return True

get_error()

Get the error message displayed while saving the configuration

Source code in pytest_splunk_addon_ui_smartx/components/entity.py
81
82
83
84
85
def get_error(self):
    """
    Get the error message displayed while saving the configuration
    """
    return self.msg_error.get_msg()

get_warning()

Get the error message displayed while saving the configuration

Source code in pytest_splunk_addon_ui_smartx/components/entity.py
75
76
77
78
79
def get_warning(self):
    """
    Get the error message displayed while saving the configuration
    """
    return self.msg_warning.get_msg()

open()

Open the entity by click on “New” button. :return: True if done properly

Source code in pytest_splunk_addon_ui_smartx/components/entity.py
140
141
142
143
144
145
146
147
def open(self):
    """
    Open the entity by click on "New" button.
        :return: True if done properly
    """
    self.add_btn.click()
    self.save_btn.wait_to_display()
    return True

save(expect_error=False, expect_warning=False)

Attempts to save configuration. If error or warning messages are found, return them instead.

Source code in pytest_splunk_addon_ui_smartx/components/entity.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def save(
    self, expect_error: bool = False, expect_warning: bool = False
) -> Union[str, bool]:
    """
    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()
    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