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

Side by Side Diff: pyautolib/pyauto_utils.py

Issue 10384104: Chrome updater test framework (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/test/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
« install_test/chrome_installer.py ('K') | « pyautolib/pyauto.py ('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) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Utilities for PyAuto.""" 5 """Utilities for PyAuto."""
6 6
7 import logging 7 import logging
8 import os 8 import os
9 import shutil 9 import shutil
10 import sys 10 import sys
11 import tempfile 11 import tempfile
12 import unittest
12 import zipfile 13 import zipfile
13 14
14 15
15 class ExistingPathReplacer(object): 16 class ExistingPathReplacer(object):
16 """Facilitates backing up a given path (file or dir).. 17 """Facilitates backing up a given path (file or dir)..
17 18
18 Often you want to manipulate a directory or file for testing but don't want to 19 Often you want to manipulate a directory or file for testing but don't want to
19 meddle with the existing contents. This class lets you make a backup, and 20 meddle with the existing contents. This class lets you make a backup, and
20 reinstate the backup when done. A backup is made in an adjacent directory, 21 reinstate the backup when done. A backup is made in an adjacent directory,
21 so you need to make sure you have write permissions to the parent directory. 22 so you need to make sure you have write permissions to the parent directory.
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 Args: 185 Args:
185 pyauto: an instance of pyauto.PyUITest. 186 pyauto: an instance of pyauto.PyUITest.
186 driver: an instance of chrome driver or a web element. 187 driver: an instance of chrome driver or a web element.
187 xpath: the xpath of the element to wait for. 188 xpath: the xpath of the element to wait for.
188 189
189 Returns: 190 Returns:
190 The element if it is found. 191 The element if it is found.
191 NoSuchElementException if it is not found. 192 NoSuchElementException if it is not found.
192 """ 193 """
193 pyauto.WaitUntil(lambda: len(driver.find_elements_by_xpath(xpath)) > 0) 194 pyauto.WaitUntil(lambda: len(driver.find_elements_by_xpath(xpath)) > 0)
194 return driver.find_element_by_xpath(xpath) 195 return driver.find_element_by_xpath(xpath)
196
197
198 class _GTestTextTestResult(unittest._TextTestResult):
199 """A test result class that can print formatted text results to a stream.
200
201 Results printed in conformance with gtest output format, like:
202 [ RUN ] autofill.AutofillTest.testAutofillInvalid: "test desc."
203 [ OK ] autofill.AutofillTest.testAutofillInvalid
204 [ RUN ] autofill.AutofillTest.testFillProfile: "test desc."
205 [ OK ] autofill.AutofillTest.testFillProfile
206 [ RUN ] autofill.AutofillTest.testFillProfileCrazyCharacters: "Test."
207 [ OK ] autofill.AutofillTest.testFillProfileCrazyCharacters
208 """
209
210 def __init__(self, stream, descriptions, verbosity):
211 unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
212
213 def _GetTestURI(self, test):
214 if sys.version_info[:2] <= (2, 4):
215 return '%s.%s' % (unittest._strclass(test.__class__),
216 test._TestCase__testMethodName)
217 return '%s.%s' % (unittest._strclass(test.__class__), test._testMethodName)
218
219 def getDescription(self, test):
220 return '%s: "%s"' % (self._GetTestURI(test), test.shortDescription())
221
222 def startTest(self, test):
223 unittest.TestResult.startTest(self, test)
224 self.stream.writeln('[ RUN ] %s' % self.getDescription(test))
225
226 def addSuccess(self, test):
227 unittest.TestResult.addSuccess(self, test)
228 self.stream.writeln('[ OK ] %s' % self._GetTestURI(test))
229
230 def addError(self, test, err):
231 unittest.TestResult.addError(self, test, err)
232 self.stream.writeln('[ ERROR ] %s' % self._GetTestURI(test))
233
234 def addFailure(self, test, err):
235 unittest.TestResult.addFailure(self, test, err)
236 self.stream.writeln('[ FAILED ] %s' % self._GetTestURI(test))
237
238
239 class GTestTextTestRunner(unittest.TextTestRunner):
240 """Test Runner for displaying test results in textual format.
241
242 Results are displayed in conformance with gtest output.
243 """
244
245 def __init__(self, verbosity=1):
246 unittest.TextTestRunner.__init__(self, stream=sys.stderr,
247 verbosity=verbosity)
248
249 def _makeResult(self):
250 return _GTestTextTestResult(self.stream, self.descriptions, self.verbosity)
OLDNEW
« install_test/chrome_installer.py ('K') | « pyautolib/pyauto.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698