[Libreoffice-commits] core.git: Branch 'private/EL-SHREIF/ui_logger' - uitest/ui_logger_dsl vcl/source

Ahmed ElShreif (via logerrit) logerrit at kemper.freedesktop.org
Tue Aug 13 03:41:44 UTC 2019


 uitest/ui_logger_dsl/UI_Object_commands.tx |   18 +++----
 uitest/ui_logger_dsl/dsl_core.py           |   50 ++++++++++++++++++---
 vcl/source/uitest/logger.cxx               |   67 ++++++++++++++++++++++++++++-
 vcl/source/uitest/uiobject.cxx             |   51 ++++++++++++++++++++++
 4 files changed, 166 insertions(+), 20 deletions(-)

New commits:
commit 21e46d5e3739704f4ee0ac365309762b1e45a792
Author:     Ahmed ElShreif <aelshreif7 at gmail.com>
AuthorDate: Fri Aug 9 23:23:11 2019 -0500
Commit:     Ahmed ElShreif <aelshreif7 at gmail.com>
CommitDate: Mon Aug 12 22:10:40 2019 -0500

    Solving problem of un-named parent:
    
    1) Add recursively query for the parent until find an parent with a name.
    
    2) Remove the parent part "from xxxxxx" from the log statment if there is un-named parent
    
    3) Update the compiler to use the most top parent if there is command with no un-named parent
    
    Change-Id: Id7dd5092bc995312494b5536720141908e73af9a

diff --git a/uitest/ui_logger_dsl/UI_Object_commands.tx b/uitest/ui_logger_dsl/UI_Object_commands.tx
index fbdab9c4e6ca..9b25e09c6efc 100644
--- a/uitest/ui_logger_dsl/UI_Object_commands.tx
+++ b/uitest/ui_logger_dsl/UI_Object_commands.tx
@@ -19,31 +19,29 @@ UIObjectCommand:
 ;
 
 ButtonUIObject:
-  'Click on' ui_button=STRING 'from' parent_id=ID 
+  'Click on' ui_button=STRING  ('from' parent_id=ID)?
 ;	
 CheckBoxUIObject:
-  'Toggle' Check_box_id=STRING 'CheckBox' 'from' parent_id=ID   
+  'Toggle' Check_box_id=STRING 'CheckBox' ('from' parent_id=ID)?   
 ;	
 RadioButtonUIObject:
-  'Select' Radio_button_id=STRING 'RadioButton' 'from' parent_id=ID 
+  'Select' Radio_button_id=STRING 'RadioButton' ('from' parent_id=ID)? 
 ;	
 ComboBoxUIObject:
-   'Select in' Combo_box_id=STRING 'ComboBox' 'item number' item_num=INT 'from' parent_id=ID  
+   'Select in' Combo_box_id=STRING 'ComboBox' 'item number' item_num=INT ('from' parent_id=ID)?  
 ;
 TabControlUIObject:
-   'Choose Tab number' tab_page_number=INT 'in' tab_id=STRING 'from' parent_id=ID 
+   'Choose Tab number' tab_page_number=INT 'in' tab_id=STRING ('from' parent_id=ID)? 
 ;
-
 EditUIObject:
-   action=action_on_UIObject 'from' parent_id=ID  
+   action=action_on_UIObject ('from' parent_id=ID)?
 ;
 SpinFieldUIObject:
-   change=increase_or_ecrease Spin_id=STRING 'from' parent_id=ID 
+   change=increase_or_ecrease Spin_id=STRING ('from' parent_id=ID)? 
 ;
 ListBoxUIObject:
-   'Select element with position ' POS=INT 'in' list_id=STRING 'from' parent_id=ID 
+   'Select element with position ' POS=INT 'in' list_id=STRING ('from' parent_id=ID)?
 ;
-
 //=============================================================
 //hellper grammer for EditUIObject
 action_on_UIObject:
diff --git a/uitest/ui_logger_dsl/dsl_core.py b/uitest/ui_logger_dsl/dsl_core.py
index 827f2ca45b20..a1d1da8b60a2 100644
--- a/uitest/ui_logger_dsl/dsl_core.py
+++ b/uitest/ui_logger_dsl/dsl_core.py
@@ -27,6 +27,9 @@ class ul_Compiler:
     variables=[]
     objects = dict()
     current_app=""
