test_BrowserFactory.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import pytest
  2. import pathlib
  3. from baangt.base.TestRun.TestRun import TestRun
  4. from baangt.base.BrowserFactory import BrowserFactory
  5. from baangt.base import GlobalConstants as GC
  6. testRun = None
  7. brFactory = None
  8. currentPath = pathlib.Path(__file__).parent.absolute()
  9. # parentPath = pathlib.Path(currentPath).parent
  10. parentPath = currentPath
  11. testRunFile = parentPath.joinpath("0TestInput/YoutubePromo.xlsx")
  12. settingfile = parentPath.joinpath("0TestInput/globals_headless.json")
  13. def BrowserFactoryInit(testRunFile, settingFile):
  14. global testRun
  15. testRun = TestRun(f"{testRunFile}",
  16. globalSettingsFileNameAndPath=f"{settingFile}", executeDirect=False)
  17. testRun._initTestRunSettingsFromFile() # Loads the globals*.json file
  18. testRun._loadJSONTestRunDefinitions()
  19. testRun._loadExcelTestRunDefinitions()
  20. brFactory = BrowserFactory(testRun)
  21. return brFactory
  22. browserFactory = BrowserFactoryInit(testRunFile=testRunFile, settingFile=settingfile)
  23. def test_getBrowser():
  24. global testRun
  25. mobileType = False
  26. browserInstance = browserFactory.getBrowser(mobileType=mobileType, browserName=GC.BROWSER_FIREFOX,
  27. browserAttributes=testRun.globalSettings["TC." + GC.BROWSER_ATTRIBUTES])
  28. assert browserInstance is not None
  29. print('GetBrowser - (mobileType={0}, browserName=GC.BROWSER_FIREFOX) OK'.format(mobileType))
  30. def test__getBrowserInstance():
  31. try:
  32. with pytest.raises(Exception) as e:
  33. browserFactory._getBrowserInstance(browserInstance=0)
  34. except:
  35. print("test__getBrowserInstance OK")
  36. def test_tearDown():
  37. try:
  38. with pytest.raises(Exception) as e:
  39. browserFactory.teardown()
  40. except:
  41. print("test_tearDown OK")