Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Runs DomDistillers jstests. | 6 """Runs DomDistillers jstests. |
| 7 | 7 |
| 8 This uses ChromeDriver (https://sites.google.com/a/chromium.org/chromedriver/) t o run the jstests. | 8 This uses ChromeDriver (https://sites.google.com/a/chromium.org/chromedriver/) t o run the jstests. |
| 9 This requires that the ChromeDriver executable is on the PATH and that Selenium WebDriver is | 9 This requires that the ChromeDriver executable is on the PATH and that Selenium WebDriver is |
| 10 installed. | 10 installed. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 |
| 43 if options.debug_level: | 43 if options.debug_level: |
| 44 params['debug_level'] = int(options.debug_level) | 44 params['debug_level'] = int(options.debug_level) |
| 45 | 45 |
| 46 if options.no_console_log: | 46 if options.no_console_log: |
| 47 params['console_log'] = '0' | 47 params['console_log'] = '0' |
| 48 | 48 |
| 49 if options.shuffle: | 49 if options.shuffle: |
| 50 params['shuffle'] = options.shuffle | 50 params['shuffle'] = options.shuffle |
| 51 | 51 |
| 52 test_runner = "return org.chromium.distiller.JsTestEntry.run()"; | 52 image_loaded = "return window.image_loaded" |
| 53 test_runner = "return org.chromium.distiller.JsTestEntry.run()" | |
| 53 test_html = os.path.abspath(os.path.join(os.path.dirname(__file__), "war", "te st.html")) | 54 test_html = os.path.abspath(os.path.join(os.path.dirname(__file__), "war", "te st.html")) |
| 54 test_html += "?" + urllib.urlencode(params) | 55 test_html += "?" + urllib.urlencode(params) |
| 55 | 56 |
| 56 chrome_options = webdriver.ChromeOptions() | 57 chrome_options = webdriver.ChromeOptions() |
| 57 | 58 |
| 58 # Travis-CI uses OpenVZ containers which are incompatible with the sandbox tec hnology. | 59 # Travis-CI uses OpenVZ containers which are incompatible with the sandbox tec hnology. |
| 59 # See https://code.google.com/p/chromium/issues/detail?id=31077 for more infor mation. | 60 # See https://code.google.com/p/chromium/issues/detail?id=31077 for more infor mation. |
| 60 # Ref: https://github.com/travis-ci/travis-ci/issues/938#issuecomment-16336150 | 61 # Ref: https://github.com/travis-ci/travis-ci/issues/938#issuecomment-16336150 |
| 61 # Drone.io also has issues running newer versions of Chrome. | 62 # Drone.io also has issues running newer versions of Chrome. |
| 62 # Ref: http://crbug.com/495254 | 63 # Ref: http://crbug.com/495254 |
| 63 if options.no_sandbox: | 64 if options.no_sandbox: |
| 64 chrome_options.add_argument("--no-sandbox") | 65 chrome_options.add_argument("--no-sandbox") |
| 65 | 66 |
| 66 driver = webdriver.Chrome(chrome_options=chrome_options) | 67 driver = webdriver.Chrome(chrome_options=chrome_options) |
| 67 driver.get("file://" + test_html) | |
| 68 for i in range(options.repeat): | 68 for i in range(options.repeat): |
| 69 driver.get("file://" + test_html) | |
| 70 while not driver.execute_script(image_loaded): | |
|
mdjones
2017/03/22 17:35:04
I'd check to see if there is a execute-and-wait ve
wychen
2017/04/11 00:22:55
I gave selenium.webdriver.support.expected_conditi
| |
| 71 print "Wait for image loading..." | |
| 72 time.sleep(0.1) | |
| 73 | |
| 69 start = time.time() | 74 start = time.time() |
| 70 result = driver.execute_script(test_runner) | 75 result = driver.execute_script(test_runner) |
| 76 end = time.time() | |
| 71 | 77 |
| 72 end = time.time() | |
| 73 if not result['success'] or options.repeat == i+1: | 78 if not result['success'] or options.repeat == i+1: |
| 74 print result['log'].encode('utf-8') | 79 print result['log'].encode('utf-8') |
| 75 print 'Tests run: %d, Failures: %d, Skipped: %d, Time elapsed: %0.3f sec' % (result['numTests'], | 80 print 'Tests run: %d, Failures: %d, Skipped: %d, Time elapsed: %0.3f sec' % (result['numTests'], |
| 76 result['failed'], result['skipped'], end - start) | 81 result['failed'], result['skipped'], end - start) |
| 77 if not result['success']: | 82 if not result['success']: |
| 78 driver.quit() | 83 driver.quit() |
| 79 if options.repeat > 1: | 84 if options.repeat > 1: |
| 80 print 'Failed at run #%d/%d' % (i+1, options.repeat) | 85 print 'Failed at run #%d/%d' % (i+1, options.repeat) |
| 81 return 1 | 86 return 1 |
| 82 driver.quit() | 87 driver.quit() |
| 83 if options.repeat > 1: | 88 if options.repeat > 1: |
| 84 print 'Passed %d runs' % (options.repeat) | 89 print 'Passed %d runs' % (options.repeat) |
| 85 return 0 | 90 return 0 |
| 86 | 91 |
| 87 if __name__ == '__main__': | 92 if __name__ == '__main__': |
| 88 sys.exit(main(sys.argv[1:])) | 93 sys.exit(main(sys.argv[1:])) |
| 89 | 94 |
| OLD | NEW |