[gnome-desktop-testing] Fwd: [Merge] lp:~javier.collado/mago/firefox into lp:mago




FYI

-------- Original Message --------
Subject: [Merge] lp:~javier.collado/mago/firefox into lp:mago
Date: Thu, 08 Oct 2009 11:20:27 -0000
From: Javier Collado <javier collado canonical com>
Reply-To: mp+13060 code launchpad net
To: mp+13060 code launchpad net

Javier Collado has proposed merging lp:~javier.collado/mago/firefox into lp:mago.

    Requested reviews:
    Mago Contributors (mago-contributors)


This branch implements a few firefox test cases. More test cases are expected to be added (and merged) in the future.

Instead of creating firefox.py modules for application and test suite, the name used is mozilla.py just in case some other mozilla application test case is automated in the future.
=== added directory 'firefox'
=== added file 'firefox/firefox_init_test.py'
--- firefox/firefox_init_test.py	1970-01-01 00:00:00 +0000
+++ firefox/firefox_init_test.py	2009-10-08 11:20:26 +0000
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+import ldtp
+from mago.test_suite.mozilla import FirefoxTestSuite as BaseTestSuite
+
+class FirefoxInitTestSuite(BaseTestSuite):
+    """
+    Test cases to verify firefox initial functionality
+    """
+    def test_open_and_close(self):
+        """
+        Open and close firefox
+
+        Detailed procedure:
+         * Launch application
+         * Check that main window exist
+         * Close main window
+         * Check that main window doesn't exist
+        """
+        self.application.open()
+        self.application.close()

=== added file 'firefox/firefox_init_test.xml'
--- firefox/firefox_init_test.xml	1970-01-01 00:00:00 +0000
+++ firefox/firefox_init_test.xml	2009-10-08 11:20:26 +0000
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<suite name="Firefox Initial Test Suite">
+  <class>firefox_init_test.FirefoxInitTestSuite</class>
+  <description>
+    Test cases to verify Firefox initial functionality
+  </description>
+  <case name="Open and close">
+    <method>test_open_and_close</method>
+    <description>
+      Open and close Firefox
+    </description>
+  </case>
+</suite>

