Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. import os
  2. import subprocess
  3. import time
  4.  
  5. # extract the transaction IDs and create a list with all of them
  6. def findTransactionIDs(filename):
  7. transIDlist = []
  8. with open(filename) as search:
  9. for line in search:
  10. if (line.find('<transaction_id>') != -1):
  11. transIDlist.append(line)
  12.  
  13. #debug
  14. for id in transIDlist:
  15. print(id)
  16.  
  17. return transIDlist
  18.  
  19. def findBasketIDs(filename):
  20. kID = []
  21. with open(filename) as search:
  22. for line in search:
  23. if (line.find('050bc41f-82b8-4c34-a687-9805672b2796') != -1):
  24. kID.append(previous_line)
  25. break
  26.  
  27. previous_line = line
  28.  
  29. #debug
  30. for id in kID:
  31. print(id)
  32.  
  33. return kID
  34.  
  35. # extract the trans ID that matches the comment in the input parameter
  36. def getTransIDbyID(str, new_ID_list):
  37. ind = int(str[str.find('#')+1:-3])
  38. return new_ID_list.get(ind-1)
  39.  
  40. # insert the transaction IDs into the requests
  41. def inserter(targetStr, new_ID_list):
  42. fin = open(r'C:\Users\nemethat\Documents\ODE-Showcase-2-soapui-project.xml', encoding="utf8")
  43. fout = open(r'C:\Users\nemethat\Documents\ODE-Showcase-2-soapui-project_copytest.xml',"wt", encoding="utf8")
  44.  
  45. #tID = getTransIDbyID(1,new_ID_list)
  46.  
  47. for line in fin:
  48. if (line.find(targetStr) != -1):
  49. line = new_ID_list.strip() + targetStr +'\n'
  50. fout.write(line)
  51.  
  52. fin.close()
  53. fout.close()
  54.  
  55. os.replace(r'C:\Users\nemethat\Documents\ODE-Showcase-2-soapui-project_copytest.xml',r'C:\Users\nemethat\Documents\ODE-Showcase-2-soapui-project.xml')
  56.  
  57. def openTransaction():
  58. print('[AUTOREGRESSION] running openTrans..')
  59.  
  60. subprocess.run(r'>nul cmd.exe /C C:\"Program Files"\SmartBear\SoapUI-5.3.0\bin\testrunner.bat >nul 2>&1 -s"csavarsoapBinding TestSuite" -cAutoOpen -a -f"C:\Users\nemethat\Documents\AutoResponses" C:\Users\nemethat\Documents\ODE-Showcase-2-soapui-project.xml',
  61. shell=True, stdout=subprocess.PIPE,
  62. universal_newlines=True)
  63.  
  64. time.sleep(5)
  65.  
  66. def setProductOffering():
  67. print('[AUTOREGRESSION] running setProductOffering..')
  68.  
  69. subprocess.run(r'cmd.exe /C C:\"Program Files"\SmartBear\SoapUI-5.3.0\bin\testrunner.bat >nul 2>&1 -s"csavarsoapBinding TestSuite" -c"AutoSet" -a -f"C:\Users\nemethat\Documents\AutoResponses" C:\Users\nemethat\Documents\ODE-Showcase-2-soapui-project.xml',
  70. shell=True, stdout=subprocess.PIPE,
  71. universal_newlines=True)
  72.  
  73. def commitTransaction():
  74. print ('[AUTOREGRESSION] running CommitTransaction..')
  75.  
  76. subprocess.run(r'cmd.exe /C C:\"Program Files"\SmartBear\SoapUI-5.3.0\bin\testrunner.bat >nul 2>&1 -s"csavarsoapBinding TestSuite" -c"AutoCommit" -a -f"C:\Users\nemethat\Documents\AutoResponses" C:\Users\nemethat\Documents\ODE-Showcase-2-soapui-project.xml',
  77. shell=True, stdout=subprocess.PIPE,
  78. universal_newlines=True)
  79.  
  80. # main
  81.  
  82. # 1 testrunner open
  83.  
  84. openTransaction()
  85.  
  86. # 2 extract and replace transaction id
  87. print('[AUTOREGRESSION] finding ID..')
  88.  
  89. trans_list = findTransactionIDs(r'C:\Users\nemethat\Documents\AutoResponses\csavarsoapBinding_TestSuite-AutoOpen-openTransaction-0-UNKNOWN.txt')
  90.  
  91. basket_list = findBasketIDs(r'C:\Users\nemethat\Documents\AutoResponses\csavarsoapBinding_TestSuite-AutoOpen-openTransaction-0-UNKNOWN.txt')
  92.  
  93. print('[AUTOREGRESSION] replacing ID..')
  94.  
  95. inserter('<!--transID target#1-->', trans_list)
  96. inserter('<!--transID target#2-->', basket_list)
  97. inserter('<!--transID target#3-->', trans_list)
  98.  
  99. # 3 setProductOffering
  100.  
  101. setProductOffering()
  102.  
  103. # 4 commit
  104.  
  105. commitTransaction()
  106.  
  107. print('[AUTOREGRESSION] Finished!')
  108.  
  109.  
  110.  
  111. # print('done')
  112. # time.sleep(5)
  113.  
  114. # 3 testrunner get available
  115.  
  116. # print('[AUTOREGRESSION] running getAvailable..')
  117. # cmd.exe /C testrunner.bat -s"csavarsoapBinding TestSuite" -c"proba 2" -a -f"C:\work\6 - argr\proba" C:\Users\nemethat\Documents\ODE-Showcase-2-soapui-project.xml
  118.  
  119. # subprocess.run(r'cmd.exe /C C:\"Program Files"\SmartBear\SoapUI-5.3.0\bin\testrunner.bat >nul 2>&1 -s"csavarsoapBinding TestSuite" -c"proba 2" -a -f"C:\work\6 - argr\proba" C:\Users\nemethat\Documents\ODE-Showcase-2-soapui-project.xml',
  120. # shell=True, stdout=subprocess.PIPE,
  121. # universal_newlines=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement