예제 #1
0
 def create_ie(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy()
         desired_capabilities = self._remote_capabilities_resolver(
             desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Ie(**desired_capabilities)
예제 #2
0
 def _make_new_browser(self,
                       url,
                       browser='firefox',
                       alias=None,
                       remote_url=False,
                       desired_capabilities=None,
                       ff_profile_dir=None,
                       options=None,
                       service_log_path=None):
     if is_truthy(remote_url):
         self.info("Opening browser '%s' to base url '%s' through "
                   "remote server at '%s'." % (browser, url, remote_url))
     else:
         self.info("Opening browser '%s' to base url '%s'." %
                   (browser, url))
     driver = self._make_driver(browser, desired_capabilities,
                                ff_profile_dir, remote_url, options,
                                service_log_path)
     driver = self._wrap_event_firing_webdriver(driver)
     index = self.ctx.register_driver(driver, alias)
     try:
         driver.get(url)
     except Exception:
         self.debug("Opened browser with session id %s but failed "
                    "to open url '%s'." % (driver.session_id, url))
         raise
     self.debug('Opened browser with session id %s.' % driver.session_id)
     return index
예제 #3
0
 def create_opera(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.OPERA.copy()
         desired_capabilities = self._remote_capabilities_resolver(
             desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Opera(**desired_capabilities)
예제 #4
0
    def add_cookie(self,
                   name,
                   value,
                   path=None,
                   domain=None,
                   secure=None,
                   expiry=None):
        """Adds a cookie to your current session.

        ``name`` and ``value`` are required, ``path``, ``domain``, ``secure``
        and ``expiry`` are optional.  Expiry supports the same formats as
        the [http://robotframework.org/robotframework/latest/libraries/DateTime.html|DateTime]
        library or an epoch time stamp.

        Example:
        | `Add Cookie` | foo | bar |                            |
        | `Add Cookie` | foo | bar | domain=example.com         |
        | `Add Cookie` | foo | bar | expiry=2027-09-28 16:21:35 | # Expiry as timestamp.     |
        | `Add Cookie` | foo | bar | expiry=1822137695          | # Expiry as epoch seconds. |

        Prior to SeleniumLibrary 3.0 setting expiry did not work.
        """
        new_cookie = {'name': name, 'value': value}
        if not is_noney(path):
            new_cookie['path'] = path
        if not is_noney(domain):
            new_cookie['domain'] = domain
        # Secure must be True or False
        if not is_noney(secure):
            new_cookie['secure'] = is_truthy(secure)
        if not is_noney(expiry):
            new_cookie['expiry'] = self._expiry(expiry)
        self.driver.add_cookie(new_cookie)
예제 #5
0
 def create_safari(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.SAFARI.copy()
         desired_capabilities = self._remote_capabilities_resolver(
             desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Safari(**desired_capabilities)
    def open_navegador(self,
                       url,
                       browser='firefox',
                       alias=None,
                       remote_url=False,
                       desired_capabilities=None,
                       ff_profile_dir=None):

        if is_truthy(remote_url):
            self.info("Opening browser '%s' to base url '%s' through "
                      "remote server at '%s'." % (browser, url, remote_url))
        else:
            self.info("Opening browser '%s' to base url '%s'." %
                      (browser, url))
        driver = self._make_driver(browser, desired_capabilities,
                                   ff_profile_dir, remote_url)
        try:
            driver.get(url)
        except Exception:
            self.ctx.register_driver(driver, alias)
            self.debug("Opened browser with session id %s but failed "
                       "to open url '%s'." % (driver.session_id, url))
            raise
        self.debug('Opened browser with session id %s.' % driver.session_id)
        return self.ctx.register_driver(driver, alias)
    def add_cookie(self, name, value, path=None, domain=None, secure=None,
                   expiry=None):
        """Adds a cookie to your current session.

        ``name`` and ``value`` are required, ``path``, ``domain``, ``secure``
        and ``expiry`` are optional.  Expiry supports the same formats as
        the [http://robotframework.org/robotframework/latest/libraries/DateTime.html|DateTime]
        library or an epoch time stamp.

        Example:
        | `Add Cookie` | foo | bar |                            |
        | `Add Cookie` | foo | bar | domain=example.com         |
        | `Add Cookie` | foo | bar | expiry=2027-09-28 16:21:35 | # Expiry as timestamp.     |
        | `Add Cookie` | foo | bar | expiry=1822137695          | # Expiry as epoch seconds. |

        Prior to SeleniumLibrary 3.0 setting expiry did not work.
        """
        new_cookie = {'name': name, 'value': value}
        if not is_noney(path):
            new_cookie['path'] = path
        if not is_noney(domain):
            new_cookie['domain'] = domain
        # Secure must be True or False
        if not is_noney(secure):
            new_cookie['secure'] = is_truthy(secure)
        if not is_noney(expiry):
            new_cookie['expiry'] = self._expiry(expiry)
        self.driver.add_cookie(new_cookie)
    def element_should_not_contain(self, locator, expected, message=None, ignore_case=False):
        """Verifies that element ``locator`` does not contains text ``expected``.

        See the `Locating elements` section for details about the locator
        syntax.

        The ``message`` argument can be used to override the default error
        message.

        The ``ignore_case`` argument can be set to True to compare case
        insensitive, default is False.

        ``ignore_case`` argument new in SeleniumLibrary 3.1.
        """
        actual = self.find_element(locator).text
        expected_before = expected
        if is_truthy(ignore_case):
            actual = actual.lower()
            expected = expected.lower()
        if expected in actual:
            if is_noney(message):
                message = "Element '%s' should not contain text '%s' but " \
                          "it did." % (locator, expected_before)
            raise AssertionError(message)
        self.info("Element '%s' does not contain text '%s'."
                  % (locator, expected_before))
    def element_text_should_not_be(self, locator, not_expected, message=None, ignore_case=False):
        """Verifies that element ``locator`` does not contain exact text ``not_expected``.

        See the `Locating elements` section for details about the locator
        syntax.

        The ``message`` argument can be used to override the default error
        message.

        The ``ignore_case`` argument can be set to True to compare case
        insensitive, default is False.

        New in SeleniumLibrary 3.1.1
        """
        self.info("Verifying element '%s' does not contains exact text '%s'."
                  % (locator, not_expected))
        text = self.find_element(locator).text
        before_not_expected = not_expected
        if is_truthy(ignore_case):
            text = text.lower()
            not_expected = not_expected.lower()
        if text == not_expected:
            if is_noney(message):
                message = ("The text of element '%s' was not supposed to be '%s'."
                           % (locator, before_not_expected))
            raise AssertionError(message)
    def element_should_contain(self, locator, expected, message=None, ignore_case=False):
        """Verifies that element ``locator`` contains text ``expected``.

        See the `Locating elements` section for details about the locator
        syntax.

        The ``message`` argument can be used to override the default error
        message.

        The ``ignore_case`` argument can be set to True to compare case
        insensitive, default is False. New in SeleniumLibrary 3.1.

        ``ignore_case`` argument new in SeleniumLibrary 3.1.

        Use `Element Text Should Be` if you want to match the exact text,
        not a substring.
        """
        actual = actual_before = self.find_element(locator).text
        expected_before = expected
        if is_truthy(ignore_case):
            actual = actual.lower()
            expected = expected.lower()
        if expected not in actual:
            if is_noney(message):
                message = "Element '%s' should have contained text '%s' but "\
                          "its text was '%s'." % (locator, expected_before, actual_before)
            raise AssertionError(message)
        self.info("Element '%s' contains text '%s'." % (locator, expected_before))
    def element_text_should_be(self, locator, expected, message=None, ignore_case=False):
        """Verifies that element ``locator`` contains exact text ``expected``.

        See the `Locating elements` section for details about the locator
        syntax.

        The ``message`` argument can be used to override the default error
        message.

        The ``ignore_case`` argument can be set to True to compare case
        insensitive, default is False.

        ``ignore_case`` argument new in SeleniumLibrary 3.1.

        Use `Element Should Contain` if a substring match is desired.
        """
        self.info("Verifying element '%s' contains exact text '%s'."
                  % (locator, expected))
        text = before_text = self.find_element(locator).text
        if is_truthy(ignore_case):
            text = text.lower()
            expected = expected.lower()
        if text != expected:
            if is_noney(message):
                message = ("The text of element '%s' should have been '%s' "
                           "but it was '%s'."
                           % (locator, expected, before_text))
            raise AssertionError(message)
예제 #12
0
 def create_phantomjs(
     self,
     desired_capabilities,
     remote_url,
     options=None,
     service_log_path=None,
     executable_path="phantomjs",
 ):
     warnings.warn(
         "SeleniumLibrary support for PhantomJS has been deprecated, "
         "please use headlesschrome or headlessfirefox instead.")
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.PHANTOMJS.copy()
         desired_capabilities = self._remote_capabilities_resolver(
             desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     if options:
         logger.warn("PhantomJS browser does not support Selenium options.")
     if is_falsy(executable_path):
         executable_path = self._get_executable_path(webdriver.PhantomJS)
     return webdriver.PhantomJS(
         service_log_path=service_log_path,
         executable_path=executable_path,
         **desired_capabilities,
     )
예제 #13
0
 def create_edge(
     self,
     desired_capabilities,
     remote_url,
     options=None,
     service_log_path=None,
     executable_path="MicrosoftWebDriver.exe",
 ):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.EDGE.copy()
         desired_capabilities = self._remote_capabilities_resolver(
             desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     if is_falsy(executable_path):
         executable_path = self._get_executable_path(webdriver.Edge)
     if self._has_options(webdriver.Edge):
         # options is supported from Selenium 4.0 onwards
         # If can be removed when minimum Selenium version is 4.0 or greater
         return webdriver.Edge(
             options=options,
             service_log_path=service_log_path,
             executable_path=executable_path,
             **desired_capabilities,
         )
     return webdriver.Edge(
         service_log_path=service_log_path,
         executable_path=executable_path,
         **desired_capabilities,
     )
예제 #14
0
 def create_edge(self,
                 desired_capabilities,
                 remote_url,
                 options=None,
                 service_log_path=None):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.EDGE.copy()
         desired_capabilities = self._remote_capabilities_resolver(
             desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     if self._has_options(webdriver.Edge) and self._has_service_log_path(
             webdriver.Edge):
         # options is supported from Selenium 4.0 onwards
         # If can be removed when minimum Selenium version is 4.0 or greater
         return webdriver.Edge(options=options,
                               service_log_path=service_log_path,
                               **desired_capabilities)
     if not self._has_options(
             webdriver.Edge) and self._has_service_log_path(webdriver.Edge):
         # service_log_path is supported from Selenium 3.14 onwards
         # If can be removed when minimum Selenium version is 3.14.0 or greater
         logger.warn(
             'This version of Selenium does not support options argument.')
         return webdriver.Edge(service_log_path=service_log_path,
                               **desired_capabilities)
     logger.warn(
         'This version of Selenium does not support options or service_log_path argument.'
     )
     return webdriver.Edge(**desired_capabilities)
예제 #15
0
 def create_edge(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.EDGE.copy()
         desired_capabilities = self._remote_capabilities_resolver(
             desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Edge(**desired_capabilities)
예제 #16
0
    def element_should_not_contain(self,
                                   locator,
                                   expected,
                                   message=None,
                                   ignore_case=False):
        """Verifies that element ``locator`` does not contains text ``expected``.

        See the `Locating elements` section for details about the locator
        syntax.

        The ``message`` argument can be used to override the default error
        message.

        The ``ignore_case`` argument can be set to True to compare case
        insensitive, default is False.

        ``ignore_case`` argument new in SeleniumLibrary 3.1.
        """
        actual = self.find_element(locator).text
        expected_before = expected
        if is_truthy(ignore_case):
            actual = actual.lower()
            expected = expected.lower()
        if expected in actual:
            if is_noney(message):
                message = "Element '%s' should not contain text '%s' but " \
                          "it did." % (locator, expected_before)
            raise AssertionError(message)
        self.info("Element '%s' does not contain text '%s'." %
                  (locator, expected_before))
예제 #17
0
    def element_should_contain(self,
                               locator,
                               expected,
                               message=None,
                               ignore_case=False):
        """Verifies that element ``locator`` contains text ``expected``.

        See the `Locating elements` section for details about the locator
        syntax.

        The ``message`` argument can be used to override the default error
        message.

        The ``ignore_case`` argument can be set to True to compare case
        insensitive, default is False. New in SeleniumLibrary 3.1.

        ``ignore_case`` argument new in SeleniumLibrary 3.1.

        Use `Element Text Should Be` if you want to match the exact text,
        not a substring.
        """
        actual = actual_before = self.find_element(locator).text
        expected_before = expected
        if is_truthy(ignore_case):
            actual = actual.lower()
            expected = expected.lower()
        if expected not in actual:
            if is_noney(message):
                message = "Element '%s' should have contained text '%s' but "\
                          "its text was '%s'." % (locator, expected_before, actual_before)
            raise AssertionError(message)
        self.info("Element '%s' contains text '%s'." %
                  (locator, expected_before))
예제 #18
0
 def create_ie(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         if not desired_capabilities:
             ie = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy()
             desired_capabilities = {'desired_capabilities': ie}
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Ie(**desired_capabilities)
예제 #19
0
    def element_text_should_be(self,
                               locator,
                               expected,
                               message=None,
                               ignore_case=False):
        """Verifies that element ``locator`` contains exact text ``expected``.

        See the `Locating elements` section for details about the locator
        syntax.

        The ``message`` argument can be used to override the default error
        message.

        The ``ignore_case`` argument can be set to True to compare case
        insensitive, default is False.

        ``ignore_case`` argument new in SeleniumLibrary 3.1.

        Use `Element Should Contain` if a substring match is desired.
        """
        self.info("Verifying element '%s' contains exact text '%s'." %
                  (locator, expected))
        text = before_text = self.find_element(locator).text
        if is_truthy(ignore_case):
            text = text.lower()
            expected = expected.lower()
        if text != expected:
            if is_noney(message):
                message = ("The text of element '%s' should have been '%s' "
                           "but it was '%s'." %
                           (locator, expected, before_text))
            raise AssertionError(message)
예제 #20
0
    def element_text_should_not_be(self,
                                   locator,
                                   not_expected,
                                   message=None,
                                   ignore_case=False):
        """Verifies that element ``locator`` does not contain exact text ``not_expected``.

        See the `Locating elements` section for details about the locator
        syntax.

        The ``message`` argument can be used to override the default error
        message.

        The ``ignore_case`` argument can be set to True to compare case
        insensitive, default is False.

        New in SeleniumLibrary 3.1.1
        """
        self.info("Verifying element '%s' does not contains exact text '%s'." %
                  (locator, not_expected))
        text = self.find_element(locator).text
        before_not_expected = not_expected
        if is_truthy(ignore_case):
            text = text.lower()
            not_expected = not_expected.lower()
        if text == not_expected:
            if is_noney(message):
                message = (
                    "The text of element '%s' was not supposed to be '%s'." %
                    (locator, before_not_expected))
            raise AssertionError(message)
예제 #21
0
 def create_firefox(
     self,
     desired_capabilities,
     remote_url,
     ff_profile_dir,
     options=None,
     service_log_path=None,
     executable_path="geckodriver",
 ):
     profile = self._get_ff_profile(ff_profile_dir)
     if is_truthy(remote_url):
         default_caps = webdriver.DesiredCapabilities.FIREFOX.copy()
         desired_capabilities = self._remote_capabilities_resolver(
             desired_capabilities, default_caps)
         return self._remote(desired_capabilities, remote_url, profile,
                             options)
     service_log_path = (service_log_path
                         if service_log_path else self._geckodriver_log)
     if is_falsy(executable_path):
         executable_path = self._get_executable_path(webdriver.Firefox)
     return webdriver.Firefox(
         options=options,
         firefox_profile=profile,
         service_log_path=service_log_path,
         executable_path=executable_path,
         **desired_capabilities,
     )
예제 #22
0
 def create_edge(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         if not desired_capabilities:
             edge = webdriver.DesiredCapabilities.EDGE.copy()
             desired_capabilities = {'desired_capabilities': edge}
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Edge(**desired_capabilities)
예제 #23
0
 def create_opera(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         if not desired_capabilities:
             opera = webdriver.DesiredCapabilities.OPERA.copy()
             desired_capabilities = {'desired_capabilities': opera}
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Opera(**desired_capabilities)
예제 #24
0
 def create_safari(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         if not desired_capabilities:
             caps = webdriver.DesiredCapabilities.SAFARI.copy()
             desired_capabilities = {'desired_capabilities': caps}
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Safari(**desired_capabilities)
예제 #25
0
 def create_chrome(self, desired_capabilities, remote_url, options=None):
     if is_truthy(remote_url):
         return self._remote(desired_capabilities,
                             remote_url,
                             options=options)
     if SELENIUM_VERSION.major >= 3 and SELENIUM_VERSION.minor >= 8:
         return webdriver.Chrome(options=options, **desired_capabilities)
     return webdriver.Chrome(**desired_capabilities)
예제 #26
0
 def create_phantomjs(self, desired_capabilities, remote_url, service_log_path=None):
     warnings.warn('SeleniumLibrary support for PhantomJS has been deprecated, '
                   'please use headlesschrome or headlessfirefox instead.')
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.PHANTOMJS.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     return webdriver.PhantomJS(service_log_path=service_log_path, **desired_capabilities)
예제 #27
0
 def create_safari(self, desired_capabilities, remote_url, options=None, service_log_path=None):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.SAFARI.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     if options or service_log_path:
         logger.warn('Safari browser does not support Selenium options or service_log_path.')
     return webdriver.Safari(**desired_capabilities)
예제 #28
0
 def create_chrome(self, desired_capabilities, remote_url, options=None):
     if is_truthy(remote_url):
         if not desired_capabilities:
             desired_capabilities = {'desired_capabilities': webdriver.DesiredCapabilities.CHROME.copy()}
         return self._remote(desired_capabilities, remote_url, options=options)
     if SELENIUM_VERSION.major >= 3 and SELENIUM_VERSION.minor >= 8:
         return webdriver.Chrome(options=options, **desired_capabilities)
     return webdriver.Chrome(**desired_capabilities)
 def create_phantomjs(self, desired_capabilities, remote_url):
     warnings.warn('SeleniumLibrary support for PhantomJS has been deprecated, '
                   'please use headlesschrome or headlessfirefox instead.')
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.PHANTOMJS.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     return webdriver.PhantomJS(**desired_capabilities)
예제 #30
0
 def create_phantomjs(self, desired_capabilities, remote_url):
     warnings.warn('SeleniumLibrary support for PhantomJS has been deprecated, '
                   'please use headlesschrome or headlessfirefox instead.')
     if is_truthy(remote_url):
         if not desired_capabilities:
             caps = webdriver.DesiredCapabilities.PHANTOMJS.copy()
             desired_capabilities = {'desired_capabilities': caps}
         return self._remote(desired_capabilities, remote_url)
     return webdriver.PhantomJS(**desired_capabilities)
예제 #31
0
 def create_chrome(self, desired_capabilities, remote_url, options=None):
     default = webdriver.DesiredCapabilities.CHROME
     if is_truthy(remote_url):
         return self._remote(default, desired_capabilities, remote_url)
     capabilities = self._combine_capabilites(default, desired_capabilities)
     if SELENIUM_VERSION.major >= '3' and SELENIUM_VERSION.minor >= '8':
         return webdriver.Chrome(desired_capabilities=capabilities,
                                 options=options)
     return webdriver.Chrome(desired_capabilities=capabilities)
예제 #32
0
 def create_chrome(self, desired_capabilities, remote_url, options=None):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.CHROME.copy()
         desired_capabilities = self._remote_capabilities_resolver(
             desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities,
                             remote_url,
                             options=options)
     return webdriver.Chrome(options=options, **desired_capabilities)
예제 #33
0
 def create_edge(self, desired_capabilities, remote_url, service_log_path=None):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.EDGE.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     if self._has_service_log_path(webdriver.Ie):
         return webdriver.Edge(service_log_path=service_log_path, **desired_capabilities)
     logger.warn('This version of Selenium does not support service_log_path argument.')
     return webdriver.Edge(**desired_capabilities)
 def create_ie(self, desired_capabilities, remote_url, options=None, service_log_path=None,
               executable_path='IEDriverServer.exe'):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url, options=options)
     if is_falsy(executable_path):
         executable_path = self._get_executable_path(webdriver.Ie)
     return webdriver.Ie(options=options, service_log_path=service_log_path, executable_path=executable_path,
                         **desired_capabilities)
 def create_opera(self, desired_capabilities, remote_url, options=None, service_log_path=None,
                  executable_path='operadriver'):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.OPERA.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url, options=options)
     if is_falsy(executable_path):
         executable_path = self._get_executable_path(webdriver.Opera)
     return webdriver.Opera(options=options, service_log_path=service_log_path, executable_path=executable_path,
                            **desired_capabilities)
 def create_firefox(self, desired_capabilities, remote_url, ff_profile_dir,
                    options=None):
     profile = self._get_ff_profile(ff_profile_dir)
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.FIREFOX.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url,
                             profile, options)
     desired_capabilities.update(self._geckodriver_log)
     return webdriver.Firefox(options=options, firefox_profile=profile,
                              **desired_capabilities)
    def press_keys(self, locator=None, *keys):
        """Simulates user pressing key(s) to an element or on the active browser.


        If ``locator`` evaluates as false, see `Boolean arguments` for more
        details, then the ``keys`` are sent to the currently active browser.
        Otherwise element is searched and ``keys`` are send to the element
        identified by the ``locator``. In later case, keyword fails if element
        is not found. See the `Locating elements` section for details about
        the locator syntax.

        ``keys`` arguments can contain one or many strings, but it can not
        be empty. ``keys`` can also be a combination of
        [https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html|Selenium Keys]
        and strings or a single Selenium Key. If Selenium Key is combined
        with strings, Selenium key and strings must be separated by the
        `+` character, like in `CONTROL+c`. Selenium Keys
        are space and case sensitive and Selenium Keys are not parsed
        inside of the string. Example AALTO, would send string `AALTO`
        and `ALT` not parsed inside of the string. But `A+ALT+O` would
        found Selenium ALT key from the ``keys`` argument. It also possible
        to press many Selenium Keys down at the same time, example
        'ALT+ARROW_DOWN`.

        If Selenium Keys are detected in the ``keys`` argument, keyword
        will press the Selenium Key down, send the strings and
         then release the Selenium Key. If keyword needs to send a Selenium
        Key as a string, then each character must be separated with
        `+` character, example `E+N+D`.

        `CTRL` is alias for
        [https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html#selenium.webdriver.common.keys.Keys.CONTROL|Selenium CONTROL]
        and ESC is alias for
        [https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html#selenium.webdriver.common.keys.Keys.ESCAPE|Selenium ESCAPE]

        New in SeleniumLibrary 3.3

        Examples:
        | `Press Keys` | text_field | AAAAA          |            | # Sends string "AAAAA" to element.                                                |
        | `Press Keys` | None       | BBBBB          |            | # Sends string "BBBBB" to currently active browser.                               |
        | `Press Keys` | text_field | E+N+D          |            | # Sends string "END" to element.                                                  |
        | `Press Keys` | text_field | XXX            | YY         | # Sends strings "XXX" and "YY" to element.                                        |
        | `Press Keys` | text_field | XXX+YY         |            | # Same as above.                                                                  |
        | `Press Keys` | text_field | ALT+ARROW_DOWN |            | # Pressing "ALT" key down, then pressing ARROW_DOWN and then releasing both keys. |
        | `Press Keys` | text_field | ALT            | ARROW_DOWN | # Pressing "ALT" key and then pressing ARROW_DOWN.                                |
        | `Press Keys` | text_field | CTRL+c         |            | # Pressing CTRL key down, sends string "c" and then releases CTRL key.            |
        | `Press Keys` | button     | RETURN         |            | # Pressing "ENTER" key to element.                                                |
        """
        parsed_keys = self._parse_keys(*keys)
        if is_truthy(locator):
            self.info('Sending key(s) %s to %s element.' % (keys, locator))
        else:
            self.info('Sending key(s) %s to page.' % str(keys))
        self._press_keys(locator, parsed_keys)
예제 #38
0
    def add_cookie(self, name, value, path=None, domain=None, secure=None,
                   expiry=None):
        """Adds a cookie to your current session.

        "name" and "value" are required, "path", "domain", "secure" and
         "expiry" are optional.  Expiry supports the same formats as
         the DateTime library.
        """
        new_cookie = {'name': name, 'value': value}
        if is_truthy(path):
            new_cookie['path'] = path
        if is_truthy(domain):
            new_cookie['domain'] = domain
        # Secure should be True or False
        if is_truthy(secure):
            new_cookie['secure'] = secure
        if is_truthy(expiry):
            expiry_datetime = int(convert_date(expiry, result_format='epoch'))
            new_cookie['expiry'] = expiry_datetime
        self.browser.add_cookie(new_cookie)
    def get_alert_message(self, dismiss=True):
        """Deprecated. Use `Handle Alert` instead.

        Returns the message the alert has. Dismisses the alert by default
        (i.e. presses ``Cancel``) and setting ``dismiss`` to false leaves
        the alert open. There is no support to accept the alert (i.e. to
        press ``Ok``).

        `Handle Alert` has better support for controlling should the alert
        be accepted, dismissed, or left open.
        """
        action = self.DISMISS if is_truthy(dismiss) else self.LEAVE
        return self.handle_alert(action)
 def _make_ff(self, remote, desired_capabilites, profile_dir):
     if is_falsy(profile_dir):
         profile = webdriver.FirefoxProfile()
     else:
         profile = webdriver.FirefoxProfile(profile_dir)
     if is_truthy(remote):
         browser = self._create_remote_web_driver(
             webdriver.DesiredCapabilities.FIREFOX, remote,
             desired_capabilites, profile)
     else:
         browser = webdriver.Firefox(firefox_profile=profile,
                                     **self._geckodriver_log_config)
     return browser
    def dismiss_alert(self, accept=True):
        """Deprecated. Use `Handle Alert` instead.

        Contrary to its name, this keyword accepts the alert by default
        (i.e. presses ``Ok``). ``accept`` can be set to a false value
        to dismiss the alert (i.e. to press ``Cancel``).

        `Handle Alert` has better support for controlling should the alert
        be accepted, dismissed, or left open.
        """
        if is_truthy(accept):
            self.handle_alert(self.ACCEPT)
            return True
        self.handle_alert(self.DISMISS)
        return False
    def get_list_items(self, locator, value=False):
        """Returns the labels or values in the select list identified by `locator`.

        Select list keywords work on both lists and combo boxes. Key attributes for
        select lists are `id` and `name`. See `introduction` for details about
        locating elements.

        Example:
        | ${labels1} = | Get List Items | xpath=//h1 |
        | ${labels2} = | Get List Items | xpath=//h1 | value=${False} |
        | ${values} = | Get List Items | xpath=//h1 | value=True |
        | Should Be Equal | ${labels1} | ${labels2} |
        """
        select, options = self._get_select_list_options(locator)
        if is_truthy(value):
            return self._get_values_for_options(options)
        else:
            return self._get_labels_for_options(options)
 def _press_keys(self, locator, parsed_keys):
     if is_truthy(locator):
         element = self.find_element(locator)
     else:
         element = None
     for parsed_key in parsed_keys:
         actions = ActionChains(self.driver)
         special_keys = []
         for key in parsed_key:
             if self._selenium_keys_has_attr(key.original):
                 special_keys = self._press_keys_special_keys(actions, element, parsed_key,
                                                              key, special_keys)
             else:
                 self._press_keys_normal_keys(actions, element, key)
         for special_key in special_keys:
             self.info('Releasing special key %s.' % special_key.original)
             actions.key_up(special_key.converted)
         actions.perform()
    def get_matching_xpath_count(self, xpath, return_str=True):
        """Returns number of elements matching `xpath`

        The default return type is `str` but it can changed to `int` by setting
        the ``return_str`` argument to Python False.

        One should not use the xpath= prefix for 'xpath'. XPath is assumed.

        Correct:
        | count = | Get Matching Xpath Count | //div[@id='sales-pop']
        Incorrect:
        | count = | Get Matching Xpath Count | xpath=//div[@id='sales-pop']

        If you wish to assert the number of matching elements, use
        `Xpath Should Match X Times`.
        """
        count = len(self.find_element("xpath=" + xpath, first_only=False,
                                      required=False))
        return str(count) if is_truthy(return_str) else count
 def _make_new_browser(self, url, browser='firefox', alias=None,
                       remote_url=False, desired_capabilities=None,
                       ff_profile_dir=None):
     if is_truthy(remote_url):
         self.info("Opening browser '%s' to base url '%s' through "
                   "remote server at '%s'." % (browser, url, remote_url))
     else:
         self.info("Opening browser '%s' to base url '%s'." % (browser, url))
     driver = self._make_driver(browser, desired_capabilities,
                                ff_profile_dir, remote_url)
     driver = self._wrap_event_firing_webdriver(driver)
     try:
         driver.get(url)
     except Exception:
         self.ctx.register_driver(driver, alias)
         self.debug("Opened browser with session id %s but failed "
                    "to open url '%s'." % (driver.session_id, url))
         raise
     self.debug('Opened browser with session id %s.' % driver.session_id)
     return self.ctx.register_driver(driver, alias)
    def get_window_size(self, inner=False):
        """Returns current window width and height as integers.

        See also `Set Window Size`.

        If ``inner`` parameter is set to True, keyword returns
        HTML DOM window.innerWidth and window.innerHeight properties.
        See `Boolean arguments` for more details how to set boolean
        arguments. The ``inner`` is new in SeleniumLibrary 4.0.

        Example:
        | ${width} | ${height}= | `Get Window Size` |      |
        | ${width} | ${height}= | `Get Window Size` | True |
        """
        if is_truthy(inner):
            inner_width = int(self.driver.execute_script("return window.innerWidth;"))
            inner_height = int(self.driver.execute_script("return window.innerHeight;"))
            return inner_width, inner_height
        size = self.driver.get_window_size()
        return size['width'], size['height']
    def get_list_items(self, locator, values=False):
        """Returns all labels or values of selection list ``locator``.

        See the `Locating elements` section for details about the locator
        syntax.

        Returns visible labels by default, but values can be returned by
        setting the ``values`` argument to a true value (see `Boolean
        arguments`).

        Example:
        | ${labels} = | `Get List Items` | mylist              |             |
        | ${values} = | `Get List Items` | css:#example select | values=True |

        Support to return values is new in SeleniumLibrary 3.0.
        """
        options = self._get_options(locator)
        if is_truthy(values):
            return self._get_values(options)
        else:
            return self._get_labels(options)
 def test_is_truthy(self):
     for item in self.truthy:
         self.assertTrue(is_truthy(item) is True)
     for item in self.falsy:
         self.assertTrue(is_truthy(item) is False)
    def open_browser(
            self, url, browser='firefox', alias=None, remote_url=False,
            desired_capabilities=None, ff_profile_dir=None):
        """Opens a new browser instance to given URL.

        Returns the index of this browser instance which can be used later to
        switch back to it. Index starts from 1 and is reset back to it when
        `Close All Browsers` keyword is used. See `Switch Browser` for
        example.

        Optional alias is an alias for the browser instance and it can be used
        for switching between browsers (just as index can be used). See `Switch
        Browser` for more details.

        Possible values for `browser` are as follows:

        | firefox          | FireFox   |
        | ff               | FireFox   |
        | internetexplorer | Internet Explorer |
        | ie               | Internet Explorer |
        | googlechrome     | Google Chrome |
        | gc               | Google Chrome |
        | chrome           | Google Chrome |
        | opera            | Opera         |
        | phantomjs        | PhantomJS     |
        | htmlunit         | HTMLUnit      |
        | htmlunitwithjs   | HTMLUnit with Javascipt support |
        | android          | Android       |
        | iphone           | Iphone        |
        | safari           | Safari        |
        | edge             | Edge          |


        Note, that you will encounter strange behavior, if you open
        multiple Internet Explorer browser instances. That is also why
        `Switch Browser` only works with one IE browser at most.
        For more information see:
        http://selenium-grid.seleniumhq.org/faq.html#i_get_some_strange_errors_when_i_run_multiple_internet_explorer_instances_on_the_same_machine

        Optional 'remote_url' is the url for a remote selenium server for example
        http://127.0.0.1:4444/wd/hub. If you specify a value for remote you can
        also specify 'desired_capabilities' which is a string in the form
        key1:val1,key2:val2 that will be used to specify desired_capabilities
        to the remote server. This is useful for doing things like specify a
        proxy server for internet explorer or for specify browser and os if your
        using saucelabs.com. 'desired_capabilities' can also be a dictonary
        (created with 'Create Dictionary') to allow for more complex configurations.

        Optional 'ff_profile_dir' is the path to the firefox profile dir if you
        wish to overwrite the default. Starting from SeleniumLibrary 3.0.0
        the SeleniumLibrary does not anymore contain own profile, instead
        Selenium
        [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.firefox_profile.html|webdriver.FirefoxProfile()]
        is used.
        """
        if is_truthy(remote_url):
            self.info("Opening browser '%s' to base url '%s' through "
                      "remote server at '%s'" % (browser, url, remote_url))
        else:
            self.info("Opening browser '%s' to base url '%s'" % (browser, url))
        browser_name = browser
        browser = self._make_browser(browser_name, desired_capabilities,
                                     ff_profile_dir, remote_url)
        try:
            browser.get(url)
        except Exception:
            self.ctx.register_browser(browser, alias)
            self.debug("Opened browser with session id %s but failed "
                       "to open url '%s'" % (browser.session_id, url))
            raise
        self.debug('Opened browser with session id %s' % browser.session_id)
        return self.ctx.register_browser(browser, alias)
 def create_ie(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Ie(**desired_capabilities)
 def create_edge(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.EDGE.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Edge(**desired_capabilities)
 def create_opera(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.OPERA.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Opera(**desired_capabilities)
 def create_safari(self, desired_capabilities, remote_url):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.SAFARI.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url)
     return webdriver.Safari(**desired_capabilities)
 def create_chrome(self, desired_capabilities, remote_url, options=None):
     if is_truthy(remote_url):
         defaul_caps = webdriver.DesiredCapabilities.CHROME.copy()
         desired_capabilities = self._remote_capabilities_resolver(desired_capabilities, defaul_caps)
         return self._remote(desired_capabilities, remote_url, options=options)
     return webdriver.Chrome(options=options, **desired_capabilities)
 def _input_text_into_text_field(self, locator, text, clear):
     element = self.find_element(locator)
     if is_truthy(clear):
         element.clear()
     element.send_keys(text)