Browse Source

first commit

jan baker 4 years ago
parent
commit
8da6fc6043

+ 2 - 1
.gitignore

@@ -13,4 +13,5 @@ __pycache__
 *.db
 *.log
 venv
-application.sublime-workspace
+application.sublime-workspace
+/.project

BIN
SimpleTheInternet.xlsx


+ 68 - 36
baangt/base/BrowserHandling/BrowserHandling.py

@@ -37,6 +37,7 @@ class BrowserDriver:
     - javaScript: to pass JS directly to the browser
     - takeScreenshot: yes, that.
     """
+
     def __init__(self, timing=None, screenshotPath=None):
         self.driver = None
         self.iFrame = None
@@ -75,23 +76,23 @@ class BrowserDriver:
             GC.BROWSER_EDGE: webdriver.Edge,
             GC.BROWSER_REMOTE: webdriver.Remote}
 
-        if browserName in browserNames:
-            GeckoExecutable = "geckodriver"
-            ChromeExecutable = "chromedriver"
+        GeckoExecutable = "geckodriver"
+        ChromeExecutable = "chromedriver"
 
-            if 'NT' in os.name.upper():
-                GeckoExecutable = GeckoExecutable + ".exe"
-                ChromeExecutable = ChromeExecutable + ".exe"
+        if 'NT' in os.name.upper():
+            GeckoExecutable = GeckoExecutable + ".exe"
+            ChromeExecutable = ChromeExecutable + ".exe"
 
+        lCurPath = Path(os.getcwd())
+        lCurPath = lCurPath.joinpath("browserDrivers")
 
-            lCurPath = Path(os.getcwd())
-            lCurPath = lCurPath.joinpath("browserDrivers")
+        if browserName in browserNames:
 
             browserProxy = kwargs.get('browserProxy')
             browserInstance = kwargs.get('browserInstance', 'unknown')
             if browserName == GC.BROWSER_FIREFOX:
                 lCurPath = lCurPath.joinpath(GeckoExecutable)
-                if not(os.path.isfile(str(lCurPath))):
+                if not (os.path.isfile(str(lCurPath))):
                     self.downloadDriver(browserName)
 
                 profile = None
@@ -111,14 +112,16 @@ class BrowserDriver:
                 lCurPath = lCurPath.joinpath(ChromeExecutable)
                 if not (os.path.isfile(str(lCurPath))):
                     self.downloadDriver(browserName)
-                self.driver = browserNames[browserName](chrome_options=self.__createBrowserOptions(browserName=browserName,
-                                                                                            desiredCapabilities=desiredCapabilities,
-                                                                                            browserProxy=browserProxy),
-                                                        executable_path=self.__findBrowserDriverPaths(ChromeExecutable))
+                self.driver = browserNames[browserName](
+                    chrome_options=self.__createBrowserOptions(browserName=browserName,
+                                                               desiredCapabilities=desiredCapabilities,
+                                                               browserProxy=browserProxy),
+                    executable_path=self.__findBrowserDriverPaths(ChromeExecutable))
                 browserProxy.new_har("baangt-chrome-{}".format(browserInstance),
                                      options={'captureHeaders': True, 'captureContent': True}) if browserProxy else None
             elif browserName == GC.BROWSER_EDGE:
-                self.driver = browserNames[browserName](executable_path=self.__findBrowserDriverPaths("msedgedriver.exe"))
+                self.driver = browserNames[browserName](
+                    executable_path=self.__findBrowserDriverPaths("msedgedriver.exe"))
             elif browserName == GC.BROWSER_SAFARI:
                 # SAFARI doesn't provide any options, but desired_capabilities.
                 # Executable_path = the standard safaridriver path.
@@ -131,6 +134,35 @@ class BrowserDriver:
                                                                                             desiredCapabilities=desiredCapabilities),
                                                         command_executor='http://localhost:4444/wd/hub',
                                                         desired_capabilities=desiredCapabilities)
+        elif browserName == GC.BROWSER_REMOTE_V4:
+            desired_capabilities = eval(desiredCapabilities)
+            if 'seleniumGridIp' in desired_capabilities.keys():
+                seleniumGridIp = desired_capabilities['seleniumGridIp']
+                del desired_capabilities['seleniumGridIp']
+            else:
+                seleniumGridIp = '127.0.0.1'
+
+            if 'seleniumGridPort' in desired_capabilities.keys():
+                seleniumGridPort = desired_capabilities['seleniumGridPort']
+                del desired_capabilities['seleniumGridPort']
+            else:
+                seleniumGridPort = '4444'
+
+            if not 'browserName' in desired_capabilities.keys():
+                desired_capabilities['browserName'] = 'firefox'
+
+            if desired_capabilities['browserName'] == 'firefox':
+                lCurPath = lCurPath.joinpath(GeckoExecutable)
+                if not (os.path.isfile(str(lCurPath))):
+                    self.downloadDriver(GC.BROWSER_FIREFOX)
+            elif desired_capabilities['browserName'] == 'chrome':
+                lCurPath = lCurPath.joinpath(ChromeExecutable)
+                if not (os.path.isfile(str(lCurPath))):
+                    self.downloadDriver(GC.BROWSER_CHROME)
+
+            serverUrl = 'http://' + seleniumGridIp + ':' + seleniumGridPort
+
+            self.driver = webdriver.Remote(command_executor=serverUrl, desired_capabilities=desired_capabilities)
         else:
             raise SystemExit("Browsername unknown")
 
@@ -154,7 +186,7 @@ class BrowserDriver:
         logger.debug(f"Path for BrowserDrivers: {lCurPath}")
         return str(lCurPath)
 
-    def slowExecutionToggle(self, newSlowExecutionWaitTimeInSeconds = None):
+    def slowExecutionToggle(self, newSlowExecutionWaitTimeInSeconds=None):
         """
         SlowExecution can be set in globals or by the teststep. It's intended use is debugging or showcasing a testcases
         functionality.
