baangt.py 2.2 KB

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