[gnome-desktop-testing] a patch enhance the gedit module in gnome.py



Hi all,
   For writing a more detailed test suite for gedit under the framework of
desktoptesting, I did some changes in gnome.py for the gedit part.

  With the patch you could check some UI menus and do "Undo", "Redo"
operations using desktoptesting.gnome.

  Could someone review it please and tell me whether it is the right way?

I also want to ask whether it is encouraged to use ldtp based calls in the testsuite without rewriting the framework(ldtp.log for example). I would like
to do some refinements of my gedit test cases and send it out for review.

  Thanks for your help ,


tac

--
----------------------------------------------
tac @ Sun China
     junyuan tan sun com
extn: +86-10-62673641 intn: 51641
----------------------------------------------

Index: desktoptesting/gnome.py
===================================================================
--- desktoptesting/gnome.py	(revision 10)
+++ desktoptesting/gnome.py	(working copy)
@@ -78,7 +78,14 @@
         It reloads the application map for the given ooldtp.context.
         """
         ldtp.remap(self.name)
+   
+    def open_with_file(self, filename):
+        """
+        Open gedit with a filename
+        """
+        ldtp.launchapp(self.LAUNCHER, [filename,])
 
+
     def open_and_check_app(self):
         """
         Given an application, it tries to open it.
@@ -155,7 +162,28 @@
             except ldtp.LdtpExecutionError:
                 raise ldtp.LdtpExecutionError, "We couldn't write text."
 
+    def append_text(self, text, txt_field=''):
+        """
+        Given an application it tries to append text to its current buffer.
+        """
+        app = ooldtp.context(self.name)
 
+        if txt_field == '':
+            try:
+                ldtp.enterstring(text)
+            except ldtp.LdtpExecutionError:
+                raise ldtp.LdtpExecutionError, "We couldn't append text."
+        else:
+            try:
+                app_txt_field = app.getchild(txt_field)
+            except ldtp.LdtpExecutionError:
+                raise ldtp.LdtpExecutionError, "The " + txt_field + " text field was not found."
+            try:
+                app_txt_field.appendtext(text)
+            except ldtp.LdtpExecutionError:
+                raise ldtp.LdtpExecutionError, "We couldn't append text."
+
+
 class Seahorse(Application):
     """
     Seahorse manages the Seahorse application.
@@ -513,7 +541,7 @@
     """
     GEdit manages the Gedit application.
     """
-    WINDOW     = "frm*gedit"
+    WINDOW     = "frm*-gedit"
     TXT_FIELD  = "txt1"
     LAUNCHER   = "gedit"
     SAVE_DLG   = "dlgSave*"
@@ -526,6 +554,9 @@
     MNU_QUIT = "mnuQuit"
     MNU_CLOSE = "mnuClose"
     MNU_NEW = "mnuNew"
+    MNU_UNDO = "mnuUndo"
+    MNU_REDO = "mnuRedo"
+    MNU_SAVE = "mnuSave"
 
     def __init__(self):
         Application.__init__(self)
@@ -568,7 +599,27 @@
         if result != 1:
             raise ldtp.LdtpExecutionError, "Failed to set up new document."
         
+    def check_menu(self, mnuName):
 
+        menuName = "mnu" + mnuName
+
+        try:
+            gedit = ooldtp.context(self.name)
+            menuitem = gedit.getchild(menuName)
+        except ldtp.LdtpExecutionError:
+            raise ldtp.LdtpExecutionError, "menu was not found."
+        # test this menu UI 
+        try:
+            menuitem.selectmenuitem()
+
+            if not ldtp.waittillguiexist("dlg*" + mnuName + "*"):
+                raise ldtp.LdtpExecutionError, "mnuName was not invoked."
+            else:
+                menudialog = ooldtp.context("dlg*" + mnuName + "*")
+                menudialog.click('btnClose')
+        except ldtp.LdtpExecutionError:
+            raise ldtp.LdtpExecutionError, "mnuName check failed." 
+
     def write_text(self, text):
         """
         It writes text to the current buffer of the Gedit window.
@@ -578,8 +629,17 @@
         """
         Application.write_text(self, text, self.TXT_FIELD)
 
-    def save(self, filename):
+    def append_text(self, text):
         """