@@ -173,7 +205,6 @@ class BrowserDriver:
 
         return self.slowExecution
 
-
     def __createBrowserOptions(self, browserName, desiredCapabilities, browserProxy=None):
         """
         Translates desired capabilities from the Testrun (or globals) into specific BrowserOptions for the
@@ -345,7 +376,7 @@ class BrowserDriver:
                 elif self.element.tag_name == 'input':
                     #  element is of type <input />
                     return self.element.get_property('value')
-                
+
             except Exception as e:
                 logger.debug(f"Exception during findByAndWaitForValue, but continuing {str(e)}, "
                              f"Locator: {self.locatorType} = {self.locator}")
@@ -392,14 +423,14 @@ class BrowserDriver:
         return self.findByAndSetText(id=id, css=css, xpath=xpath, class_name=class_name, value=value, iframe=iframe,
                                      timeout=timeout)
 
-    def findByAndSetTextValidated(self,id = None,
-                       css = None,
-                       xpath = None,
-                       class_name = None,
-                       value = None,
-                       iframe = None,
-                       timeout = 60,
-                       retries = 5):
+    def findByAndSetTextValidated(self, id=None,
+                                  css=None,
+                                  xpath=None,
+                                  class_name=None,
+                                  value=None,
+                                  iframe=None,
+                                  timeout=60,
+                                  retries=5):
         """
         This is a method not recommended to be used regularly. Sometimes (especially with Angular Frontends) it gets
         pretty hard to set a value into a field. Chrome, but also FF will show the value, but the DOM will not have it.
@@ -412,7 +443,6 @@ class BrowserDriver:
         self.findBy(id=id, css=css, xpath=xpath, class_name=class_name, iframe=iframe, timeout=timeout)
 
         while self.element.text != value and self.element.get_property("value") != value and tries < retries:
