]> dev.renevier.net Git - syp.git/blob - openlayers/tests/selenium/remotecontrol/test_ol.py
fixes notices
[syp.git] / openlayers / tests / selenium / remotecontrol / test_ol.py
1 from selenium import selenium
2 import time
3 import sys
4 from ConfigParser import ConfigParser
5
6 MAX_TEST_LENGTH = 300
7 if len(sys.argv) > 2: 
8     filename = sys.argv[2]
9 else:
10     filename = "config.cfg"
11
12 c = ConfigParser()
13 c.read(filename)
14
15 targets = {}
16
17 server = c.get('config', 'server') 
18 url= c.get('config', 'url')
19 if c.has_option('config', 'timeout'):
20     MAX_TEST_LENGTH = int(c.get('config', 'timeout'))
21
22
23 sections = c.sections()
24 for s in sections:
25     if s == 'config':
26        continue
27     targets[s] = dict(c.items(s))
28     targets[s]['name'] = s
29
30 if sys.argv[1] == "all":
31     browsers = list(targets.values())
32 elif sys.argv[1] not in targets:
33     print "Invalid target"
34     sys.exit()
35 else:    
36     browsers = [targets[sys.argv[1]]]
37
38 keep_going = True
39
40 if 1:
41     for b in browsers:
42         if not keep_going: 
43             continue
44
45         print "Running %s on %s" % (b['name'], b['host']) 
46         s = selenium(b['host'], 4444, "*%s" % b['browsercmd'], server)
47         s.start()
48         try:
49             s.open_window(url, "test_running")
50             time.sleep(2)
51             s.select_window("test_running")
52             time.sleep(2)
53             s.refresh()
54             
55             count = 0
56             while count == 0: 
57                 count = int(s.get_eval("window.document.getElementById('testtable').getElementsByTagName('tr').length"))
58                 time.sleep(5)
59                 
60             ok = 0 
61             fail = 0
62             last_change = time.time()
63             while True:
64                 new_ok = int(s.get_eval('window.Test.AnotherWay._g_ok_pages'))
65                 new_fail = int(s.get_eval('window.Test.AnotherWay._g_fail_pages'))
66                 if new_ok != ok or new_fail != fail:
67                     ok = new_ok
68                     fail = new_fail
69                     last_change = time.time()
70                     
71                 if (ok + fail) >= count:
72                     break 
73                 if time.time() - last_change > MAX_TEST_LENGTH:
74                     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))      
75                 time.sleep(10)
76             
77             if fail:
78                 print "Failed: %s" % fail
79                 html = s.get_eval("window.document.getElementById('results').innerHTML").encode("utf-8")
80                 all_html = """<html>
81   <head>    
82     <meta content="text/html; charset=utf-8" http-equiv="content-type" />
83   </head>
84   <body>%s</body></html>""" % html
85
86                 f = open("fail.%s.%s.html" % (time.time(), b['name']), "w")
87                 f.write(all_html)
88                 f.close()
89         except KeyboardInterrupt, E:
90             keep_going = False
91             print "Stopped by keyboard interrupt"
92         except Exception, E:
93             print "Error: ", E
94         s.stop()
95