=== added file 'firefox/firefox_test.py'
--- firefox/firefox_test.py	1970-01-01 00:00:00 +0000
+++ firefox/firefox_test.py	2009-10-08 11:20:26 +0000
@@ -0,0 +1,155 @@
+#!/usr/bin/python
+import ldtp
+from mago.test_suite.mozilla import FirefoxTestSuite as BaseTestSuite
+try:
+    import lsb_release
+except ImportError:
+    import subprocess
+    lsb_release = None
+
+class FirefoxTestSuite(BaseTestSuite):
+    """
+    Test cases to verify basic firefox functionality
+    """
+    # Get Ubuntu release number either from python package or command line
+    if lsb_release:
+        release = lsb_release.get_distro_information()['RELEASE']
+    else:
+        release = subprocess.Popen(["lsb_release", "-r"],
+                                   stdout=subprocess.PIPE).communicate()[0].split()[1]
+        
+    DEFAULT_HOME_PAGE = {'chrome': 'chrome://ubufox/content/startpage.html',
+                         'http': 'http://start.ubuntu.com/%s/' % release}
+    URL = {'canonical': "http://www.canonical.com/";,
+           'ubuntu': "http://www.ubuntu.com/";,
+           }
+    TAB = {'canonical': "scpn*Canonical",
+           'ubuntu': "scpn*Ubuntu",
+           'new': "scpn(Untitled)",
+           }
+
+
+    def setup(self):
+        """
+        Open Firefox by default when suite starts
+        """
+        BaseTestSuite.setup(self)
+        self.application.open()
+
+
+    def cleanup(self):
+        BaseTestSuite.cleanup(self)
+        self.application.close()
+        # Firefox cannot be restarted immediatly
+        ldtp.wait() 
+        self.application.open()
+
+
+    def teardown(self):
+        """
+        Open firefox when test suite finishes
+        """
+        self.application.close()
+
+
+    def test_new_location(self):
+        """
+        Enter a new location and load it
+
+        Detailed procedure:
+         * Enter new URL in the location text box
+         * Wait until status bar says "Done"
+        """
+        self.application.load_page(self.URL["canonical"])
+
+
+    def test_home_page(self):
+        """
+        Update home page configuration
+
+        Detailed procedure:
+         * Load a page different than home
+         * Open preferences dialog
+         * Get home page value
+         * Press home button
+         * Verify that location text box has been correctly updated
+        """
+        self.application.load_page(self.URL["canonical"])
+        self.application.open_preferences()
+        home_page = ldtp.gettextvalue(self.application.PREFERENCES_WINDOW, 'txtHomePage')
+        assert home_page == self.DEFAULT_HOME_PAGE['chrome']
+        self.application.close_preferences()
+        self.application.go_home()
+        assert self.application.location == self.DEFAULT_HOME_PAGE['http']
+
+
+    def test_new_tab(self):
+        """
+        Open new tab
+
+        Detailed procedure:
+         * Check that there is just one tab opened
+         * Select new tab menu item
+         * Check that there are now two tabs opened
+         * Close the new tab
+         * Check that there is again just one tab opened
+        """
+        assert 1 == len(self.application.tabs)
+        self.application.open_tab()
+        self.application.load_page(self.URL['canonical'])
+        ldtp.waittillguiexist(self.application.WINDOW, self.TAB['canonical'])
+        assert 2 == len(self.application.tabs)
+        self.application.close_tab()
+        ldtp.waittillguinotexist(self.application.WINDOW, self.TAB['canonical'])
+        assert 1 == len(self.application.tabs)
+
+
+    def test_new_window(self):
+        """
+        Open new window
+
+        Detailed procedure:
+         * Check that there is just one window opened
+         * Select new window menu item
+         * Check that there are now two windows opened
+         * Close the new window
+         * Check that there is again just one window opened
+        """
+        assert 1 == len(self.application.windows)
+        self.application.load_page(self.URL['canonical'])
+        window = self.application.open_window()
+        assert 2 == len(self.application.windows)
+        self.application.close_window(window)
+        assert 1 == len(self.application.windows)
+
+
+    def test_back_forward(self):
+        """
+        Back and forward buttons
+
+        Detailed procedure:
+         * Load page 1
+         * Load page 2
+         * Press back button
+         * (Page 1 is loaded)
+         * Press forward button
+         * (Page 2 is loaded)
+        """
+        self.application.load_page(self.URL['canonical'])
+        self.application.load_page(self.URL['ubuntu'])
+        self.application.go_back()
+        assert self.application.location == self.URL['canonical']
+        self.application.go_forward()
+        assert self.application.location == self.URL['ubuntu']
+
+
+    def test_search(self):
+        """
+        Search a string
+
+        Detailed procedure:
+         * Type query string
+         * Wait until status bar says "Done"
+        """
+        ldtp.generatekeyevent('<ctrl>kubuntu<enter>')
+        ldtp.waittillguiexist(self.application.WINDOW, 'btnDone')

=== added file 'firefox/firefox_test.xml'
--- firefox/firefox_test.xml	1970-01-01 00:00:00 +0000
+++ firefox/firefox_test.xml	2009-10-08 11:20:26 +0000
@@ -0,0 +1,43 @@
+<?xml version="1.0"?>
+<suite name="Firefox Test Suite">
+  <class>firefox_test.FirefoxTestSuite</class>
+  <description>
+    Test cases to verify basic Firefox functionality
+  </description>
+  <case name="Back and forward">
+    <method>test_back_forward</method>
+    <description>
+      Back and forward buttons
+    </description>
+  </case>
+  <case name="Home page">
+    <method>test_home_page</method>
+    <description>
+      Update home page configuration
+    </description>
+  </case>
+  <case name="Enter new location">
+    <method>test_new_location</method>
+    <description>
+      Enter a new location and load it
+    </description>
+  </case>
+  <case name="New tab">
+    <method>test_new_tab</method>
+    <description>
+      Open new tab
+    </description>
+  </case>
+  <case name="New window">
+    <method>test_new_window</method>
+    <description>
+      Open new window
+    </description>
+  </case>
+  <case name="Search">
+    <method>test_search</method>
+    <description>
+      Search a string
+    </description>
+  </case>
+</suite>