+        It appends text to the current buffer of the Gedit window.
+
+        @type text: string
+        @param text: The text string to be written to the current buffer.
+        """
+        Application.append_text(self, text, self.TXT_FIELD)
+
+    def save(self, filename, new):
+        """
         It tries to save the current opened buffer to the filename passed as parameter.
 
         TODO: It does not manage the overwrite dialog yet.
@@ -588,34 +648,63 @@
         @param filename: The name of the file to save the buffer to.
         """
         Application.save(self)
-        ooldtp.context(self.name)
+        gedit = ooldtp.context(self.name)
+        if new == 1:
+            try:
+                ldtp.waittillguiexist(self.SAVE_DLG)
+                save_dialog = ooldtp.context(self.SAVE_DLG)
+            except ldtp.LdtpExecutionError:
+                raise ldtp.LdtpExecutionError, "The Gedit save dialog was not found."
+            try:
+                save_dlg_txt_filename = save_dialog.getchild(self.SAVE_DLG_TXT_NAME)
+            except ldtp.LdtpExecutionError:
+                raise ldtp.LdtpExecutionError, "The filename txt field in Gedit save dialog was not found."
+            try:
+                ldtp.wait(2)
+                save_dlg_txt_filename.settextvalue(filename)
+            except ldtp.LdtpExecutionError:
+                raise ldtp.LdtpExecutionError, "We couldn't write text."
 
-        try:
-            ldtp.waittillguiexist(self.SAVE_DLG)
-            save_dialog = ooldtp.context(self.SAVE_DLG)
-        except ldtp.LdtpExecutionError:
-            raise ldtp.LdtpExecutionError, "The Gedit save dialog was not found."
-        try:
-            save_dlg_txt_filename = save_dialog.getchild(self.SAVE_DLG_TXT_NAME)
-        except ldtp.LdtpExecutionError:
-            raise ldtp.LdtpExecutionError, "The filename txt field in Gedit save dialog was not found."
-        try:
-            ldtp.wait(2)
-            save_dlg_txt_filename.settextvalue(filename)
-        except ldtp.LdtpExecutionError:
-           raise ldtp.LdtpExecutionError, "We couldn't write text."
+            try:
+                save_dlg_btn_save = save_dialog.getchild(self.SAVE_DLG_BTN_SAVE)
+            except ldtp.LdtpExecutionError:
+                raise ldtp.LdtpExecutionError, "The button Save in Gedit save dialog was not found."
+        
+            try:
+                save_dlg_btn_save.click()
+            except ldtp.LdtpExecutionError:
+                raise ldtp.LdtpExecutionError, "There was an error when pushing the Save button."
 
+            ldtp.waittillguinotexist(self.SAVE_DLG)
+        else:
+            try:
+                savebutton = gedit.getchild(self.MNU_SAVE)   
+                savebutton.click()
+            except ldtp.LdtpExecutionError:
+                raise ldtp.LdtpExecutionError, "Save failed."
+            
+
+    def undo(self):
+        """
+        Go back by one modified step
+        """
         try:
-            save_dlg_btn_save = save_dialog.getchild(self.SAVE_DLG_BTN_SAVE)
+            gedit = ooldtp.context(self.name)
+            undomenu = gedit.getchild(self.MNU_UNDO)
+            undomenu.click()
         except ldtp.LdtpExecutionError:
-            raise ldtp.LdtpExecutionError, "The button Save in Gedit save dialog was not found."
+            raise ldtp.LdtpExecutionError, "Undo button invalid."
         
+    def redo(self):
+        """
+        Go forward by one modified step
+        """
         try:
-            save_dlg_btn_save.click()
+            gedit = ooldtp.context(self.name)
+            redomenu = gedit.getchild(self.MNU_REDO)
+            redomenu.click()
         except ldtp.LdtpExecutionError:
-            raise ldtp.LdtpExecutionError, "There was an error when pushing the Save button."
-
-        ldtp.waittillguinotexist(self.SAVE_DLG)
+            raise ldtp.LdtpExecutionError, "Redo button invalid."
         
     def open(self):
         """


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