Browse Source

All tests working in Pytest

Akash Singh 3 years ago
parent
commit
220f16e8d9

+ 3 - 0
baangt/base/PathManagement.py

@@ -4,7 +4,9 @@ import platform
 from pathlib import Path
 from baangt.base import GlobalConstants as GC
 from baangt.TestSteps import Exceptions as baangtExceptions
+import logging
 
+logger = logging.getLogger("pyC")
 
 class Singleton(type):
     _instances = {}
@@ -234,6 +236,7 @@ class ManagedPaths(metaclass=Singleton):
 
         if not Path(newPath).is_dir():
             baangtExceptions.baangtTestStepException(f"Tried to create folder {newPath} and failed.")
+            logger.debug(f"Tried to create folder {newPath} and failed.")
 
         return None
 

+ 1 - 1
baangt/base/TestRun/TestRun.py

@@ -257,8 +257,8 @@ class TestRun:
 
     def _initTestRunSettingsFromFile(self):
         self.__loadJSONGlobals()
-        self.__sanitizeGlobalsValues()
         self.__setPathsIfNotPredefined()
+        self.__sanitizeGlobalsValues()
 
     def __setPathsIfNotPredefined(self):
         if not self.globalSettings.get(GC.PATH_SCREENSHOTS, None):

+ 1 - 1
tests/test_DownloadFolderMonitoring.py

@@ -2,7 +2,7 @@ from baangt.base.DownloadFolderMonitoring import DownloadFolderMonitoring
 from datetime import datetime
 import os
 
-directoryToMonitor = "0TestInput"
+directoryToMonitor = os.path.join(os.getcwd(), "tests/0TestInput")
 newFileName = "DownloadFolderMonitoring_test.txt"
 newFile = os.path.join(directoryToMonitor, newFileName)
 

+ 3 - 3
tests/test_FileOpen.py

@@ -14,7 +14,7 @@ def test_Open_NoFile():
     assert not lResult
 
 
-@pytest.mark.skipif(lIsLinux)
+@pytest.mark.skipif(lIsLinux, reason="Linux")
 def test_Open_XLSX():
     lResult = FilesOpen.open(lXLSXFile)
     assert lResult
@@ -25,7 +25,7 @@ def test_Open_LOGFILE():
     assert lResult
 
 
-@pytest.mark.skipif(lIsLinux)
+@pytest.mark.skipif(lIsLinux, reason="Linux")
 def test_with_class_resultFile():
     lFilesOpen = FilesOpen.FilesOpen()
     lResult = lFilesOpen.openResultFile(lXLSXFile)
@@ -38,7 +38,7 @@ def test_with_class_LogFile():
     assert lResult
 
 
-@pytest.mark.skipif(lIsLinux)
+@pytest.mark.skipif(lIsLinux, reason="Linux")
 def test_with_class_TestRunDefinitionFile():
     lFilesOpen = FilesOpen.FilesOpen()
     lResult = lFilesOpen.openTestRunDefinition(lXLSXFile)

+ 40 - 27
tests/test_ServiceTest.py

@@ -9,7 +9,7 @@ from baangt.base import GlobalConstants as GC
 from baangt.base.PathManagement import ManagedPaths
 from baangt.base.TestRun.TestRun import TestRun
 from uuid import uuid4
-from threading import Thread
+import psutil
 
 # Will Check for the current directory and change it to baangt root dir
 if not os.path.basename(os.getcwd()) == "baangt":
@@ -21,18 +21,12 @@ if not os.path.basename(os.getcwd()) == "baangt":
 
 # Paths
 current_dir = os.getcwd()
-output_dir = Path(current_dir).joinpath('tests/1TestResults/ServiceTest')
+managed_path = ManagedPaths()
+output_dir = Path(managed_path.getOrSetExportPath())
 input_dir = Path(current_dir).joinpath("tests/0TestInput/ServiceTestInput")
 input_file = str(Path(current_dir).joinpath("tests/0TestInput/ServiceTestInput/simpleAutomationpractice_small.xlsx"))
 input_file_parallel = str(Path(input_dir).joinpath("simpleAutomationpractice.xlsx"))
