OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 # | 6 # |
7 | 7 |
8 """Script to actually open a browser and perform the test, and reports back with | 8 """Script to actually open a browser and perform the test, and reports back with |
9 the result. | 9 the result. |
10 """ | 10 """ |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 def parse_args(): | 85 def parse_args(): |
86 parser = optparse.OptionParser() | 86 parser = optparse.OptionParser() |
87 parser.add_option('--out', dest='out', | 87 parser.add_option('--out', dest='out', |
88 help = 'The path for html output file that we will running our test from',
| 88 help = 'The path for html output file that we will running our test from',
|
89 action = 'store', default = '') | 89 action = 'store', default = '') |
90 parser.add_option('--browser', dest='browser', | 90 parser.add_option('--browser', dest='browser', |
91 help = 'The browser type (default = chrome)', | 91 help = 'The browser type (default = chrome)', |
92 action = 'store', default = 'chrome') | 92 action = 'store', default = 'chrome') |
93 parser.add_option('--timeout', dest = 'timeout', | 93 parser.add_option('--timeout', dest = 'timeout', |
94 help = 'Amount of time (seconds) to wait before timeout', type = 'int', | 94 help = 'Amount of time (seconds) to wait before timeout', type = 'int', |
95 action = 'store', default=10) | 95 action = 'store', default=40) |
96 parser.add_option('--perf', dest = 'is_perf', | 96 parser.add_option('--perf', dest = 'is_perf', |
97 help = 'Add this flag if we are running a browser performance test', | 97 help = 'Add this flag if we are running a browser performance test', |
98 action = 'store_true', default=False) | 98 action = 'store_true', default=False) |
99 args, ignored = parser.parse_args() | 99 args, ignored = parser.parse_args() |
100 return args.out, args.browser, args.timeout, args.is_perf | 100 return args.out, args.browser, args.timeout, args.is_perf |
101 | 101 |
102 def Main(): | 102 def Main(): |
103 # Note: you need ChromeDriver *in your path* to run Chrome, in addition to | 103 # Note: you need ChromeDriver *in your path* to run Chrome, in addition to |
104 # installing Chrome. | 104 # installing Chrome. |
105 browser = None | 105 browser = None |
106 html_out, browser, timeout, is_perf = parse_args() | 106 html_out, browser, timeout, is_perf = parse_args() |
107 | 107 |
108 if browser == 'chrome': | 108 if browser == 'chrome': |
109 browser = selenium.webdriver.Chrome() | 109 browser = selenium.webdriver.Chrome() |
110 elif browser == 'ff': | 110 elif browser == 'ff': |
111 browser = selenium.webdriver.Firefox() | 111 browser = selenium.webdriver.Firefox() |
112 elif browser == 'ie' and platform.system() == 'Windows': | 112 elif browser == 'ie' and platform.system() == 'Windows': |
113 browser = selenium.webdriver.Ie() | 113 browser = selenium.webdriver.Ie() |
114 elif browser == 'safari' and platform.system() == 'Darwin': | 114 elif browser == 'safari' and platform.system() == 'Darwin': |
115 # TODO(efortuna): Ensure our preferences (no pop-up blocking) file is the | 115 # TODO(efortuna): Ensure our preferences (no pop-up blocking) file is the |
116 # same (Safari auto-deletes when it has too many "crashes," or in our case, | 116 # same (Safari auto-deletes when it has too many "crashes," or in our case, |
117 # timeouts). Come up with a less hacky way to do this. | 117 # timeouts). Come up with a less hacky way to do this. |
118 shutil.copy(os.path.dirname(__file__) + '/com.apple.Safari.plist', | 118 shutil.copy(os.path.dirname(__file__) + '/com.apple.Safari.plist', |
119 '/Library/Preferences/com.apple.Safari.plist') | 119 '/Library/Preferences/com.apple.Safari.plist') |
120 sel = selenium.selenium('localhost', 4444, "*safari", 'file://' + html_out) | 120 sel = selenium.selenium('localhost', 4444, "*safari", 'file://' + html_out) |
121 try: | 121 try: |
(...skipping 12 matching lines...) Expand all Loading... |
134 source = run_test_in_browser(browser, html_out, timeout, is_perf) | 134 source = run_test_in_browser(browser, html_out, timeout, is_perf) |
135 | 135 |
136 if is_perf: | 136 if is_perf: |
137 # We're running a performance test. | 137 # We're running a performance test. |
138 print source | 138 print source |
139 if 'NaN' in source: | 139 if 'NaN' in source: |
140 return 1 | 140 return 1 |
141 else: | 141 else: |
142 return 0 | 142 return 0 |
143 else: | 143 else: |
144 # We're running a correctness test. | 144 # We're running a correctness test. Mark test as passing if all individual |
145 if ('PASS' in source): | 145 # test cases pass. |
| 146 if 'FAIL' not in source and 'PASS' in source: |
146 print 'Content-Type: text/plain\nPASS' | 147 print 'Content-Type: text/plain\nPASS' |
147 return 0 | 148 return 0 |
148 else: | 149 else: |
149 #The hacky way to get document.getElementById('body').innerHTML for this | 150 #The hacky way to get document.getElementById('body').innerHTML for this |
150 # webpage, without the JavaScript. | 151 # webpage, without the JavaScript. |
151 #TODO(efortuna): Access these elements in a nicer way using DOM parser. | 152 #TODO(efortuna): Access these elements in a nicer way using DOM parser. |
152 index = source.find('<body>') | 153 index = source.find('<body>') |
153 index += len('<body>') | 154 index += len('<body>') |
154 end_index = source.find('<script') | 155 end_index = source.find('<script') |
155 print source[index : end_index] | 156 print source[index : end_index] |
156 return 1 | 157 return 1 |
157 | 158 |
158 | 159 |
159 if __name__ == "__main__": | 160 if __name__ == "__main__": |
160 sys.exit(Main()) | 161 sys.exit(Main()) |
OLD | NEW |