I am using Selenium to run tests on a website. I have many individual test I need to run, and want to create a script that will run all of the python files in a certain folder. I can get the names, and import the modules, but once I do this I can't get the unittest to run the files. Here is some of the test code I have created. My problem seems to be that once I glob the names they are input as strings, and I can't get away from it.
I want to write one of these files for each folder, or some way of executing all of the folders in a directory. Here is the code I have so far:
\## This Module will execute all of the Admin>Vehicles>Add Vehicle (AVHC) Test Cases
import sys, glob, unittest
sys.path.append('/com/inthinc/python/tiwiPro/IE7/AVHC')
AddVehicle_IE7_tests = glob.glob('/com/inthinc/python/tiwipro/IE7/AVHC/*.py')
for i in range( len(AddVehicle_IE7_tests) ):
replaceme = AddVehicle_IE7_tests[i]
withoutpy = replaceme.replace( '.py', '')
withouttree1 = withoutpy.replace( '/com/inthinc/python/tiwipro/IE7/AVHC\\', '' )
exec("import " + withouttree1)
AddVehicle_IE7_tests[i] = withouttree1
sys.path.append('/com/inthinc/python/tiwiPro/FF3/AVHC')
AddVehicle_FF3_tests = glob.glob('/com/inthinc/python/tiwipro/FF3/AVHC/*.py')
for i in range( len(AddVehicle_FF3_tests) ):
replaceme = AddVehicle_FF3_tests[i]
withoutpy = replaceme.replace( '.py', '')
withouttree2 = withoutpy.replace( '/com/inthinc/python/tiwipro/FF3/AVHC\\', '' )
exec("import " + withouttree2)
print withouttree2
if __name__ == '__main__':
print AddVehicle_IE7_tests
unittest.TextTestRunner().run(AddVehicle_IE7_tests)
else:
unittest.TextTestRunner().run(AddVehicle_IE7_tests)
unittest.TextTestRunner().run(AddVehicle_FF3_tests)
print "success"