baangt.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import getopt
  2. import sys
  3. from baangt.base.TestRun import TestRun
  4. from baangt.ui.ui import UI
  5. # from baangtVIG.CustTestRun import CustTestRun
  6. from baangt.base.utils import utils
  7. def args_read(l_search_parameter):
  8. l_args = sys.argv[1:]
  9. try:
  10. opts, args = getopt.getopt(l_args, "", ["run=",
  11. "globals="
  12. ])
  13. except getopt.GetoptError as err_det:
  14. print("Error in reading parameters:" + str(err_det))
  15. print_args()
  16. sys.exit("Wrong parameters - exiting")
  17. if opts:
  18. for opt, arg in opts:
  19. if l_search_parameter == opt: # in ("-u", "--usage"):
  20. return arg
  21. if "--" + l_search_parameter == opt:
  22. return arg
  23. return None
  24. def print_args():
  25. print("""
  26. Call: python baangt.py --parameters
  27. --run=<Existing, predefined Name of a TestRun (XLSX or .JSON-File incl. Path)>
  28. --globals=<path to JSON-File containing global Settings. If omitted, will look for globals.json in the current directory>
  29. Suggested for standard use:
  30. python baangt.py --run="Franzi4711.xlsx": Will run a Testrun Franzi4711.xlsx
  31. python baangt.py --run="runProducts.json": Will execute a Testrun as specified in runProducts.json and use default globals.json, if exists
  32. python baangt.py --run="runProducts.json" --globals="production.json" will use settings in production.json
  33. python baangt.py --run="runProducts.json" --globals="qa.json" will use settings in qa.json
  34. """)
  35. def callTestrun():
  36. if ".XLSX" in testRunFile.upper() or ".JSON" in testRunFile.upper():
  37. TestRun(testRunName=utils.sanitizeFileName(testRunFile),
  38. globalSettingsFileNameAndPath=utils.sanitizeFileName(globalSettingsFileName))
  39. else:
  40. sys.exit(f"Unknown Filetype - should be XLSX or JSON: {testRunFile}")
  41. def getGlobalSettings():
  42. lGlobals = args_read("globals")
  43. if not lGlobals:
  44. lGlobals = "globals.json"
  45. return lGlobals
  46. print_args()
  47. testRunFile=args_read("run")
  48. if testRunFile:
  49. print(f"Starting Testrun: {testRunFile}")
  50. globalSettingsFileName = getGlobalSettings()
  51. callTestrun()
  52. else:
  53. UI()