Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: tools/testing/dart/browser_controller.dart

Issue 2811093003: Attempt at capturing screenshot on IE if tests time out (Closed)
Patch Set: addressed comment Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/capture_screenshot.ps1 ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 library browser; 4 library browser;
5 5
6 import "dart:async"; 6 import "dart:async";
7 import "dart:convert" show UTF8, JSON; 7 import "dart:convert" show UTF8, JSON;
8 import "dart:core"; 8 import "dart:core";
9 import "dart:io"; 9 import "dart:io";
10 import "dart:math" show min; 10 import "dart:math" show min;
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 1123
1124 if (status != null && !status.timeout && status.currentTest != null) { 1124 if (status != null && !status.timeout && status.currentTest != null) {
1125 status.currentTest.timeoutTimer.cancel(); 1125 status.currentTest.timeoutTimer.cancel();
1126 status.currentTest.timeoutTimer = 1126 status.currentTest.timeoutTimer =
1127 createTimeoutTimer(status.currentTest, status); 1127 createTimeoutTimer(status.currentTest, status);
1128 status.currentTest.delayUntilTestStarted = 1128 status.currentTest.delayUntilTestStarted =
1129 status.currentTest.stopwatch.elapsed; 1129 status.currentTest.stopwatch.elapsed;
1130 } 1130 }
1131 } 1131 }
1132 1132
1133 void handleTimeout(BrowserStatus status) { 1133 Future handleTimeout(BrowserStatus status) async {
1134 // We simply kill the browser and starts up a new one! 1134 // We simply kill the browser and starts up a new one!
1135 // We could be smarter here, but it does not seems like it is worth it. 1135 // We could be smarter here, but it does not seems like it is worth it.
1136 if (status.timeout) { 1136 if (status.timeout) {
1137 DebugLogger.error("Got test timeout for an already restarting browser"); 1137 DebugLogger.error("Got test timeout for an already restarting browser");
1138 return; 1138 return;
1139 } 1139 }
1140 status.timeout = true; 1140 status.timeout = true;
1141 timedOut.add(status.currentTest.url); 1141 timedOut.add(status.currentTest.url);
1142 var id = status.browser.id; 1142 var id = status.browser.id;
1143 1143
1144 status.currentTest.stopwatch.stop(); 1144 status.currentTest.stopwatch.stop();
1145 status.browser.close().then((_) {
1146 var lastKnownMessage =
1147 'Dom could not be fetched, since the test timed out.';
1148 if (status.currentTest.lastKnownMessage.length > 0) {
1149 lastKnownMessage = status.currentTest.lastKnownMessage;
1150 }
1151 if (status.lastTest != null) {
1152 lastKnownMessage += '\nPrevious test was ${status.lastTest.url}';
1153 }
1154 // Wait until the browser is closed before reporting the test as timeout.
1155 // This will enable us to capture stdout/stderr from the browser
1156 // (which might provide us with information about what went wrong).
1157 var browserTestOutput = new BrowserTestOutput(
1158 status.currentTest.delayUntilTestStarted,
1159 status.currentTest.stopwatch.elapsed,
1160 lastKnownMessage,
1161 status.browser.testBrowserOutput,
1162 didTimeout: true);
1163 status.currentTest.doneCallback(browserTestOutput);
1164 status.lastTest = status.currentTest;
1165 status.currentTest = null;
1166 1145
1167 // We don't want to start a new browser if we are terminating. 1146 // Before closing the browser, we'll try to capture a screenshot on
1168 if (underTermination) return; 1147 // windows when using IE (to debug flakiness).
1169 removeBrowser(id); 1148 if (status.browser is IE) {
1170 requestBrowser(); 1149 await captureInternetExplorerScreenshot(
1171 }); 1150 'IE screenshot for ${status.currentTest.url}');
1151 }
1152 await status.browser.close();
1153 var lastKnownMessage =
1154 'Dom could not be fetched, since the test timed out.';
1155 if (status.currentTest.lastKnownMessage.length > 0) {
1156 lastKnownMessage = status.currentTest.lastKnownMessage;
1157 }
1158 if (status.lastTest != null) {
1159 lastKnownMessage += '\nPrevious test was ${status.lastTest.url}';
1160 }
1161 // Wait until the browser is closed before reporting the test as timeout.
1162 // This will enable us to capture stdout/stderr from the browser
1163 // (which might provide us with information about what went wrong).
1164 var browserTestOutput = new BrowserTestOutput(
1165 status.currentTest.delayUntilTestStarted,
1166 status.currentTest.stopwatch.elapsed,
1167 lastKnownMessage,
1168 status.browser.testBrowserOutput,
1169 didTimeout: true);
1170 status.currentTest.doneCallback(browserTestOutput);
1171 status.lastTest = status.currentTest;
1172 status.currentTest = null;
1173
1174 // We don't want to start a new browser if we are terminating.
1175 if (underTermination) return;
1176 removeBrowser(id);
1177 requestBrowser();
1172 } 1178 }
1173 1179
1174 /// Remove a browser that has closed from our data structures that track 1180 /// Remove a browser that has closed from our data structures that track
1175 /// open browsers. Check if we want to replace it with a new browser. 1181 /// open browsers. Check if we want to replace it with a new browser.
1176 void removeBrowser(String id) { 1182 void removeBrowser(String id) {
1177 if (browserName == 'chromeOnAndroid') { 1183 if (browserName == 'chromeOnAndroid') {
1178 idleAdbDevices.add(adbDeviceMapping.remove(id)); 1184 idleAdbDevices.add(adbDeviceMapping.remove(id));
1179 } 1185 }
1180 markNotCurrentlyStarting(id); 1186 markNotCurrentlyStarting(id);
1181 browserStatus.remove(id); 1187 browserStatus.remove(id);
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 </div> 1883 </div>
1878 <div id="embedded_iframe_div" class="test box"> 1884 <div id="embedded_iframe_div" class="test box">
1879 <iframe id="embedded_iframe"></iframe> 1885 <iframe id="embedded_iframe"></iframe>
1880 </div> 1886 </div>
1881 </body> 1887 </body>
1882 </html> 1888 </html>
1883 """; 1889 """;
1884 return driverContent; 1890 return driverContent;
1885 } 1891 }
1886 } 1892 }
1893
1894 Future captureInternetExplorerScreenshot(String message) async {
1895 if (Platform.environment['USERNAME'] != 'chrome-bot') {
1896 return;
1897 }
1898
1899 print('--------------------------------------------------------------------');
1900 final String date =
1901 new DateTime.now().toUtc().toIso8601String().replaceAll(':', '_');
1902 final screenshotName = 'ie_screenshot_${date}.png';
1903
1904 // The "capture_screen.ps1" script is next to "test.dart" in "tools/"
1905 final powerShellScript =
1906 Platform.script.resolve('capture_screenshot.ps1').toFilePath();
1907 final screenshotFile =
1908 Platform.script.resolve('../$screenshotName').toFilePath();
1909
1910 final args = [powerShellScript, screenshotFile];
1911 final ProcessResult result =
1912 await Process.run('powershell.exe', args, runInShell: true);
1913 if (result.exitCode != 0) {
1914 print('[$message] Failed to capture IE screenshot on windows: '
1915 'powershell.exe "${args.join(' ')}" returned with:\n'
1916 'exit code: ${result.exitCode}\n'
1917 'stdout: ${result.stdout}\n'
1918 'stderr: ${result.stderr}');
1919 } else {
1920 final storageUrl = 'gs://dart-temp-crash-archive/$screenshotName';
1921 final args = [
1922 r'e:\b\depot_tools\gsutil.py',
1923 'cp',
1924 screenshotFile,
1925 storageUrl,
1926 ];
1927 final ProcessResult result = await Process.run('python', args);
1928 if (result.exitCode != 0) {
1929 print('[$message] Failed upload captured IE screenshot to cloud storage: '
1930 '"${args.join(' ')}" returned with:\n'
1931 'exit code: ${result.exitCode}\n'
1932 'stdout: ${result.stdout}\n'
1933 'stderr: ${result.stderr}');
1934 } else {
1935 print('[$message] Successfully uploaded screenshot to $storageUrl');
1936 }
1937 new File(screenshotFile).deleteSync();
1938 }
1939 print('--------------------------------------------------------------------');
1940 }
OLDNEW
« no previous file with comments | « tools/capture_screenshot.ps1 ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698