-
             self._log(logging.DEBUG, f"Verified trying of SetText - iteration {tries} of {retries}")
 
             self.findByAndForceText(id=id, css=css, xpath=xpath, class_name=class_name, iframe=iframe,
@@ -429,7 +459,7 @@ class BrowserDriver:
         """
         self.element.submit()
 
-    def findByAndClick(self, id = None, css=None, xpath=None, class_name=None, iframe=None, timeout=20, optional=False):
+    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.
@@ -607,13 +637,13 @@ class BrowserDriver:
 
         return wasSuccessful
 
-    def findWaitNotVisible(self, css=None, xpath=None, id=None, timeout = 90, optional = False):
+    def findWaitNotVisible(self, css=None, xpath=None, id=None, timeout=90, optional=False):
         """
         You'd use this method when you wait for an element to disappear, for instance Angular Spinner or a popup
         to disapear before you continue with your script in the main screen.
 
         """
-        self._log(logging.DEBUG, "Waiting for Element to disappear", **{"xpath":xpath, "timeout":timeout})
+        self._log(logging.DEBUG, "Waiting for Element to disappear", **{"xpath": xpath, "timeout": timeout})
         time.sleep(0.5)
 
         stillHere = True
@@ -636,7 +666,8 @@ class BrowserDriver:
                 self._log(logging.DEBUG, f"Element was gone after {format(elapsed, '.2f')} seconds")
                 return
 
-        raise Exceptions.baangtTestStepException(f"Element still here after {timeout} seconds. Locator: xpath={xpath}, id={id}")
+        raise Exceptions.baangtTestStepException(
+            f"Element still here after {timeout} seconds. Locator: xpath={xpath}, id={id}")
 
     @staticmethod
     def sleep(sleepTimeinSeconds):
@@ -688,12 +719,14 @@ class BrowserDriver:
                 raise Exceptions.baangtTestStepException(e)
             except NoSuchWindowException as e:
                 raise Exceptions.baangtTestStepException(e)
-            elapsed = time.time()-begin
+            elapsed = time.time() - begin
 
         if optional:
-            logger.debug(f"Action not possible after {timeout} s, Locator: {self.locatorType}: {self.locator}, but flag 'optional' is set")
+            logger.debug(
+                f"Action not possible after {timeout} s, Locator: {self.locatorType}: {self.locator}, but flag 'optional' is set")
         else:
-            raise Exceptions.baangtTestStepException(f"Action not possible after {timeout} s, Locator: {self.locatorType}: {self.locator}")
+            raise Exceptions.baangtTestStepException(
+                f"Action not possible after {timeout} s, Locator: {self.locatorType}: {self.locator}")
 
     def goToUrl(self, url):
         self._log(logging.INFO, f'GoToUrl:{url}')
@@ -714,12 +747,11 @@ class BrowserDriver:
         except Exception as e:
             self._log(logging.WARNING, f"Tried to go back in history, didn't work with error {e}")
 
-
     def javaScript(self, jsText):
         """Execute a given JavaScript in the current Session"""
         self.driver.execute_script(jsText)
 
-    def downloadDriver(self,browserName):
+    def downloadDriver(self, browserName):
         path = Path(os.getcwd())
         path = path.joinpath("browserDrivers")
         tar_url = ''
@@ -751,7 +783,7 @@ class BrowserDriver:
 
             if tar_url != '':
                 path_zip = path.joinpath(GC.GECKO_DRIVER.replace('exe', 'tar.gz'))
-                filename, headers = urlretrieve(tar_url,path_zip)
+                filename, headers = urlretrieve(tar_url, path_zip)
                 tar = tarfile.open(filename, "r:gz")
                 tar.extractall(path)
                 tar.close()

+ 1 - 0
baangt/base/GlobalConstants.py

@@ -28,6 +28,7 @@ BROWSER_CHROME = "CHROME"
 BROWSER_SAFARI = "SAFARI"
 BROWSER_EDGE = "EDGE"
 BROWSER_REMOTE = 'REMOTE'
+BROWSER_REMOTE_V4 = 'REMOTE_V4'
 BROWSER_MODE_HEADLESS = "HEADLESS"
 BROWSER_ATTRIBUTES = "BrowserAttributes"
 

BIN
browserDrivers/chromedriver.exe


BIN
browserDrivers/geckodriver


BIN
browserDrivers/geckodriver.exe


BIN
browserDrivers/msedgedriver.exe


BIN
browserDrivers/chromedriver_78


+ 12 - 0
globals.json

@@ -0,0 +1,12 @@
+{
+    "exportFilesBasePath": "",
+    "TC.Lines": "",
+    "RootPath": "/home/aaa/baangt",
+    "ScreenshotPath": "/home/aaa/baangt/Screenshots",
+    "ExportPath": "/home/aaa/baangt/1testoutput",
+    "ImportPath": "/home/aaa/baangt/0testdateninput",
+    "TC.dontCloseBrowser": "",
+    "TC.slowExecution": "",
+    "TC.BrowserAttributes": "{'browserName': 'chrome', 'seleniumGridIp': 'localhost', 'seleniumGridPort': '4444'}",
+    "TC.Browser": "REMOTE_V4"
+}

+ 15 - 0
test.json

@@ -0,0 +1,15 @@
+{
+    "exportFilesBasePath": "",
+    "TC.Lines": "",
+    "TC.dontCloseBrowser": "True",
+    "TC.slowExecution": "True",
+    "TC.NetworkInfo": "True",
+    "TC.BrowserAttributes": "{'browserName': 'chrome'}",
+    "RootPath": "D:\\www_desktop\\python\\20200317_python_baangt\\baangt",
+    "ScreenshotPath": "D:\\www_desktop\\python\\20200317_python_baangt\\baangt\\Screenshots",
+    "ExportPath": "D:\\www_desktop\\python\\20200317_python_baangt\\baangt\\1testoutput",
+    "ImportPath": "D:\\www_desktop\\python\\20200317_python_baangt\\baangt\\0testdateninput",
+    "TC.Browser": "REMOTE_V4",
+    "TC.SeleniumGridIP": "127.0.0.1",
+    "TC.SeleniumGridPort": "4444"
+}