Skip to content

checkbox

Checkbox(browser, container, searchable=True)

Bases: BaseControl

Entity_Component : Checkbox

Source code in pytest_splunk_addon_ui_smartx/components/controls/checkbox.py
29
30
31
32
33
34
35
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
def __init__(self, browser, container, searchable=True):
    super().__init__(browser, container)
    if container.by == "xpath":
        self.elements.update(
            {
                "internal_container": Selector(
                    by=By.XPATH,
                    select=container.select + '//div[@data-test="switch"]',
                ),
                "checkbox": Selector(
                    by=By.XPATH,
                    select=container.select + '//div[@data-test="switch"]',
                ),
                "checkbox_btn": Selector(
                    by=By.XPATH,
                    select=container.select + '//button[@role="checkbox"]',
                ),
            }
        )
    else:
        self.elements.update(
            {
                "internal_container": Selector(
                    select=container.select + ' [data-test="switch"]'
                ),
                "checkbox": Selector(
                    select=container.select + ' [data-test="switch"]'
                ),
                "checkbox_btn": Selector(
                    select=container.select
                    + ' [data-test="button"][role="checkbox"]'
                ),
            }
        )

check()

Checks the checkbox if unchecked :return: Bool true if successful, else it will return a statement that it was already checked

Source code in pytest_splunk_addon_ui_smartx/components/controls/checkbox.py
80
81
82
83
84
85
86
87
88
89
90
91
92
def check(self):
    """
    Checks the checkbox if unchecked
        :return: Bool true if successful, else it will return a statement that it was already checked
    """
    try:
        if self.is_checked() == False:
            self.toggle()
            return True
        else:
            return "Checkbox is already checked"
    except Exception as e:
        print(f"Check checkbox failed with {e}")

is_checked()

Returns True if the checkbox is already checked, otherwise False :return: Bool True if checked, False if unchecked

Source code in pytest_splunk_addon_ui_smartx/components/controls/checkbox.py
108
109
110
111
112
113
114
115
116
117
def is_checked(self):
    """
    Returns True if the checkbox is already checked, otherwise False
        :return: Bool True if checked, False if unchecked
    """
    is_selected = self.checkbox.get_attribute("data-test-selected")
    if is_selected == "true":
        return True
    else:
        return False

toggle(max_attempts=5)

Toggles the checkbox value

Source code in pytest_splunk_addon_ui_smartx/components/controls/checkbox.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def toggle(self, max_attempts=5):
    """
    Toggles the checkbox value
    """
    before_toggle = self.is_checked()
    for _ in range(max_attempts):
        try:
            self.wait_to_be_clickable("checkbox")
            self.checkbox_btn.click()
            after_toggle = self.is_checked()
            if before_toggle != after_toggle:
                return
            time.sleep(0.25)
        except Exception as e:
            print(f"Toggle checkbox failed with {e}")

uncheck()

Unchecks the checkbox if checked :return: Bool true if successful, else it will return a statement that it was already unchecked

Source code in pytest_splunk_addon_ui_smartx/components/controls/checkbox.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
def uncheck(self):
    """
    Unchecks the checkbox if checked
        :return: Bool true if successful, else it will return a statement that it was already unchecked
    """
    try:
        if self.is_checked() == True:
            self.toggle()
            return True
        else:
            return "Checkbox is already unchecked"
    except Exception as e:
        print(f"Uncheck checkbox failed with {e}")