+    parent_hierarchy_count=0
+    last_parent=[]
+
     def __init__(self , input_address , output_address):
         self.ui_dsl_mm = metamodel_from_file('ui_logger_dsl_grammar.tx')
         self.output_stream=self.initiate_test_generation(output_address)
@@ -44,6 +47,7 @@ class ul_Compiler:
         return content
 
     def initiate_test_generation(self,output_address):
+        self.last_parent.append("MainWindow")
         try:
             f = open(output_address,"w")
         except IOError as err:
@@ -195,6 +199,8 @@ class ul_Compiler:
             self.variables.append(old_line)
             line = "\t\t" + DialogCommand.dialog_name + " = self.xUITest.getTopFocusWindow()\n"
             self.variables.append(line)
+            self.last_parent.append(DialogCommand.dialog_name)
+            self.parent_hierarchy_count=self.parent_hierarchy_count+1
 
         elif (DialogCommand.__class__.__name__ == "OpenModelessDialog"):
             old_line = self.variables.pop()
@@ -209,6 +215,8 @@ class ul_Compiler:
             self.variables.append(old_line)
             line = "\t\t" + DialogCommand.dialog_name + "  = self.xUITest.getTopFocusWindow()\n"
             self.variables.append(line)
+            self.last_parent.append(DialogCommand.dialog_name)
+            self.parent_hierarchy_count=self.parent_hierarchy_count+1
 
         elif (DialogCommand.__class__.__name__ == "CloseDialog"):
             if (self.prev_command.__class__.__name__ == "ButtonUIObject"):
@@ -216,12 +224,17 @@ class ul_Compiler:
                 line="\t\tself.ui_test.close_dialog_through_button("+\
                     self.prev_command.ui_button+")\n"
                 self.variables.append(line)
+            self.last_parent.pop()
+            self.parent_hierarchy_count=self.parent_hierarchy_count-1
 
         self.prev_command=DialogCommand
 
     def handle_button(self, ButtonUIObject):
 
-        self.init_Object(ButtonUIObject.ui_button,ButtonUIObject.parent_id)
+        if  ButtonUIObject.parent_id == "" :
+            self.init_Object( ButtonUIObject.ui_button , self.last_parent[self.parent_hierarchy_count] )
+        else:
+            self.init_Object(ButtonUIObject.ui_button,ButtonUIObject.parent_id)
 
         self.write_line_without_parameters(ButtonUIObject.ui_button,"CLICK","tuple")
 
@@ -229,7 +242,10 @@ class ul_Compiler:
 
     def handle_check_box(self, CheckBoxUIObject):
 
-        self.init_Object(CheckBoxUIObject.Check_box_id,CheckBoxUIObject.parent_id)
+        if  CheckBoxUIObject.parent_id == "" :
+            self.init_Object( CheckBoxUIObject.Check_box_id , self.last_parent[self.parent_hierarchy_count] )
+        else:
+            self.init_Object(CheckBoxUIObject.Check_box_id,CheckBoxUIObject.parent_id)
 
         self.write_line_without_parameters(CheckBoxUIObject.Check_box_id,"CLICK","tuple")
 
@@ -237,7 +253,10 @@ class ul_Compiler:
 
     def handle_tab(self, TabControlUIObject):
 
-        self.init_Object(TabControlUIObject.tab_id,TabControlUIObject.parent_id)
+        if  TabControlUIObject.parent_id == "" :
+            self.init_Object( TabControlUIObject.tab_id , self.last_parent[self.parent_hierarchy_count] )
+        else:
+            self.init_Object(TabControlUIObject.tab_id,TabControlUIObject.parent_id)
 
         self.write_line_with_one_parameters(TabControlUIObject.tab_id,"SELECT","POS",TabControlUIObject.tab_page_number)
 
@@ -245,7 +264,10 @@ class ul_Compiler:
 
     def handle_Combo_box(self, ComboBoxUIObject):
 
