Browse Source

Service Test

Akash Singh 4 years ago
parent
commit
5ec4f3d64d

+ 1 - 0
.gitignore

@@ -17,3 +17,4 @@ baangt_*.xlsx
 /.eggs/
 /baangt.egg-info/
 /venv3_6/
+/tests/proxies.csv

+ 1 - 1
baangt/base/BrowserFactory.py

@@ -25,7 +25,7 @@ class BrowserFactory:
         self.timing = self.testrun.timing
         self.globalSettings = testrun.globalSettings
         self.browserServer = BrowserFactory.__getBrowserServer() \
-            if self.globalSettings.get('TC.' + GC.EXECUTION_NETWORK_INFO) == 'True' else None
+            if self.globalSettings.get('TC.' + GC.EXECUTION_NETWORK_INFO) == True else None
         self.browsersMobProxies = {}
 
         self.__startRotatingProxies()

+ 4 - 2
baangt/base/BrowserHandling/BrowserHandling.py

@@ -827,8 +827,10 @@ class BrowserDriver:
 
         return isZoomed
 
-    def downloadDriver(self, browserName):
-        path = Path(self.managedPaths.getOrSetDriverPath())
+    @staticmethod
+    def downloadDriver(browserName):
+        managedPaths = ManagedPaths()
+        path = Path(managedPaths.getOrSetDriverPath())
         logger.debug(f"Trying to download browserDriver for {browserName} into {path}")
         path.mkdir(parents=True, exist_ok=True)
         if browserName == GC.BROWSER_FIREFOX:

+ 12 - 0
tests/0TestInput/ServiceTestInput/globals_browsermob_proxy_chrome.json

@@ -0,0 +1,12 @@
+{
+    "TC.slowExecution": "False",
+    "TC.Browser": "CHROME",
+    "TC.BrowserAttributes": "",
+    "TC.ParallelRuns": "",
+    "TC.BrowserWindowSize": "1024x768",
+    "TC.Stage": "test",
+    "TC.NetworkInfo": "True",
+    "TC.LogLevel": "Info",
+    "TC.DriverPath": "tests/0TestInput/Drivers",
+    "1TestResults": "tests/1Testresults/ServiceTest"
+}

+ 13 - 0
tests/0TestInput/ServiceTestInput/globals_browsermob_proxy_ff.json

@@ -0,0 +1,13 @@
+{
+    "TC.slowExecution": "False",
+    "TC.dontCloseBrowser": "False",
+    "TC.Browser": "FF",
+    "TC.BrowserAttributes": "",
+    "TC.ParallelRuns": "",
+    "TC.BrowserWindowSize": "1024x768",
+    "TC.Stage": "test",
+    "TC.NetworkInfo": "True",
+    "TC.LogLevel": "Info",
+    "TC.DriverPath": "tests/0TestInput/Drivers",
+    "1TestResults": "tests/1Testresults/ServiceTest"
+}

+ 11 - 0
tests/0TestInput/ServiceTestInput/globals_chrome.json

@@ -0,0 +1,11 @@
+{
+    "TC.slowExecution": "False",
+    "TC.Browser": "CHROME",
+    "TC.BrowserAttributes": "",
+    "TC.ParallelRuns": "",
+    "TC.BrowserWindowSize": "1024x768",
+    "TC.Stage": "test",
+    "TC.LogLevel": "Info",
+    "TC.DriverPath": "tests/0TestInput/Drivers",
+    "1TestResults": "tests/1Testresults/ServiceTest"
+}

+ 12 - 0
tests/0TestInput/ServiceTestInput/globals_csv_chrome.json

@@ -0,0 +1,12 @@
+{
+    "TC.slowExecution": "False",
+    "TC.Browser": "CHROME",
+    "TC.BrowserAttributes": "",
+    "TC.ParallelRuns": "",
+    "TC.BrowserWindowSize": "1024x768",
+    "TC.Stage": "test",
+    "TC.LogLevel": "Info",
+    "TC.DriverPath": "tests/0TestInput/Drivers",
+    "TC.ExportFormat": "CSV",
+    "1TestResults": "tests/1Testresults/ServiceTest"
+}

