Пример #1
0
    def findByAndForceText(self,
                           id=None,
                           css=None,
                           xpath=None,
                           class_name=None,
                           value=None,
                           iframe=None,
                           timeout=60,
                           optional=False):
        """
        Convenience Method. Please see documentation in findBy and __doSomething.

        """

        self.element, self.html = self.findBy(id=id,
                                              css=css,
                                              xpath=xpath,
                                              class_name=class_name,
                                              iframe=iframe,
                                              timeout=timeout,
                                              optional=optional)

        if not self.element:
            return False

        return webDrv.webdriver_doSomething(GC.CMD_FORCETEXT,
                                            self.element,
                                            value=value,
                                            timeout=timeout,
                                            optional=optional,
                                            browserData=self.browserData)
Пример #2
0
    def findByAndClick(self,
                       id=None,
                       css=None,
                       xpath=None,
                       class_name=None,
                       iframe=None,
                       timeout=20,
                       optional=False):
        """
        Execute a Click on an element identified by it's locator.
        @return wasSuccessful says, whether the element was found.
        """

        self.element, self.html = self.findBy(id=id,
                                              css=css,
                                              xpath=xpath,
                                              class_name=class_name,
                                              iframe=iframe,
                                              timeout=timeout,
                                              optional=optional)

        if not self.element:
            logger.debug("findBy didn't work in findByAndClick")
            return False
        else:
            return webDrv.webdriver_doSomething(GC.CMD_CLICK,
                                                self.element,
                                                timeout=timeout,
                                                optional=optional,
                                                browserData=self.browserData)
Пример #3
0
    def _browserFirefoxRun(self, browserName, lCurPath, browserProxy,
                           randomProxy, desiredCapabilities):
        executable = helper.browserHelper_getBrowserExecutable(browserName)
        self._downloadDriverCheck(executable, lCurPath, browserName)

        profile = webDrv.webdriver_setFirefoxProfile(browserProxy, randomProxy)
        self.downloadFolder = webDrv.getDownloadFolderFromProfile(profile)
        logger.debug(f"Firefox Profile as follows:{profile.userPrefs}")

        return webDrv.BROWSER_DRIVERS[browserName](
            options=webDrv.webdriver_createBrowserOptions(
                browserName=browserName,
                desiredCapabilities=desiredCapabilities),
            executable_path=helper.browserHelper_findBrowserDriverPaths(
                executable),
            firefox_profile=profile,
            service_log_path=os.path.join(self.managedPaths.getLogfilePath(),
                                          'geckodriver.log'))
Пример #4
0
    def _browserChromeRun(self, browserName, lCurPath, browserProxy,
                          randomProxy, desiredCapabilities):
        executable = helper.browserHelper_getBrowserExecutable(browserName)
        self._downloadDriverCheck(executable, lCurPath, browserName)

        lOptions = webDrv.webdriver_createBrowserOptions(
            browserName=browserName,
            desiredCapabilities=desiredCapabilities,
            browserMobProxy=browserProxy,
            randomProxy=randomProxy)

        self.downloadFolder = webDrv.getDownloadFolderFromChromeOptions(
            options=lOptions)

        return webDrv.BROWSER_DRIVERS[browserName](
            chrome_options=lOptions,
            executable_path=helper.browserHelper_findBrowserDriverPaths(
                executable),
            service_log_path=os.path.join(self.managedPaths.getLogfilePath(),
                                          'chromedriver.log'))
Пример #5
0
    def findBy(self,
               id=None,
               css=None,
               xpath=None,
               class_name=None,
               iframe=None,
               timeout=60,
               loggingOn=True,
               optional=False):
        """
        chose any single locator (ID, CSS, XPATH, CLASS_NAME) to identify an element within the page. if slowExectuion
        is set, we'll pause for slowExecutionTimeoutInSeconds.

        @param id: ID of the element
        @param css: CSS-Locator
        @param xpath: XPATH
        @param class_name: Class-Name
        @param iframe: Name of an Iframe. Use only, if you didn't set the Iframe previously already!
        @param timeout: How many seconds shall we try/retry, default = 60 Seconds
        @param loggingOn: Shall this request be logged? Default = Yes
        @param optional: If set to true and within Timeout we can't find the element, we just return this info. If set to False (=default), an Exception is raised
        @return: True if element was located, False if element couldn't be found.
        """
        self.statistics.update_teststep()

        if self.slowExecution:
            time.sleep(self.slowExecutionTimeoutInSeconds)

        if iframe:
            self.handleIframe(iframe)

        # Set class variables for potential logging of problems.
        self.browserData = self._setLocator(id, css, xpath, class_name,
                                            self.browserData)

        if loggingOn:
            logger.debug(
                f"Locating Element {self.browserData.locatorType} = {self.browserData.locator}"
            )

        self.element, self.html = webDrv.webdriver_tryAndRetry(
            self.browserData, timeout=timeout, optional=optional)

        if not self.element and not optional:
            raise Exceptions.baangtTestStepException(
                f"Element {self.browserData.locatorType} = {self.browserData.locator} could not be found "
                f"within timeout of {timeout}")
        return self.element, self.html
