diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-09 18:26:23 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-09 18:26:23 +0000 |
commit | 76bb9c355cc9d34bc3d489125d9764598d533289 (patch) | |
tree | c5f2c9aabc98d2e024ce1e1f537b972a7044b131 /chrome/test/pyautolib | |
parent | 5da7c2d76833bb8d1580a8c3e09849a876fea65d (diff) | |
download | chromium_src-76bb9c355cc9d34bc3d489125d9764598d533289.zip chromium_src-76bb9c355cc9d34bc3d489125d9764598d533289.tar.gz chromium_src-76bb9c355cc9d34bc3d489125d9764598d533289.tar.bz2 |
Provide a method to specify to the automation interface the dir containing browser binaries
Problem:
The automation proxy interface kinda assumes that the running binary would
reside in the same directory as the browser binaries -- ie in Debug/Release
dirs. While this works for all C++ binaries like ui_tests, startup_tests,
this fails for pyauto tests since the running binary in this case is
/usr/bin/python (or some such system path).
This changeset lets pyauto explicitly specify the automation interface the
dir in which to look for chromium binaries.
Also, expose RunCommand method to pyauto.
BUG=37730
TEST=pyauto scripts should work without having to copy python to Debug/Release dirs
Review URL: http://codereview.chromium.org/695001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41051 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/pyautolib')
-rw-r--r-- | chrome/test/pyautolib/pyauto.py | 12 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.cc | 17 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.h | 7 | ||||
-rw-r--r-- | chrome/test/pyautolib/pyautolib.i | 7 |
4 files changed, 37 insertions, 6 deletions
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py index 4fee17c..636552a 100644 --- a/chrome/test/pyautolib/pyauto.py +++ b/chrome/test/pyautolib/pyauto.py @@ -39,13 +39,13 @@ def _LocateBinDirs(): _LocateBinDirs() try: - from pyautolib import * + import pyautolib except ImportError: print >>sys.stderr, "Could not locate built libraries. Did you build?" raise -class PyUITest(PyUITestSuite, unittest.TestCase): +class PyUITest(pyautolib.PyUITestSuite, unittest.TestCase): """Base class for UI Test Cases in Python. A browser is created before executing each test, and is destroyed after @@ -64,11 +64,15 @@ class PyUITest(PyUITestSuite, unittest.TestCase): """ def __init__(self, methodName='runTest'): - PyUITestSuite.__init__(self, sys.argv) + pyautolib.PyUITestSuite.__init__(self, sys.argv) + # Figure out path to chromium binaries + browser_dir = os.path.normpath(os.path.dirname(pyautolib.__file__)) + os.environ['PATH'] = browser_dir + os.pathsep + os.environ['PATH'] + self.Initialize(pyautolib.FilePath(browser_dir)) unittest.TestCase.__init__(self, methodName) def __del__(self): - PyUITestSuite.__del__(self) + pyautolib.PyUITestSuite.__del__(self) def run(self, result=None): """The main run method. diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc index 5ebfe0f..b9090e4 100644 --- a/chrome/test/pyautolib/pyautolib.cc +++ b/chrome/test/pyautolib/pyautolib.cc @@ -10,13 +10,18 @@ PyUITestSuite::PyUITestSuite(int argc, char** argv) : UITestSuite(argc, argv), UITestBase() { - UITestSuite::Initialize(); } PyUITestSuite::~PyUITestSuite() { UITestSuite::Shutdown(); } +void PyUITestSuite::Initialize(const FilePath& browser_dir) { + UITestSuite::SetBrowserDirectory(browser_dir); + UITestBase::SetBrowserDirectory(browser_dir); + UITestSuite::Initialize(); +} + void PyUITestSuite::SetUp() { UITestBase::SetUp(); } @@ -48,6 +53,15 @@ bool PyUITestSuite::ApplyAccelerator(int id, int window_index) { return browser_proxy->ApplyAccelerator(id); } +bool PyUITestSuite::RunCommand(int browser_command, int window_index){ + scoped_refptr<BrowserProxy> browser_proxy = + automation()->GetBrowserWindow(window_index); + EXPECT_TRUE(browser_proxy.get()); + if (!browser_proxy.get()) + return false; + return browser_proxy->RunCommand(browser_command); +} + bool PyUITestSuite::ActivateTab(int tab_index, int window_index) { scoped_refptr<BrowserProxy> browser_proxy = automation()->GetBrowserWindow(window_index); @@ -144,4 +158,3 @@ bool PyUITestSuite::WaitForBookmarkBarVisibilityChange(bool wait_for_open) { return completed; } - diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h index aab4dce..461834a 100644 --- a/chrome/test/pyautolib/pyautolib.h +++ b/chrome/test/pyautolib/pyautolib.h @@ -30,6 +30,10 @@ class PyUITestSuite : public UITestSuite, public UITestBase { PyUITestSuite(int argc, char** argv); ~PyUITestSuite(); + // Initialize the setup. Should be called before launching the browser. + // |browser_dir| is the path to dir containing chromium binaries. + void Initialize(const FilePath& browser_dir); + // SetUp,TearDown is redeclared as public to make it accessible from swig. virtual void SetUp(); virtual void TearDown(); @@ -59,6 +63,9 @@ class PyUITestSuite : public UITestSuite, public UITestBase { // Returns true if the call was successful. bool ApplyAccelerator(int id, int window_index = 0); + // Like ApplyAccelerator except that it waits for the command to execute. + bool RunCommand(int browser_command, int window_index = 0); + // Shows or hides the download shelf. void SetDownloadShelfVisible(bool is_visible, int window_index = 0); diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i index 28aa983..f1a01f1 100644 --- a/chrome/test/pyautolib/pyautolib.i +++ b/chrome/test/pyautolib/pyautolib.i @@ -81,6 +81,10 @@ class PyUITestSuite { public: PyUITestSuite(int argc, char** argv); + %feature("docstring", "Initialize the entire setup. Should be called " + "before launching the browser. For internal use.") Initialize; + void Initialize(const FilePath& browser_dir); + %feature("docstring", "Fires up the browser and opens a window.") SetUp; virtual void SetUp(); @@ -106,6 +110,9 @@ class PyUITestSuite { "Returns True on success.") ApplyAccelerator; bool ApplyAccelerator(int id, int window_index=0); + %feature("docstring", "Like ApplyAccelerator, except that it waits for " + "the command to execute.") RunCommand; + bool RunCommand(int browser_command, int window_index = 0); // Get/fetch properties %feature("docstring", |