Go to the documentation of this file.00001 from selenium import selenium
00002 import time
00003 import sys
00004 from ConfigParser import ConfigParser
00005
00006 MAX_TEST_LENGTH = 300
00007 if len(sys.argv) > 2:
00008 filename = sys.argv[2]
00009 else:
00010 filename = "config.cfg"
00011
00012 c = ConfigParser()
00013 c.read(filename)
00014
00015 targets = {}
00016
00017 server = c.get('config', 'server')
00018 url= c.get('config', 'url')
00019 if c.has_option('config', 'timeout'):
00020 MAX_TEST_LENGTH = int(c.get('config', 'timeout'))
00021
00022
00023 sections = c.sections()
00024 for s in sections:
00025 if s == 'config':
00026 continue
00027 targets[s] = dict(c.items(s))
00028 targets[s]['name'] = s
00029
00030 if sys.argv[1] == "all":
00031 browsers = list(targets.values())
00032 elif sys.argv[1] not in targets:
00033 print "Invalid target"
00034 sys.exit()
00035 else:
00036 browsers = [targets[sys.argv[1]]]
00037
00038 keep_going = True
00039
00040 if 1:
00041 for b in browsers:
00042 if not keep_going:
00043 continue
00044
00045 print "Running %s on %s" % (b['name'], b['host'])
00046 s = selenium(b['host'], 4444, "*%s" % b['browsercmd'], server)
00047 s.start()
00048 try:
00049 s.open_window(url, "test_running")
00050 time.sleep(2)
00051 s.select_window("test_running")
00052 time.sleep(2)
00053 s.refresh()
00054
00055 count = 0
00056 while count == 0:
00057 count = int(s.get_eval("window.document.getElementById('testtable').getElementsByTagName('tr').length"))
00058 time.sleep(5)
00059
00060 ok = 0
00061 fail = 0
00062 last_change = time.time()
00063 while True:
00064 new_ok = int(s.get_eval('window.Test.AnotherWay._g_ok_pages'))
00065 new_fail = int(s.get_eval('window.Test.AnotherWay._g_fail_pages'))
00066 if new_ok != ok or new_fail != fail:
00067 ok = new_ok
00068 fail = new_fail
00069 last_change = time.time()
00070
00071 if (ok + fail) >= count:
00072 break
00073 if time.time() - last_change > MAX_TEST_LENGTH:
00074 raise Exception("Failed: with %s okay and %s failed, ran out of time: %s is more than %s" % (ok, fail, (time.time() - last_change), MAX_TEST_LENGTH))
00075 time.sleep(10)
00076
00077 if fail:
00078 print "Failed: %s" % fail
00079 html = s.get_eval("window.document.getElementById('results').innerHTML").encode("utf-8")
00080 all_html = """<html>
00081 <head>
00082 <meta content="text/html; charset=utf-8" http-equiv="content-type" />
00083 </head>
00084 <body>%s</body></html>""" % html
00085
00086 f = open("fail.%s.%s.html" % (time.time(), b['name']), "w")
00087 f.write(all_html)
00088 f.close()
00089 except KeyboardInterrupt, E:
00090 keep_going = False
00091 print "Stopped by keyboard interrupt"
00092 except Exception, E:
00093 print "Error: ", E
00094 s.stop()
00095