Skip to content

learn_more

LearnMore(browser, container)

Bases: BaseControl

Entity_Component : Learn More

Parameters:

Name Type Description Default
browser

The selenium webdriver

required
container

The locator of the container where the control is located in.

required
Source code in pytest_splunk_addon_ui_smartx/components/controls/learn_more.py
31
32
33
34
35
36
37
38
39
40
41
42
43
def __init__(self, browser, container):
    """
    :param browser: The selenium webdriver
    :param container: The locator of the container where the control is located in.
    """
    super().__init__(browser, container)
    self.elements.update(
        {
            "internal_container": Selector(
                select=container.select + ' [data-test="link"]'
            ),
        }
    )

Redirects the browser object to the link provided by the container and returns the URL

Source code in pytest_splunk_addon_ui_smartx/components/controls/learn_more.py
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
@contextmanager
def open_link(self, open_new_tab=True):
    """
    Redirects the browser object to the link provided by the container and returns the URL
    """
    page_url = self.browser.current_url
    self.internal_container.click()
    # For Safari window_handles works opposite as compared to Firefox and Chrome
    # In Safari window_handles[1] represents the current window.
    # And in other browsers window_handels[0] represents the current window.
    if open_new_tab:
        self.wait_for_tab()
        if self.browser.name == "Safari":
            self.browser.switch_to.window(self.browser.window_handles[0])
        else:
            self.browser.switch_to.window(self.browser.window_handles[1])

        current_url = self.browser.current_url
        yield current_url
        self.browser.close()
        self.browser.switch_to.window(self.browser.window_handles[0])
    else:
        self.wait_for_url_change(page_url)
        current_url = self.browser.current_url
        yield current_url

wait_for_tab()

Wait for redirect page title to load.

Source code in pytest_splunk_addon_ui_smartx/components/controls/learn_more.py
74
75
76
77
78
79
80
81
82
def wait_for_tab(self):
    """
    Wait for redirect page title to load.
    """

    def _wait_for_tab(driver):
        return len(self.browser.window_handles) > 1

    self.wait_for(_wait_for_tab, msg="Redirect page didn't open")

wait_for_url_change(page_url)

Wait for url to be change

Source code in pytest_splunk_addon_ui_smartx/components/controls/learn_more.py
84
85
86
87
88
89
90
91
92
def wait_for_url_change(self, page_url):
    """
    Wait for url to be change
    """

    def _wait_for_url_change(driver):
        return self.browser.current_url != page_url

    self.wait_for(_wait_for_url_change, msg="Redirect page didn't open")