-        self.init_Object(ComboBoxUIObject.Combo_box_id,ComboBoxUIObject.parent_id)
+        if  ComboBoxUIObject.parent_id == "" :
+            self.init_Object( ComboBoxUIObject.Combo_box_id , self.last_parent[self.parent_hierarchy_count] )
+        else:
+            self.init_Object(ComboBoxUIObject.Combo_box_id,ComboBoxUIObject.parent_id)
 
         self.write_line_with_one_parameters(ComboBoxUIObject.Combo_box_id,"SELECT","POS",ComboBoxUIObject.item_num)
 
@@ -253,7 +275,10 @@ class ul_Compiler:
 
     def handle_Radio_button(self,RadioButtonUIObject):
 
-        self.init_Object(RadioButtonUIObject.Radio_button_id,RadioButtonUIObject.parent_id)
+        if  RadioButtonUIObject.parent_id == "" :
+            self.init_Object( RadioButtonUIObject.Radio_button_id , self.last_parent[self.parent_hierarchy_count] )
+        else:
+            self.init_Object(RadioButtonUIObject.Radio_button_id,RadioButtonUIObject.parent_id)
 
         self.write_line_without_parameters(RadioButtonUIObject.Radio_button_id,"CLICK","tuple")
 
@@ -261,7 +286,10 @@ class ul_Compiler:
 
     def handle_List_box(self, ListBoxUIObject):
 
-        self.init_Object(ListBoxUIObject.list_id,ListBoxUIObject.parent_id)
+        if  ListBoxUIObject.parent_id == "" :
+            self.init_Object(  ListBoxUIObject.list_id , self.last_parent[self.parent_hierarchy_count] )
+        else:
+            self.init_Object(ListBoxUIObject.list_id,ListBoxUIObject.parent_id)
 
         self.write_line_with_one_parameters(ListBoxUIObject.list_id,"SELECT","POS",ListBoxUIObject.POS)
 
@@ -269,7 +297,10 @@ class ul_Compiler:
 
     def handle_spin_field(self,SpinFieldUIObject):
 
-        self.init_Object(SpinFieldUIObject.Spin_id,SpinFieldUIObject.parent_id)
+        if  SpinFieldUIObject.parent_id == "" :
+            self.init_Object( SpinFieldUIObject.Spin_id , self.last_parent[self.parent_hierarchy_count] )
+        else:
+            self.init_Object(SpinFieldUIObject.Spin_id,SpinFieldUIObject.parent_id)
 
         if(SpinFieldUIObject.change=="Increase"):
             self.write_line_without_parameters(SpinFieldUIObject.Spin_id,"UP","tuple")
@@ -279,7 +310,10 @@ class ul_Compiler:
 
     def handle_Edit_uiObject(self,EditUIObject):
 
-        self.init_Object(EditUIObject.action.edit_button,EditUIObject.parent_id)
+        if  EditUIObject.parent_id == "" :
+            self.init_Object( EditUIObject.action.edit_button , self.last_parent[self.parent_hierarchy_count] )
+        else:
+            self.init_Object(EditUIObject.action.edit_button,EditUIObject.parent_id)
 
         if(EditUIObject.action.__class__.__name__ =="Type_action"):
 
diff --git a/vcl/source/uitest/logger.cxx b/vcl/source/uitest/logger.cxx
index eafcef0a2997..cf63dd6ca70b 100644
--- a/vcl/source/uitest/logger.cxx
+++ b/vcl/source/uitest/logger.cxx
@@ -20,6 +20,49 @@
 #include <com/sun/star/beans/PropertyValue.hpp>
 #include <memory>
 
+namespace{
+
+bool isDialogWindow(vcl::Window const * pWindow)
+{
+    WindowType nType = pWindow->GetType();
+    // DIALOG to MODALDIALOG
+    if (nType >= WindowType::DIALOG && nType <= WindowType::MODALDIALOG)
+        return true;
+
+    // MESSBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
+    if (nType >= WindowType::MESSBOX && nType <= WindowType::QUERYBOX)
+        return true;
+
+    if (nType == WindowType::TABDIALOG)
+        return true;
+
+    return false;
+}
+
+bool isTopWindow(vcl::Window const * pWindow)
+{
+    WindowType eType = pWindow->GetType();
+    if (eType == WindowType::FLOATINGWINDOW)
+    {
+        return pWindow->GetStyle() & WB_SYSTEMFLOATWIN;
+    }
+    return false;
+}
+
+vcl::Window* get_top_parent(vcl::Window* pWindow)
+{
+    if (isDialogWindow(pWindow) || isTopWindow(pWindow))
+        return pWindow;
+
+    vcl::Window* pParent = pWindow->GetParent();
+    if (!pParent)
+        return pWindow;
+
+    return get_top_parent(pParent);
+}
+
+
+}
 UITestLogger::UITestLogger():
     maStream(),
     mbValid(false)