Пример #6
0
    def createNewBrowser(self,
                         mobileType=None,
                         mobileApp=None,
                         desired_app=None,
                         mobile_app_setting=None,
                         browserName=GC.BROWSER_FIREFOX,
                         desiredCapabilities={},
                         randomProxy=None,
                         **kwargs):
        """
        Will find the specified executables of the desired browser and start it with the given capabilities.

        @param browserName: one of GC_BROWSER_*-Browsernames, e.g. GC_BROWSER_FIREFOX
        @param desiredCapabilities: DICT of desiredCapabilities for this browser
        @param kwargs: Currently (Jan2020) not used
        """
        self.takeTime("Browser Start")
        self.randomProxy = randomProxy
        self.browserName = browserName
        self.browserProcessID = []
        lCurPath = Path(self.managedPaths.getOrSetDriverPath())

        if browserName in webDrv.BROWSER_DRIVERS:

            browserProxy = kwargs.get('browserProxy')
            browserInstance = kwargs.get('browserInstance', 'unknown')

            if utils.anything2Boolean(mobileType):
                self.browserData.driver = self._mobileConnectAppium(
                    browserName, desired_app, mobileApp, mobile_app_setting)
            elif GC.BROWSER_FIREFOX == browserName:
                self.browserData.driver = self._browserFirefoxRun(
                    browserName, lCurPath, browserProxy, randomProxy,
                    desiredCapabilities)
                helper.browserHelper_startBrowsermobProxy(
                    browserName=browserName,
                    browserInstance=browserInstance,
                    browserProxy=browserProxy)
                self.browserProcessID.append(
                    self.browserData.driver.capabilities.get("moz:processID"))
            elif GC.BROWSER_CHROME == browserName:
                self.browserData.driver = self._browserChromeRun(
                    browserName, lCurPath, browserProxy, randomProxy,
                    desiredCapabilities)
                helper.browserHelper_startBrowsermobProxy(
                    browserName=browserName,
                    browserInstance=browserInstance,
                    browserProxy=browserProxy)
                try:
                    port = self.browserData.driver.capabilities[
                        'goog:chromeOptions']["debuggerAddress"].split(":")[1]
                    fp = os.popen(f"lsof -nP -iTCP:{port} | grep LISTEN")
                    self.browserProcessID.append(
                        int(fp.readlines()[-1].split()[1]))
                except Exception as ex:
                    logger.info(ex)
            elif GC.BROWSER_EDGE == browserName:
                self.browserData.driver = webDrv.BROWSER_DRIVERS[browserName](
                    executable_path=helper.
                    browserHelper_findBrowserDriverPaths(GC.EDGE_DRIVER))
            elif GC.BROWSER_SAFARI == browserName:
                # SAFARI doesn't provide any options, but desired_capabilities.
                # Executable_path = the standard safaridriver path.
                if len(desiredCapabilities) == 0:
                    desiredCapabilities = {}
                self.browserData.driver = webDrv.BROWSER_DRIVERS[browserName](
                    desired_capabilities=desiredCapabilities)
            elif GC.BROWSER_REMOTE == browserName:
                self.browserData.driver = webDrv.BROWSER_DRIVERS[browserName](
                    options=webDrv.webdriver_createBrowserOptions(
                        browserName=browserName,
                        desiredCapabilities=desiredCapabilities),
                    command_executor=GC.REMOTE_EXECUTE_URL,
                    desired_capabilities=desiredCapabilities)
            else:
                logger.critical(
                    f"Browsername not found: {browserName}. Cancelling test run"
                )
                raise SystemError(
                    f"Browsername not found: {browserName}. Cancelling test run"
                )
        elif GC.BROWSER_REMOTE_V4 == browserName:
            desired_capabilities, seleniumGridIp, seleniumGridPort = helper.browserHelper_setSettingsRemoteV4(
                desiredCapabilities)

            if desired_capabilities['browserName'] == 'firefox':
                browserExecutable = helper.browserHelper_getBrowserExecutable(
                    GC.BROWSER_FIREFOX)
                self._downloadDriverCheck(browserExecutable, lCurPath,
                                          GC.BROWSER_FIREFOX)
            elif desired_capabilities['browserName'] == 'chrome':
                browserExecutable = helper.browserHelper_getBrowserExecutable(
                    GC.BROWSER_CHROME)
                self._downloadDriverCheck(browserExecutable, lCurPath,
                                          GC.BROWSER_CHROME)

            serverUrl = 'http://' + seleniumGridIp + ':' + seleniumGridPort
            self.browserData.driver = webDrv.BROWSER_DRIVERS[
                GC.BROWSER_REMOTE](command_executor=serverUrl,
                                   desired_capabilities=desiredCapabilities)
        else:
            raise SystemExit("Browsername unknown")

        if self.downloadFolder:
            self.downloadFolderMonitoring = DownloadFolderMonitoring(
                self.downloadFolder)

        self.takeTime("Browser Start")