=== modified file 'mago/application/__init__.py'
--- mago/application/__init__.py	2009-06-15 10:58:35 +0000
+++ mago/application/__init__.py	2009-10-08 11:20:26 +0000
@@ -3,4 +3,4 @@
 
 Classes that wrap application functionality to ease their testing
 """
-__all__ = ['main', 'gnome', 'ubuntu', 'pidgin', 'evolution']
+__all__ = ['main', 'gnome', 'ubuntu', 'pidgin', 'evolution', 'mozilla']

=== added file 'mago/application/mozilla.py'
--- mago/application/mozilla.py	1970-01-01 00:00:00 +0000
+++ mago/application/mozilla.py	2009-10-08 11:20:26 +0000
@@ -0,0 +1,179 @@
+"""
+LDTP wrappers for mozilla applications
+"""
+import os, fnmatch
+
+import ldtp
+from .main import Application
+
+class Firefox(Application):
+    """
+    Firefox web browser
+    """
+    WINDOW = "frm*MozillaFirefox*"
+    START_WINDOW = "frmUbuntuStartPage-MozillaFirefox"
+    PREFERENCES_WINDOW = "*FirefoxPreferences"
+    LAUNCHER = "firefox"
+    QUIT_DIALOG = 'dlgQuitFirefox'
+
+    def close(self):
+        """
+        Close Firefox safely (take into account close dialog)
+        """
+        self.close_window()
+#         while self.LAUNCHER in ldtp.getapplist():
+#             ldtp.wait()
+
+
+    def open_preferences(self):
+        """
+        Open preferences window
+        """
+        ldtp.click(self.WINDOW, 'mnuPreferences')
+        ldtp.waittillguiexist(self.PREFERENCES_WINDOW)
+
+
+    def close_preferences(self):
+        """
+        Close preferences window
+        """
+        ldtp.click(self.PREFERENCES_WINDOW, 'btnClose')
+        ldtp.waittillguinotexist(self.PREFERENCES_WINDOW)
+
+
+    def load_page(self, url):
+        """
+        Load a new web page for the given URL
+        """
+        # The code below isn't currently working because of a failure
+        # in Firefox. Please take a look at bug 462367
+        # in bugzilla.mozilla.org for more information
+        #ldtp.settextvalue(self.WINDOW, 'txtLocation', self.URL)
+        #assert 1 == ldtp.verifysettext(self.WINDOW, 'txtLocation', self.URL)
+        #ldtp.activatetext(self.WINDOW, 'txtLocation')
+
+        # This code is the alternate version of the previous one, but
+        # is based on the expectation that Firefox will be the
+        # application with the focus (which is something difficult to
+        # know for sure)
+        # Note: Prefix is removed from URL because it seems isn't
+        # being correctly sent by LDTP (maybe it's an escap problem)
+        short_url = url.replace('http://', '').replace('/','')
+        ldtp.generatekeyevent('<ctrl>l%s' % short_url)
+        ldtp.waittillguiexist(self.WINDOW, 'btnGo*')
+        ldtp.click(self.WINDOW, 'btnGo*')
+        ldtp.waittillguiexist(self.WINDOW, 'btnDone')
+        assert self.location == url, "%s != %s" % (self.location, url)
+
+
+    def open_tab(self):
+        """
+        Open a new tab by selecting the new tab menu
+        """
+        ldtp.click(self.WINDOW, 'mnuNewTab')
+        ldtp.waittillguiexist(self.WINDOW, 'scpn(Untitled)')
+
+
+    def close_tab(self):
+        """
+        Close a tab by selecting the close tab menu
+        """
+        ldtp.click(self.WINDOW, 'mnuCloseTab')
+
+
+    def open_window(self):
+        """
+        Open a new window by selecting new window menu
+        """
+        ldtp.click(self.WINDOW, 'mnuNewWindow')
+        ldtp.waittillguiexist(self.START_WINDOW)
+        return self.START_WINDOW
+
+
+    def close_window(self, window = None):
+        """
+        Close a window by selecting close menu
+        """
+        if len(self.windows) == 1:
+            close_menu = 'mnuQuit'
+        else:
+            objects = ldtp.getobjectlist(self.WINDOW)
+
+            if 'mnuCloseWindow' in objects: # Firefox 3.5
+                close_menu = 'mnuCloseWindow'
+            elif 'mnuClose' in objects: # Firefox 3.0
+                close_menu = 'mnuClose'
+            else:
+                raise ldtp.LdtpExecutionError('Close menu object not found')
+
+        if window is None:
+            window = self.WINDOW
+        ldtp.click(window, close_menu)
+        success = ldtp.waittillguinotexist(window, guiTimeOut=5)
+        if not success and self.QUIT_DIALOG in ldtp.getwindowlist():
+            ldtp.click(self.QUIT_DIALOG, 'btnQuit')
+            ldtp.waittillguinotexist(self.QUIT_DIALOG)
+        ldtp.waittillguinotexist(window)
+
+
+    def go_home(self):
+        """
+        Load home page
+        """
+        self._go('btnHome')
+
+
+    def go_back(self):
+        """
+        Go one step back in browsing history
+        """
+        self._go('btnBack')
+
+
+    def go_forward(self):
+        """
+        Go one step back in browsing history
+        """
+        self._go('btnForward')
+
+
+    def _go(self, button):
+        """
+        Press one button and wait for page to be loaded
+        """
+        ldtp.click(self.WINDOW, button)
+        ldtp.waittillguiexist(self.WINDOW, 'btnDone')
+
+
+    @property
+    def location(self):
+        """
+        Return current location
+        """
+        objects = ldtp.getobjectlist(self.WINDOW)
+
+        if 'txtSearchBookmarksandHistory' in objects: # Firefox 3.5
+            location = ldtp.gettextvalue(self.WINDOW, 'txtSearchBookmarksandHistory')
+        elif 'txtLocation' in objects: # Firefox 3.0
+            location = ldtp.gettextvalue(self.WINDOW, 'txtLocation')
+        else:
+            raise ldtp.LdtpExecutionError('Location object not found')
+
+        return location
+
+
+    @property
+    def tabs(self):
+        """
+        Get a list of tab controls
+        """
+        return [object for object in ldtp.getobjectlist(self.WINDOW)
+                if object.startswith('scpn')]
+
+    @property
+    def windows(self):
+        """
+        Get a list of application windows
+        """
+        return [window for window in ldtp.getwindowlist()
+                if fnmatch.fnmatch(window, self.WINDOW)]

=== modified file 'mago/test_suite/__init__.py'
--- mago/test_suite/__init__.py	2009-06-15 10:58:35 +0000
+++ mago/test_suite/__init__.py	2009-10-08 11:20:26 +0000
@@ -3,4 +3,4 @@
 
 Test suite classes that implement setup/teardown/cleanup methods
 """
-__all__ = ['main', 'gnome', 'ubuntu', 'pidgin', 'evolution']
+__all__ = ['main', 'gnome', 'ubuntu', 'pidgin', 'evolution', 'mozilla']

=== added file 'mago/test_suite/mozilla.py'
--- mago/test_suite/mozilla.py	1970-01-01 00:00:00 +0000
+++ mago/test_suite/mozilla.py	2009-10-08 11:20:26 +0000
@@ -0,0 +1,20 @@
+"""
+ubuntu module contains the definition of the test suites used for ubuntu
+applications
+"""
+import ldtp
+from .main import SingleApplicationTestSuite
+from ..application.mozilla import Firefox
+
+class FirefoxTestSuite(SingleApplicationTestSuite):
+    """
+    Base clase for firefox test suites
+    """
+    APPLICATION_FACTORY = Firefox
+
+    def setup(self):
+        """
+        Check that no Firefox instance is running
+        """
+        assert 'Firefox' not in ldtp.getapplist(), \
+            "At least one Firefox instance is already running"




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]