Exemple #1
0
    def _make_ff(self, proxy=None):
        cur_path = os.path.dirname(os.path.realpath(__file__))
        cur_path = cur_path + os.sep + ".." + os.sep + 'log' + os.sep + 'geckodriver.log'
        fp = None
        if System.get_os_name().lower() == 'windows':
            target = os.path.expanduser('~') \
                     + os.sep + 'AppData' + os.sep + 'Roaming' + os.sep + 'Mozilla' + os.sep + 'Firefox' \
                     + os.sep + 'Profiles'
            fp = System.search_file_contains(target, '.default')
        firefox_profile = webdriver.FirefoxProfile(fp)
        if proxy is not None:
            host, port = proxy.split(r'//')[1].split(':')[0], proxy.split(
                r'//')[1].split(':')[1]

            firefox_profile.set_preference("network.proxy.http", host)
            firefox_profile.set_preference("network.proxy.http_port",
                                           int(port))
            firefox_profile.set_preference("network.proxy.ssl", host)
            firefox_profile.set_preference("network.proxy.ssl_port", int(port))
            firefox_profile.set_preference("network.proxy.socks", host)
            firefox_profile.set_preference("network.proxy.socks_port",
                                           int(port))
            firefox_profile.set_preference("network.proxy.ftp", host)
            firefox_profile.set_preference("network.proxy.ftp_port", int(port))
            firefox_profile.set_preference("network.proxy.no_proxies_on",
                                           'localhost')
            firefox_profile.set_preference("network.proxy.type", 1)
        else:
            firefox_profile.set_preference("network.proxy.type", 0)
        firefox_capabilities = DesiredCapabilities.FIREFOX
        firefox_capabilities['acceptInsecureCerts'] = True
        firefox_capabilities['marionette'] = True

        binary = FirefoxBinary()

        return webdriver.Firefox(
            executable_path=self.__get_driver_path("firefox"),
            capabilities=firefox_capabilities,
            firefox_binary=binary,
            firefox_profile=firefox_profile,
            log_path=cur_path)
Exemple #2
0
 def _make_chrome(self, proxy=None):
     cur_path = os.path.dirname(os.path.realpath(__file__))
     cur_path = cur_path + os.sep + ".." + os.sep + 'log' + os.sep + 'chrome.log'
     chrome_capabilities = webdriver.DesiredCapabilities.CHROME
     chrome_capabilities['chromeOptions'] = {
         "args": ["--disable-extensions"],
         "extensions": []
     }
     chrome_capabilities['proxy'] = System.set_proxy(proxy)
     return webdriver.Chrome(
         executable_path=self.__get_driver_path("chrome"),
         desired_capabilities=chrome_capabilities,
         service_log_path=cur_path)
Exemple #3
0
 def element_should_not_be_enabled(self, locator, timeout=30):
     """
     Assert if the element should not be enabled
     The possible locator could be
     id, xpath, link text, partial link text, name, tag name, class name, css selector
     Example:
     | element should not be enabled | id=kwiws |
     """
     (prefix, criteria) = System.parse_locator(locator)
     if self.is_element_enabled(locator, timeout=timeout):
         message = "Element '%s' is enabled currently." % (
             prefix, criteria).__str__()
         raise AssertionError(message)
Exemple #4
0
 def element_should_contain_text(self, locator, expected=None, timeout=30):
     """
     Assert if the element contains expected text
     The possible locator could be
     id, xpath, link text, partial link text, name, tag name, class name, css selector
     Example:
     | element should contain text | id=kw | expectedtext |
     """
     (prefix, criteria) = System.parse_locator(locator)
     actual = self._get_text(locator, timeout=timeout)
     if expected not in actual:
         message = "Element '%s' should have contained text '%s' but " \
                   "its text was '%s'." % ((prefix, criteria), expected, actual)
         raise AssertionError(message)
Exemple #5
0
    def __get_driver_path(self, browser):
        default = os.path.split(os.path.realpath(__file__))[0]
        default = default + os.sep + '..' + os.sep + "resource" + os.sep + "driver"
        _browser = browser.lower()
        if _browser == "chrome":
            default = default + os.sep + _browser + os.sep + self.chrome_driver_version
            if System.get_os_name() == "linux":
                if System.is64bit():
                    default = default + os.sep + "linux64"
                else:
                    default = default + os.sep + "linux32"
                default = default + os.sep + "chromedriver"
            elif System.get_os_name() == "windows":
                default = default + os.sep + "win32" + os.sep + "chromedriver.exe"
            elif System.get_os_name() == "macos":
                default = default + os.sep + "mac64" + os.sep + "chromedriver"

        elif _browser == "edge":
            default = default + os.sep + _browser + os.sep + self.edge_driver_version \
                      + os.sep + "MicrosoftWebDriver.exe"

        elif _browser == "firefox":
            default = default + os.sep + _browser + os.sep + self.firefox_driver_version
            if System.get_os_name() == "linux":
                if System.is64bit():
                    default = default + os.sep + "linux64"
                else:
                    default = default + os.sep + "linux32"
                default = default + os.sep + "geckodriver"
            elif System.get_os_name() == "windows":
                if System.is64bit():
                    default = default + os.sep + "win64"
                else:
                    default = default + os.sep + "win32"
                default = default + os.sep + "geckodriver.exe"

        elif _browser == "ie":
            default = default + os.sep + _browser + os.sep + self.ie_driver_version
            # Use win32 for IE driver only because of performance issue.
            # if (self.__is64bit()):
            #     default = default + os.path.sep + "win64"
            # else:
            #     default = default + os.path.sep + "win32"
            # default = default + os.path.sep + "IEDriverServer.exe"
            default = default + os.sep + "win32" + os.sep + "IEDriverServer.exe"
        return default