-drivers_folder = Path(current_dir).joinpath("tests/0TestInput/Drivers")
-
-
-# Make and check dir using ManagePaths method & updating ManagePaths for driver path
-managed_path = ManagedPaths()
-managed_path._ManagedPaths__makeAndCheckDir(output_dir)
-managed_path._ManagedPaths__makeAndCheckDir(drivers_folder)
-managed_path.getOrSetDriverPath(path=str(drivers_folder))
+drivers_folder = Path(managed_path.getOrSetDriverPath())
 
 
 # Creates a copy of your environment
@@ -42,13 +36,6 @@ my_env = os.environ.copy()
 my_env["PATH"] = r"C:\Program Files (x86)\Java\jre1.8.0_251\bin;" + my_env["PATH"]
 
 
-# Will delete old result files
-files = glob.glob(str(output_dir.joinpath('*')))
-for f in files:
-    if '.xlsx' in f:
-        os.remove(f)
-
-
 # To monitor new download files
 folder_monitor = DownloadFolderMonitoring(str(output_dir))
 
@@ -111,7 +98,9 @@ def test_regular_firefox():
     execute(run_file, globals_file)
     new_file = folder_monitor.getNewFiles()
     assert new_file
-    check_output(output_dir.joinpath(new_file[0][0]).as_posix())
+    output_file = output_dir.joinpath(new_file[0][0]).as_posix()
+    check_output(output_file)
+    os.remove(output_file)
     return "Firefox regular test succeed output file =", new_file[0][0]
 
 
@@ -122,7 +111,9 @@ def test_parellel_firefox():
     execute(run_file, globals_file)
     new_file = folder_monitor.getNewFiles()
     assert new_file
-    check_output(output_dir.joinpath(new_file[0][0]).as_posix())
+    output_file = output_dir.joinpath(new_file[0][0]).as_posix()
+    check_output(output_file)
+    os.remove(output_file)
     return "Firefox parellel test succeed output file =", new_file[0][0]
 
 
@@ -133,8 +124,10 @@ def test_browsermob_proxy_firefox():
     execute(run_file, globals_file)
     new_file = folder_monitor.getNewFiles()
     assert new_file
-    check_output(output_dir.joinpath(new_file[0][0]).as_posix())
-    check_browsermob_output(output_dir.joinpath(new_file[0][0]).as_posix())
+    output_file = output_dir.joinpath(new_file[0][0]).as_posix()
+    check_output(output_file)
+    check_browsermob_output(output_file)
+    os.remove(output_file)
     return "Firefox Browsermob test succeed output file =", new_file[0][0]
 
 
@@ -145,7 +138,9 @@ def test_headless_firefox():
     execute(run_file, globals_file)
     new_file = folder_monitor.getNewFiles()
     assert new_file
-    check_output(output_dir.joinpath(new_file[0][0]).as_posix())
+    output_file = output_dir.joinpath(new_file[0][0]).as_posix()
+    check_output(output_file)
+    os.remove(output_file)
     return "Firefox headless test succeed output file =", new_file[0][0]
 
 
@@ -157,6 +152,8 @@ def test_csv_firefox():
     new_file = folder_monitor.getNewFiles()
     assert new_file
     assert ".csv" in new_file[0][0]
+    output_file = output_dir.joinpath(new_file[0][0]).as_posix()
+    os.remove(output_file)
     return "Firefox Output Format test succeed output file =", new_file[0][0]
 
 
@@ -168,7 +165,9 @@ def test_regular_chrome():
     execute(run_file, globals_file)
     new_file = folder_monitor.getNewFiles()
     assert new_file
-    check_output(output_dir.joinpath(new_file[0][0]).as_posix())
+    output_file = output_dir.joinpath(new_file[0][0]).as_posix()
+    check_output(output_file)
+    os.remove(output_file)
     return "Chrome regular test succeed output file =", new_file[0][0]
 
 