@@ -216,7 +259,17 @@ void UITestLogger::logKeyInput(VclPtr<vcl::Window> const & xUIElement, const Key
     OUString aContent;
 
     if(pUIObject->get_type()=="EditUIObject"){
-        aContent =  "Type on '" + rID + "' " + aKeyCode + " from " + aParentID ;
+        if(aParentID=="")
+        {
+            VclPtr <vcl::Window> pParent_top = get_top_parent(xUIElement);
+            aParentID= pParent_top->get_id();
+        }
+        if(aParentID==""){
+            aContent =  aContent+"Type on '" + rID + "' " + aKeyCode;
+        }
+        else{
+            aContent =  aContent+"Type on '" + rID + "' " + aKeyCode + " from " + aParentID ;
+        }
     }
     else if(pUIObject->get_type()=="SwEditWinUIObject" && rID=="writer_edit"){
         aContent = "Type on writer " + aKeyCode ;
@@ -234,7 +287,17 @@ void UITestLogger::logKeyInput(VclPtr<vcl::Window> const & xUIElement, const Key
         aContent = "Type on draw " + aKeyCode ;
     }
     else{
-        aContent =  "Type on '" + rID + "' " + aKeyCode + " from " + aParentID ;
+        if(aParentID=="")
+        {
+            VclPtr <vcl::Window> pParent_top = get_top_parent(xUIElement);
+            aParentID= pParent_top->get_id();
+        }
+        if(aParentID==""){
+            aContent =  "Type on '" + rID + "' " + aKeyCode ;
+        }
+        else{
+            aContent =  "Type on '" + rID + "' " + aKeyCode + " from " + aParentID ;
+        }
     }
     maStream.WriteLine(OUStringToOString(aContent, RTL_TEXTENCODING_UTF8));
 }
diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx
index b7a9bce4e224..c6cdd58e39b4 100644
--- a/vcl/source/uitest/uiobject.cxx
+++ b/vcl/source/uitest/uiobject.cxx
@@ -617,6 +617,10 @@ OUString ButtonUIObject::get_action(VclEventId nEvent) const
             return "Start database" ;
         }
         else{
+            if (get_top_parent(mxButton)->get_id()==""){
+                //This part because if we don't have parent
+                return "Click on '" + mxButton->get_id() ;
+            }
             return "Click on '" + mxButton->get_id() + "' from "+
                 get_top_parent(mxButton)->get_id();
         }
@@ -742,6 +746,14 @@ OUString EditUIObject::get_action(VclEventId nEvent) const
         const Selection& rSelection  = mxEdit->GetSelection();
         long nMin = rSelection.Min();
         long nMax = rSelection.Max();
+        if(get_top_parent(mxEdit)->get_id()==""){
+            //This part because if we don't have parent
+            return  "Select in '" +
+                mxEdit->get_id() +
+                "' {\"FROM\": \"" + OUString::number(nMin) + "\", \"TO\": \"" +
+                OUString::number(nMax) + "\"}"
+                ;
+        }
         return  "Select in '" +
                 mxEdit->get_id() +
                 "' {\"FROM\": \"" + OUString::number(nMin) + "\", \"TO\": \"" +