+ 12 - 0
tests/0TestInput/ServiceTestInput/globals_csv_ff.json

@@ -0,0 +1,12 @@
+{
+    "TC.slowExecution": "False",
+    "TC.Browser": "FF",
+    "TC.BrowserAttributes": "",
+    "TC.ParallelRuns": "",
+    "TC.BrowserWindowSize": "1024x768",
+    "TC.Stage": "test",
+    "TC.LogLevel": "Info",
+    "TC.DriverPath": "tests/0TestInput/Drivers",
+    "TC.ExportFormat": "CSV",
+    "1TestResults": "tests/1Testresults/ServiceTest"
+}

+ 11 - 0
tests/0TestInput/ServiceTestInput/globals_ff.json

@@ -0,0 +1,11 @@
+{
+    "TC.slowExecution": "False",
+    "TC.Browser": "FF",
+    "TC.BrowserAttributes": "",
+    "TC.ParallelRuns": "",
+    "TC.BrowserWindowSize": "1024x768",
+    "TC.Stage": "test",
+    "TC.LogLevel": "Info",
+    "TC.DriverPath": "tests/0TestInput/Drivers",
+    "1TestResults": "tests/1Testresults/ServiceTest"
+}

+ 11 - 0
tests/0TestInput/ServiceTestInput/globals_headless_chrome.json

@@ -0,0 +1,11 @@
+{
+    "TC.slowExecution": "False",
+    "TC.Browser": "CHROME",
+    "TC.BrowserAttributes": "{'HEADLESS': 'True'}",
+    "TC.ParallelRuns": "",
+    "TC.BrowserWindowSize": "1024x768",
+    "TC.Stage": "test",
+    "TC.LogLevel": "Info",
+    "TC.DriverPath": "tests/0TestInput/Drivers",
+    "1TestResults": "tests/1Testresults/ServiceTest"
+}

+ 11 - 0
tests/0TestInput/ServiceTestInput/globals_headless_ff.json

@@ -0,0 +1,11 @@
+{
+    "TC.slowExecution": "False",
+    "TC.Browser": "FF",
+    "TC.BrowserAttributes": "{'HEADLESS': 'True'}",
+    "TC.ParallelRuns": "",
+    "TC.BrowserWindowSize": "1024x768",
+    "TC.Stage": "test",
+    "TC.LogLevel": "Info",
+    "TC.DriverPath": "tests/0TestInput/Drivers",
+    "1TestResults": "tests/1Testresults/ServiceTest"
+}

+ 11 - 0
tests/0TestInput/ServiceTestInput/globals_parellel_chrome.json

@@ -0,0 +1,11 @@
+{
+    "TC.slowExecution": "False",
+    "TC.Browser": "CHROME",
+    "TC.BrowserAttributes": "",
+    "TC.ParallelRuns": "2",
+    "TC.BrowserWindowSize": "1024x768",
+    "TC.Stage": "test",
+    "TC.LogLevel": "Info",
+    "TC.DriverPath": "tests/0TestInput/Drivers",
+    "1TestResults": "tests/1Testresults/ServiceTest"
+}

+ 11 - 0
tests/0TestInput/ServiceTestInput/globals_parellel_ff.json

@@ -0,0 +1,11 @@
+{
+    "TC.slowExecution": "False",
+    "TC.Browser": "FF",
+    "TC.BrowserAttributes": "",
+    "TC.ParallelRuns": "2",
+    "TC.BrowserWindowSize": "1024x768",
+    "TC.Stage": "test",
+    "TC.LogLevel": "Info",
+    "TC.DriverPath": "tests/0TestInput/Drivers",
+    "1TestResults": "tests/1Testresults/ServiceTest"
+}