Exemple #6
0
 def _make_ie(self, proxy=None):
     cur_path = os.path.dirname(os.path.realpath(__file__))
     cur_path = cur_path + os.sep + ".." + os.sep + 'log' + os.sep + 'ie.log'
     ie_capabilities = DesiredCapabilities.INTERNETEXPLORER
     ie_capabilities['ignoreProtectedModeSettings'] = True
     ie_capabilities[
         'INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS'] = True
     ie_capabilities['requireWindowFocus'] = False
     ie_capabilities['enableElementCacheCleanup'] = True
     ie_capabilities['ie.usePerProcessProxy'] = True
     ie_capabilities['proxy'] = System.set_proxy(proxy)
     return webdriver.Ie(executable_path=self.__get_driver_path("ie"),
                         capabilities=ie_capabilities,
                         log_file=cur_path,
                         log_level='INFO')
Exemple #7
0
 def _make_edge(self, proxy=None):
     if hasattr(webdriver, 'Edge'):
         cur_path = os.path.dirname(os.path.realpath(__file__))
         cur_path = cur_path + os.sep + ".." + os.sep + 'log' + os.sep + 'edge.log'
         edge_capabilities = DesiredCapabilities.EDGE
         edge_capabilities['edge.usePerProcessProxy'] = True
         edge_capabilities['proxy'] = System.set_proxy(proxy)
         # edge_options = Options()
         return webdriver.Edge(
             executable_path=self.__get_driver_path("edge"),
             capabilities=edge_capabilities,
             log_path=cur_path,
             verbose=True)
     else:
         raise ValueError(
             "Edge is not a supported browser with your version of Selenium python library."
             " Please, upgrade to minimum required version 2.47.0.")
Exemple #8
0
    def _safe_find(self, locator, timeout=30):
        if self._get_platform() == 'ios':
            _locator = normalize('NFD', locator)
        else:
            _locator = locator
        (prefix, criteria) = System.parse_locator(_locator)
        strategy = self._strategies.get(prefix)
        if strategy is None:
            raise ValueError(
                "Element locator with prefix '" + prefix +
                "' is not supported, Please use 'identifier','id','name','xpath','class','class name',"
                "'classname','accessibility_id','android','ios','css',"
                "'ios','css','link','link text','partial link text', 'partial link'"
            )

        start = int(round(time.time() * 1000))
        timeout = robot.utils.timestr_to_secs(
            timeout
        ) if timeout is not None else self.__default_implicit_wait_in_secs
        while timeout * 1000 > int(round(time.time() * 1000)) - start:
            try:
                _driver = self._get_current_browser()
                _driver.implicitly_wait(1)
                element_list = _driver.find_elements(strategy, criteria)
                for element in element_list:
                    if element.is_displayed():
                        _driver.implicitly_wait(
                            self.__default_implicit_wait_in_secs)
                        # print "debug time taken for safe_find is %s millisecond for element %s" % (
                        # int(round(time.time() * 1000)) - start, (by, value).__str__())
                        return element
            except:
                pass
            finally:
                _driver.implicitly_wait(self.__default_implicit_wait_in_secs)
                # print "debug time taken for safe_find is %s millisecond" % (int(round(time.time() * 1000)) - start)
        raise RuntimeError("Could not find element %s within %s millisecond." %
                           ((strategy, criteria).__str__(),
                            int(round(time.time() * 1000)) - start))
Exemple #9
0
    def _safe_finds(self, locator, timeout=30):
        if self._get_platform() == 'ios':
            _locator = normalize('NFD', locator)
        else:
            _locator = locator
        (prefix, criteria) = System.parse_locator(_locator)
        strategy = self._strategies.get(prefix)
        if strategy is None:
            raise ValueError(
                "Element locator with prefix '" + prefix +
                "' is not supported, Please use 'identifier','id','name','xpath','class',"
                "'class name','classname','accessibility_id','accessibility id','android',"
                "'ios','css','link','link text','partial link text', 'partial link'"
            )

        start = int(round(time.time() * 1000))
        timeout = robot.utils.timestr_to_secs(
            timeout
        ) if timeout is not None else self.__default_implicit_wait_in_secs
        _driver = self._get_current_browser()
        while timeout * 1000 > int(round(time.time() * 1000)) - start:
            try:
                try:
                    _driver.implicitly_wait(5)
                    WebDriverWait(_driver, 1, poll_frequency=0.1)\
                        .until(ec.visibility_of_any_elements_located(locator=(strategy, criteria)))
                except:
                    pass
                return _driver.find_elements(strategy, criteria)
            except:
                pass
            finally:
                _driver.implicitly_wait(self.__default_implicit_wait_in_secs)
        raise RuntimeError("Could not find element %s within %s millisecond." %
                           ((strategy, criteria).__str__(),
                            int(round(time.time() * 1000)) - start))