@@ -863,6 +875,10 @@ OUString CheckBoxUIObject::get_action(VclEventId nEvent) const
 {
     if (nEvent == VclEventId::CheckboxToggle)
     {
+        if(get_top_parent(mxCheckBox)->get_id()==""){
+            //This part because if we don't have parent
+            return "Toggle '" + mxCheckBox->get_id() + "' CheckBox";
+        }
         return "Toggle '" + mxCheckBox->get_id() + "' CheckBox from " +
             get_top_parent(mxCheckBox)->get_id();
     }
@@ -913,6 +929,10 @@ OUString RadioButtonUIObject::get_action(VclEventId nEvent) const
 {
     if (nEvent == VclEventId::RadiobuttonToggle)
     {
+        if(get_top_parent(mxRadioButton)->get_id()==""){
+            //This part because if we don't have parent
+            return "Select '" + mxRadioButton->get_id() + "' RadioButton";
+        }
         return "Select '" + mxRadioButton->get_id() + "' RadioButton from " +
             get_top_parent(mxRadioButton)->get_id();
     }
@@ -1019,11 +1039,21 @@ OUString ListBoxUIObject::get_action(VclEventId nEvent) const
     if (nEvent == VclEventId::ListboxSelect)
     {
         sal_Int32 nPos = mxListBox->GetSelectedEntryPos();
+        if(get_top_parent(mxListBox)->get_id()==""){
+            //This part because if we don't have parent
+            return "Select element with position " + OUString::number(nPos) +
+                 " in '" + mxListBox->get_id();
+        }
         return "Select element with position " + OUString::number(nPos) +
                  " in '" + mxListBox->get_id() +"' from" + get_top_parent(mxListBox)->get_id() ;
     }
     else if (nEvent == VclEventId::ListboxFocus)
     {
+        if(get_top_parent(mxListBox)->get_id()=="")
+        {
+            //This part because if we don't have parent
+            return this->get_type() + " Action:FOCUS Id:" + mxListBox->get_id();
+        }
         return this->get_type() + " Action:FOCUS Id:" + mxListBox->get_id() +
             " Parent:" + get_top_parent(mxListBox)->get_id();
     }
@@ -1094,6 +1124,11 @@ OUString ComboBoxUIObject::get_action(VclEventId nEvent) const
     if (nEvent == VclEventId::ComboboxSelect)
     {
         sal_Int32 nPos = mxComboBox->GetSelectedEntryPos();
+        if (get_top_parent(mxComboBox)->get_id()==""){
+            //This part because if we don't have parent
+            return "Select in '" + mxComboBox->get_id() +
+                "' ComboBox item number " + OUString::number(nPos);
+        }
         return "Select in '" + mxComboBox->get_id() +
                 "' ComboBox item number " + OUString::number(nPos) +
                 " from " + get_top_parent(mxComboBox)->get_id();
@@ -1209,11 +1244,21 @@ OUString SpinFieldUIObject::get_action(VclEventId nEvent) const
 {
     if (nEvent == VclEventId::SpinfieldUp)
     {
+        if(get_top_parent(mxSpinField)->get_id()=="")
+        {
+            //This part because if we don't have parent
+            return "Increase '" + mxSpinField->get_id();
+        }
         return "Increase '" + mxSpinField->get_id() +
             "' from " + get_top_parent(mxSpinField)->get_id();
     }
     else if (nEvent == VclEventId::SpinfieldDown)
     {
+        if(get_top_parent(mxSpinField)->get_id()=="")
+        {
+            //This part because if we don't have parent
+            return "Decrease '" + mxSpinField->get_id();
+        }
         return "Decrease '" + mxSpinField->get_id() +
             "' from " + get_top_parent(mxSpinField)->get_id();
     }
@@ -1277,6 +1322,12 @@ OUString TabControlUIObject::get_action(VclEventId nEvent) const
     if (nEvent == VclEventId::TabpageActivate)
     {
         sal_Int32 nPageId = mxTabControl->GetCurPageId();
+
+        if(get_top_parent(mxTabControl)->get_id()==""){
+            //This part because if we don't have parent
+            return "Choose Tab number " + OUString::number(mxTabControl->GetPagePos(nPageId)) +
+                " in '" + mxTabControl->get_id();
+        }
         return "Choose Tab number " + OUString::number(mxTabControl->GetPagePos(nPageId)) +
                 " in '" + mxTabControl->get_id()+
                 "' from " + get_top_parent(mxTabControl)->get_id() ;


More information about the Libreoffice-commits mailing list