BIN
tests/0TestInput/ServiceTestInput/simpleAutomationpractice.xlsx


BIN
tests/0TestInput/ServiceTestInput/simpleAutomationpractice_small.xlsx


+ 203 - 0
tests/test_ServiceTest.py

@@ -0,0 +1,203 @@
+import os
+import glob
+import subprocess
+from baangt.base.DownloadFolderMonitoring import DownloadFolderMonitoring
+from baangt.base.BrowserFactory import BrowserDriver
+from baangt.base import GlobalConstants as GC
+from baangt.base.PathManagement import ManagedPaths
+
+
+# Creates a copy of your environment
+my_env = os.environ.copy()
+# Use if you get error 'java' command not found even after it is installed in your system
+# Replace the path inside "" to the bin folder of java.
+# my_env["PATH"] = r"C:\Program Files (x86)\Java\jre1.8.0_251\bin;" + my_env["PATH"]
+
+
+# Will Check for the current directory.
+if not os.path.basename(os.getcwd()) == "baangt":
+    if os.path.basename(os.path.dirname(os.getcwd())) == "baangt":
+        os.chdir('..')
+    else:
+        assert 0, "Please run the test from baangt/ or baangt/tests/ directory."
+
+
+# Will delete old result files
+files = glob.glob(os.path.join(os.getcwd(), 'tests/1Testresults/ServiceTest/*'))
+for f in files:
+    if '.xlsx' in f:
+        os.remove(f)
+
+
+# To monitor new download files
+folder_monitor = DownloadFolderMonitoring(os.path.join(os.getcwd(), "tests/1Testresults/ServiceTest"))
+managed_path = ManagedPaths()
+drivers_folder = os.path.join(os.getcwd(), "tests/0TestInput/Drivers")
+
+
+def execute(run_file, globals_file):
+    # Execute the main baangt program with TestRunFile and globals file
+    subprocess.call(
+        "python baangt.py --run "+run_file+" --globals "+globals_file,
+        shell=True, env=my_env
+    )
+
+
+def test_download_browser_drivers():
+    # Will delete the pre-existing browsers and download new.
+    managed_path.getOrSetDriverPath(path=drivers_folder)
+    if os.path.exists(drivers_folder):
+        file_list = glob.glob(drivers_folder + '/*')
+        for file in file_list:
+            os.remove(file)
+    driver_folder_monitor = DownloadFolderMonitoring(drivers_folder)
+    BrowserDriver.downloadDriver(GC.BROWSER_FIREFOX)
+    BrowserDriver.downloadDriver(GC.BROWSER_CHROME)
+    new_drivers = driver_folder_monitor.getNewFiles()
+    assert driver_folder_monitor
+    for drivers in new_drivers:
+        print(drivers[0], "downloaded")
+    return "Downloading drivers test succeeded"
+
+
+# Firefox testing section
+def test_regular_firefox():
+    # Will run the main program with normal regular globals settings
+    run_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/simpleAutomationpractice_small.xlsx")
+    globals_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/globals_ff.json")
+    execute(run_file, globals_file)
+    new_file = folder_monitor.getNewFiles()
+    assert new_file
+    return "Firefox regular test succeed output file =", new_file[0][0]
+
+
+def test_parellel_firefox():
+    # Will run the main program with 2 browsers running parallel
+    run_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/simpleAutomationpractice.xlsx")
+    globals_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/globals_parellel_ff.json")
+    execute(run_file, globals_file)
+    new_file = folder_monitor.getNewFiles()
+    assert new_file
+    return "Firefox parellel test succeed output file =", new_file[0][0]
+
+
+def test_browsermob_proxy_firefox():
+    # Will run the main program with browsermob proxy mode
+    run_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/simpleAutomationpractice_small.xlsx")
+    globals_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/globals_browsermob_proxy_ff.json")
+    execute(run_file, globals_file)
+    new_file = folder_monitor.getNewFiles()
+    assert new_file
+    return "Firefox Browsermob test succeed output file =", new_file[0][0]
+
+
+def test_headless_firefox():
+    # Will run the main program with headless browser
+    run_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/simpleAutomationpractice_small.xlsx")
+    globals_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/globals_headless_ff.json")
+    execute(run_file, globals_file)
+    new_file = folder_monitor.getNewFiles()
+    assert new_file
+    return "Firefox headless test succeed output file =", new_file[0][0]
+
+
+def test_csv_firefox():
+    # Will run the main program for csv output
+    run_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/simpleAutomationpractice_small.xlsx")
+    globals_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/globals_csv_ff.json")
+    execute(run_file, globals_file)
+    new_file = folder_monitor.getNewFiles()
+    assert new_file
+    assert ".csv" in new_file[0][0]
+    return "Firefox Output Format test succeed output file =", new_file[0][0]
+
+
+def test_all_firefox():
+    # Will test all firefox functionalities together
+    results = [
+        test_regular_firefox(),
+        test_parellel_firefox(),
+        test_browsermob_proxy_firefox(),
+        test_headless_firefox(),
+        test_csv_firefox()
+    ]
+    return results
+
+
+# Chrome Testing Section
+def test_regular_chrome():
+    # Will run the main program with normal regular globals settings
+    run_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/simpleAutomationpractice_small.xlsx")
+    globals_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/globals_chrome.json")
+    execute(run_file, globals_file)
+    new_file = folder_monitor.getNewFiles()
+    assert new_file
+    return "Chrome regular test succeed output file =", new_file[0][0]
+
+
+def test_parellel_chrome():
+    # Will run the main program with 2 browsers running parallel
+    run_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/simpleAutomationpractice.xlsx")
+    globals_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/globals_parellel_chrome.json")
+    execute(run_file, globals_file)
+    new_file = folder_monitor.getNewFiles()
+    assert new_file
+    return "Chrome parellel test succeed output file =", new_file[0][0]
+
+
+def test_browsermob_proxy_chrome():
+    # Will run the main program with browsermob proxy mode
+    run_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/simpleAutomationpractice_small.xlsx")
+    globals_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/globals_browsermob_proxy_chrome.json")
+    execute(run_file, globals_file)
+    new_file = folder_monitor.getNewFiles()
+    assert new_file
+    return "Chrome Browsermob test succeed output file =", new_file[0][0]
+
+
+def test_headless_chrome():
+    # Will run the main program with headless browser
+    run_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/simpleAutomationpractice_small.xlsx")
+    globals_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/globals_headless_chrome.json")
+    execute(run_file, globals_file)
+    new_file = folder_monitor.getNewFiles()
+    assert new_file
+    return "Chrome headless test succeed output file =", new_file[0][0]
+
+
+def test_csv_chrome():
+    # Will run the main program for csv output
+    run_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/simpleAutomationpractice_small.xlsx")
+    globals_file = os.path.join(os.getcwd(), "tests/0TestInput/ServiceTestInput/globals_csv_chrome.json")
+    execute(run_file, globals_file)
+    new_file = folder_monitor.getNewFiles()
+    assert new_file
+    assert ".csv" in new_file[0][0]
+    return "Chrome Output Format test succeed output file =", new_file[0][0]
+
+
+def test_all_chrome():
+    # Will test all firefox functionalities together
+    results = [
+        test_regular_chrome(),
+        test_parellel_chrome(),
+        test_browsermob_proxy_chrome(),
+        test_headless_chrome(),
+        test_csv_chrome()
+    ]
+    return results
+
+
+def test_all():
+    # Will test all functions in this module
+    results = [
+        test_download_browser_drivers(),
+        test_all_firefox(),
+        test_all_chrome()
+    ]
+    for result in results:
+        if type(result) == str:
+            print(result)
+        else:
+            for each in result:
+                print(each)