diff options
Diffstat (limited to 'chrome/test/pyautolib')
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 35 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.i | 4 |
2 files changed, 39 insertions, 0 deletions
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 3d9c008..8f40bdc 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -29,7 +29,9 @@ import logging import optparse import os import re +import shutil import sys +import tempfile import time import types import unittest @@ -617,6 +619,39 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): if ret_dict.has_key('error'): raise JSONInterfaceError(ret_dict['error']) + def GetTabContents(self, tab_index=0, window_index=0): + """Get the html contents of a tab (a la "view source"). + + As an implementation detail, this saves the html in a file, reads + the file into a buffer, then deletes it. + + Args: + tab_index: tab index, defaults to 0. + window_index: window index, defaults to 0. + Returns: + html content of a page as a string. + """ + tempdir = tempfile.mkdtemp() + filename = os.path.join(tempdir, 'content.html') + cmd_dict = { # Prepare command for the json interface + 'command': 'SaveTabContents', + 'tab_index': tab_index, + 'filename': filename + } + ret_dict = json.loads(self._SendJSONRequest(window_index, + json.dumps(cmd_dict))) + if ret_dict.has_key('error'): + raise JSONInterfaceError(ret_dict['error']) + try: + f = open(filename) + all_data = f.read() + f.close() + return all_data + except IOError: + raise + finally: + shutil.rmtree(tempdir) + class PyUITestSuite(pyautolib.PyUITestSuiteBase, unittest.TestSuite): """Base TestSuite for PyAuto UI tests.""" diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i index 5b3db11..1b011a2 100644 --- a/chrome/test/pyautolib/pyautolib.i +++ b/chrome/test/pyautolib/pyautolib.i @@ -93,6 +93,10 @@ class BrowserProxy { ActivateTab; bool ActivateTab(int tab_index); + %feature("docstring", "Activate the browser's window and bring it to front.") + BringToFront; + bool BringToFront(); + %feature("docstring", "Get proxy to the tab at the given zero-based index") GetTab; scoped_refptr<TabProxy> GetTab(int tab_index) const; |