@@ -179,7 +178,9 @@ def test_parellel_chrome():
     execute(run_file, globals_file)
     new_file = folder_monitor.getNewFiles()
     assert new_file
-    check_output(output_dir.joinpath(new_file[0][0]).as_posix())
+    output_file = output_dir.joinpath(new_file[0][0]).as_posix()
+    check_output(output_file)
+    os.remove(output_file)
     return "Chrome parellel test succeed output file =", new_file[0][0]
 
 
@@ -190,19 +191,27 @@ def test_browsermob_proxy_chrome():
     execute(run_file, globals_file)
     new_file = folder_monitor.getNewFiles()
     assert new_file
-    check_output(output_dir.joinpath(new_file[0][0]).as_posix())
-    check_browsermob_output(output_dir.joinpath(new_file[0][0]).as_posix())
+    output_file = output_dir.joinpath(new_file[0][0]).as_posix()
+    check_output(output_file)
+    check_browsermob_output(output_file)
+    os.remove(output_file)
     return "Chrome Browsermob test succeed output file =", new_file[0][0]
 
 
 def test_headless_chrome():
     # Will run the main program with headless browser
+    for proc in psutil.process_iter():
+        if proc.name() == "browsermob-proxy":
+            proc.kill()
+
     run_file = input_file
     globals_file = Path(input_dir).joinpath("globals_headless_chrome.json").as_posix()
     execute(run_file, globals_file)
     new_file = folder_monitor.getNewFiles()
     assert new_file
-    check_output(output_dir.joinpath(new_file[0][0]).as_posix())
+    output_file = output_dir.joinpath(new_file[0][0]).as_posix()
+    check_output(output_file)
+    os.remove(output_file)
     return "Chrome headless test succeed output file =", new_file[0][0]
 
 
@@ -222,3 +231,7 @@ def test_full_BaangtWebDemo():
     execute(run_file, globals_file=Path(input_dir).joinpath("globals_ff.json"))
     new_file = folder_monitor.getNewFiles()
     assert new_file
+    output_file = output_dir.joinpath(new_file[0][0]).as_posix()
+    check_output(output_file)
+    os.remove(output_file)
+

+ 1 - 1
tests/test_Utils.py

@@ -230,7 +230,7 @@ def test_dynamicImportOfClasses_path_className_not_found_class_in_module():
 
 def test_findFileAndPathFromPath_directory():
     directory = "~/baangt/examples"
-    fileNameAndPath = Path(directory).joinpath('globals.json')
+    fileNameAndPath = Path(directory).joinpath('global_not_exist.json')
     with pytest.raises(Exception):
         utils.findFileAndPathFromPath(fileNameAndPath, directory)
 

+ 3 - 3
tests/test_browserHandling.py

@@ -27,7 +27,7 @@ def test_setZoomFactor(getdriver):
     assert not getdriver.browserData.driver
 
 
-@pytest.mark.parametrize(("driverName", "browserName"), [("geckodriver", GC.BROWSER_FIREFOX), ("chromedriver", GC.BROWSER_CHROME)])
+@pytest.mark.parametrize(("driverName", "browserName"), [("geckodriver.exe", GC.BROWSER_FIREFOX), ("chromedriver.exe", GC.BROWSER_CHROME)])
 def test_downloadDriver(getdriver, driverName, browserName):
     from pathlib import Path
     import os
@@ -40,11 +40,11 @@ def test_downloadDriver(getdriver, driverName, browserName):
         os.remove(fileName)
     except:
         pass
-    assert False == os.path.isfile(fileName) 
+    assert not os.path.isfile(fileName)
 
     # create browser
     getdriver.downloadDriver(browserName)
-    assert True == os.path.isfile(fileName) 
+    assert os.path.isfile(fileName)
 
 
 def test_findBy_class(getdriver):