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

Unified Diff: chrome/test/pyautolib/pyauto.py

Issue 2861019: Enable "get html from page" functionality for PyAuto.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/pyautolib/pyauto.py
===================================================================
--- chrome/test/pyautolib/pyauto.py (revision 50654)
+++ chrome/test/pyautolib/pyauto.py (working copy)
@@ -29,7 +29,9 @@
import optparse
import os
import re
+import shutil
import sys
+import tempfile
import time
import types
import unittest
@@ -617,7 +619,40 @@
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."""

Powered by Google App Engine
This is Rietveld 408576698