diff options
Diffstat (limited to 'testautomation/global/tools')
7 files changed, 270 insertions, 233 deletions
diff --git a/testautomation/global/tools/includes/optional/t_filetools.inc b/testautomation/global/tools/includes/optional/t_filetools.inc index 070427ef3c5b..7189a8e01a43 100644 --- a/testautomation/global/tools/includes/optional/t_filetools.inc +++ b/testautomation/global/tools/includes/optional/t_filetools.inc @@ -260,80 +260,6 @@ end function '******************************************************************************* -function hGetWorkPath() as string - - '///<h3>Retrieve the users work directory</h3> - '///<i>Uses: Call to UNO service</i><br> - '///<i>Errorhandling: Fixes "$(user)"-type path (uses fallback)</i><br> - '///<i>Errorhandling: Handles broken UNO connection (uses fallback)</i><br> - '///<u>Input</u>: - '///<ol> - '///+<li>Nothing</li> - '///</ol> - '///<u>Returns</u>: - '///<ol> - '///+<li>Path to local workdir (string)</li> - '///<ul> - '///+<li>Includes trailing slash/backslash</li> - '///</ul> - '///</ol> - '///<u>Description</u>: - '///<ul> - - dim sPath as string - dim sDefaultPath as string - sDefaultPath = convertpath( gOfficePath & "user/work" ) - dim oOfficeConnect as object - dim oOfficeConfig as object - dim bPathIsFromAPI as boolean - - const CFN = "hGetWorkPath::" - - '///+<li>Create an UNO service and ask it for the location of "Work"</li> - try - oOfficeConnect = hGetUnoService( true ) - oOfficeConfig = oOfficeConnect.createInstance( "com.sun.star.util.PathSettings" ) - sPath = convertFromURL( oOfficeConfig.Work ) - bPathIsFromAPI = true - catch - '///+<li>Handle broken UNO connection</li> - printlog( CFN & "Could not access service, connection broken?" ) - sPath = "" - bPathIsFromAPI = false - endcatch - - '///+<li>If the path differs from the default do a warnlog</li> - if ( sPath <> sDefaultPath ) then - printlog( CFN & "Default path is: " & sDefaultPath ) - printlog( CFN & "Workpath is not defaultpath: " & sPath ) - printlog( CFN & "Overriding UNO path" ) - sPath = convertpath( gOfficePath & "user\work" ) - bPathIsFromAPI = false - endif - - '///+<li>Apply fallback in case of broken connection or invalid path</li> - if ( instr( sPath , "$(user)" ) > 0 ) then - printlog( CFN & "sPath has $(user)-type string, using fallback" ) - sPath = sDefaultPath - bPathIsFromAPI = false - endif - - '///+<li>Add trailing pathseparator, do convertpath</li> - sPath = sPath & "/" - sPath = convertpath( sPath ) - - '///+<li>Print info to the log and return the path</li> - if ( GVERBOSE ) then - if ( bPathIsFromAPI ) then - printlog( CFN & "(From API): " & sPath ) - else - qaerrorlog( CFN & "(Junked API-Path): " & sPath ) - endif - endif - hGetWorkPath() = sPath - '///</ul> - -end function '******************************************************************************* @@ -389,24 +315,5 @@ end function '******************************************************************************* -function hGetWorkFile( cFileName as string ) as string - - '///<h3>Returns a fully qualified filename to a workfile</h3> - '///<u>Input</u>: - '///<ol> - '///+<li>Filename without path (string)</li> - '///</ol> - '///<u>Returns</u>: - '///<ol> - '///+<li>Filename including path to user work directory (string)</li> - '///</ol> - '///<u>Description</u>: - '///<ul> - - '///+<li>Concatenate workpath and filename, convertpath</li> - hGetWorkFile() = convertpath( hGetWorkPath() & cFileName ) - '///</ul> - -end function diff --git a/testautomation/global/tools/includes/optional/t_macro_tools.inc b/testautomation/global/tools/includes/optional/t_macro_tools.inc index 6c1fcc478e5a..733b28fa32f4 100644 --- a/testautomation/global/tools/includes/optional/t_macro_tools.inc +++ b/testautomation/global/tools/includes/optional/t_macro_tools.inc @@ -172,4 +172,44 @@ function hBasicIDERunMacro( cIdentifier as string ) as boolean hBasicIDERunMacro() = false endif +end function + +'******************************************************************************* + +function hExecMacro( cMacro as string ) as boolean + + const CFN = "global::tools::includes::optional::t_macro_tools.inc::hExecMacro(): " + + dim iCurrentModule as integer + dim iCurrentMacro as integer + hEXECMacro() = FALSE + + ToolsMacro_uno + + kontext "Makro" + if ( Makro.exists( 2 ) ) then + ' Iterate through the left treelist + for iCurrentModule = hExpandAllNodes( MakroAus ) to 1 step -1 + MakroAus.select( iCurrentModule ) + ' Iterate through the Macros list (right pane) + for iCurrentMacro = 1 to MakroListe.getItemCount() + MakroListe.select( iCurrentMacro ) + ' Try to find the macro + if ( cMacro = MakroListe.getSelText() ) then + ' Run the macro + if ( Ausfuehren.isEnabled() ) then + Ausfuehren.click() + hExecMacro() = TRUE + exit function + else + warnlog( CFN & "Macro found but <Ausfuehren> is not enabled" ) + exit function + endif + endif + next iCurrentMacro + next iCurrentModule + else + warnlog( CFN & "Macro Organizer is not open within 2 seconds" ) + endif + end function
\ No newline at end of file diff --git a/testautomation/global/tools/includes/required/t_dir.inc b/testautomation/global/tools/includes/required/t_dir.inc index ee673e6b1c47..f5aa59e2d78b 100644 --- a/testautomation/global/tools/includes/required/t_dir.inc +++ b/testautomation/global/tools/includes/required/t_dir.inc @@ -288,4 +288,55 @@ function GetExtention ( Datei as String ) as string next i% GetExtention = Datei end function +' +'------------------------------------------------------------------------------- +' +function hSplitString( sString as string, sSeparator as string, iIndex as integer ) as string + + ' This function wraps around the "split" command and returns one single + ' item by index. Index = 0 means the *LAST* item is returned as this is + ' probably the most commonly used item. If the index is invalid (out of + ' bounds) we print a warning and return an error string. + + const CFN = "global::tools::includes::required::t_dir.inc:hSplitString(): " + const ERROR_MESSAGE = "Array out of bounds for the requested index in string " + const ARRAY_INDEX_CORRECTION = 1 ' The array lower boundary is zero but + ' function starts to count with one. + + ' Split the string into its fragments into an array with dynamic boundaries + dim sArray() as string + dim sReturnString as string : sReturnString = "" + + if ( GVERBOSE ) then + printlog( CFN & "Separator is: " & sSeparator ) + printlog( CFN & "Original string is: " & sString ) + endif + + sArray() = split( sString, sSeparator ) + + if ( GVERBOSE ) then + printlog( CFN & "Number of items found: " & ubound( sArray() ) ) + endif + + ' Special case: Index out of bounds + if ( iIndex > ( ubound( sArray() ) + ARRAY_INDEX_CORRECTION ) or iIndex < 0 ) then + warnlog( CFN & ERROR_MESSAGE & sString ) + hSplitString() = ERROR_MESSAGE & sString + exit function + endif + + ' Special case: Last item requested (this usually is the filename from a path) + if ( iIndex = 0 ) then + sReturnString = sArray( ubound( sArray() ) + if ( GVERBOSE ) then printlog( CFN & sReturnString ) + hSplitString() = sReturnString + exit function + endif + + ' Default is to return the requested item. + sReturnString = sArray( iIndex - ARRAY_INDEX_CORRECTION ) + if ( GVERBOSE ) then printlog( CFN & sReturnString ) + hSplitString() = sReturnString + +end function diff --git a/testautomation/global/tools/includes/required/t_doc1.inc b/testautomation/global/tools/includes/required/t_doc1.inc index ff07554bca35..0ee504c5432e 100755 --- a/testautomation/global/tools/includes/required/t_doc1.inc +++ b/testautomation/global/tools/includes/required/t_doc1.inc @@ -243,20 +243,17 @@ end function ' function hCloseDocument() - '/// Trigger FileClose slot' hUseAsyncSlot( "FileClose") - '/// Accept to lose changes' Kontext "Active" if ( Active.Exists( 2 ) ) then try Active.No catch - Active.Click( 202 ) + Active.click( 202 ) endcatch end if - '/// Wait for FileClose to complete' WaitSlot( 2000 ) end function @@ -357,6 +354,8 @@ end sub ' sub hTypeKeys ( OutputText , optional _iLoop as Integer ) + const CFN = "global::tools::includes::required::t_doc1.inc::hTypeKeys(): " + dim iRepeat as integer dim iLoop as integer dim oDocument as object @@ -371,10 +370,14 @@ sub hTypeKeys ( OutputText , optional _iLoop as Integer ) hSetDocumentContext() ' set kontext to current document type oDocument = hSetDocumentObject() ' Get the document object we want to write to - for iRepeat = 1 to iLoop - oDocument.TypeKeys( OutputText ) - wait( 200 ) - next iRepeat + try + for iRepeat = 1 to iLoop + oDocument.TypeKeys( OutputText ) + wait( 200 ) + next iRepeat + catch + warnlog( CFN & "Failed to send keystroke to given context" ) + endcatch end sub diff --git a/testautomation/global/tools/includes/required/t_doc2.inc b/testautomation/global/tools/includes/required/t_doc2.inc index 4192563b0eba..0e9af93f287c 100644 --- a/testautomation/global/tools/includes/required/t_doc2.inc +++ b/testautomation/global/tools/includes/required/t_doc2.inc @@ -113,135 +113,6 @@ end sub ' '------------------------------------------------------------------------------- ' -function hEnableDocumentEditMode() as boolean - - hEnableDocumentEditMode() = false - - dim iTry as integer - - printlog( "Try to switch document to edit mode" ) - for iTry = 1 to 20 - try - kontext "Standardbar" - if ( Bearbeiten.getState( 2 ) <> 1 ) then - Bearbeiten.click() - - kontext "Active" - if ( Active.exists( 1 ) ) then - printlog( "Handle <Use copy message>" ) - hCloseDialog( Active, "yes" ) - wait( 2000 ) - printlog( "Successfully switched to edit mode" ) - hEnableDocumentEditMode() = true - exit for - endif - endif - catch - wait( 200 ) - endcatch - next iTry - -end function - -'******************************************************************************* - -function sMakeReadOnlyDocumentEditable() as boolean - - sMakeReadOnlyDocumentEditable() = hEnableDocumentEditMode() - exit function - - ' Function returns TRUE if document has been made editable and FALSE if - ' no action was required (that is: Document was not read-only) - - dim iTry as integer - dim iWait as integer - dim rc as integer - const CFN = "sMakeReadOnlyDocumentEditable::" - - if ( GVERBOSE ) then printlog( CFN & "Making document editable (create a copy) if it is readonly" ) - - ' We still run into synchronization problems with the "Make document editable" feature - ' because we do not know when this button becomes available and ready for use: The - ' document has to be loaded, then we have to wait for the toolbar to get populated. - ' One thing appears to work though: Try to execute the slot using hUseAsyncSlot. - ' This is a little bit tricky because the state of the document is altered but if - ' the slot has been executed once we know for sure that the button on the toolbar is - ' available and can check its state and - if need be - chenge the document state back. - - ' ========== Workaround begin ========== - hUseAsyncSlot( "EditDoc" ) - kontext "Active" - if ( Active.exists() ) then - if ( GVERBOSE ) then printlog( "Handling create copy message" ) - Active.yes() - wait( 1000 ) - endif - ' ========== Workaround end ========== - Kontext "Standardbar" - iWait = 0 - Do - if ( Bearbeiten.IsEnabled() ) then - try - if Bearbeiten.getState( 2 ) = 0 then - exit do - endif - catch - if ( GVERBOSE ) then printlog "Attempt " & iWait & " to make document readable failed" - iWait = iWait + 1 - wait ( 1000 ) - endcatch - else - if ( GVERBOSE ) then printlog "Attempt " & iWait & " to make document readable failed" - iWait = iWait + 1 - wait ( 1000 ) - end if - if iWait >= 5 then exit do - Loop - - if ( Bearbeiten.IsEnabled() ) then - - if ( Bearbeiten.getState( 2 ) = 0 ) then - - rc = hUseAsyncSlot("editdoc") - - if ( rc >= 0 ) then - for iTry = 1 to 2 - - - Kontext "Active" - if ( Active.exists( 5 ) ) then - - printlog( CFN & "Messagebox: " & Active.getText() ) - - try - if ( GVERBOSE ) then printlog( CFN & "Document was read-only. A copy will be used." ) - Active.Yes() - if ( GVERBOSE ) then printlog( CFN & "Closed 'use copy' message" ) - catch - if ( GVERBOSE ) then printlog( CFN & "Probing for unexpected messagebox..." ) - active.ok() - qaerrorlog( "#i100701 - Object not found message" ) - endcatch - else - printlog( CFN & "No messagebox informing about a copy being used" ) - endif - sMakeReadOnlyDocumentEditable() = TRUE - next iTry - else - printlog( CFN & "Document appears to be editable" ) - endif - else - if ( GVERBOSE ) then printlog( CFN & "Button <Bearbeiten> is pressed, document is editable" ) - sMakeReadOnlyDocumentEditable() = FALSE - endif - else - if ( GVERBOSE ) then printlog( CFN & "Control <Bearbeiten> is not enabled" ) - endif - -end function -' -'------------------------------------------------------------------------------- -' function fSelectFirstOLE() as integer 'Select first visible OLE object using Navigator 'Returns error-code: diff --git a/testautomation/global/tools/includes/required/t_files.inc b/testautomation/global/tools/includes/required/t_files.inc index 4b0ddd09318b..d734cd3f05a7 100644 --- a/testautomation/global/tools/includes/required/t_files.inc +++ b/testautomation/global/tools/includes/required/t_files.inc @@ -34,7 +34,6 @@ function hGrafikEinfuegen( cFile as string ) as Boolean hGrafikEinfuegen() = hInsertGraphic( cFile, "Static" ) - exit function end function @@ -43,7 +42,6 @@ end function function hGrafikVerknuepftEinfuegen( cFile as string ) as Boolean hGrafikVerknuepftEinfuegen() = hInsertGraphic( cFile, "Linked" ) - exit function end function @@ -103,7 +101,7 @@ end function function hIsNamedDocLoaded( cFileName as string ) as boolean ' Retrieve the current filename from the document properties - which in - ' comparision to the old approach to retrive the name from the file save + ' comparision to the old approach to retrieve the name from the file save ' dialog - gives us the file including its extension. So we only need ' to compare the last characters from a full path to be relatively ' certain that we work with the correct file. There is some small margin of @@ -501,6 +499,167 @@ end function ' '------------------------------------------------------------------------------- ' +function hGetWorkFile( cFileName as string ) as string + hGetWorkFile() = hGetWorkPath() & cFileName +end function +' +'------------------------------------------------------------------------------- +' +function hGetWorkPath() as string + + ' Retrieve the user's work directory using the API (or fallback) + + dim sPath as string : sPath = "" + dim oOfficeConnect as object + dim oOfficeConfig as object + dim bPathIsFromAPI as boolean + + const CFN = "global::tools::includes::required::t_files.inc:hGetWorkPath(): " + + ' Create an UNO service and ask it for the location of Work + try + oOfficeConnect = hGetUnoService( true ) + oOfficeConfig = oOfficeConnect.createInstance( "com.sun.star.util.PathSettings" ) + sPath = convertFromURL( oOfficeConfig.Work ) + bPathIsFromAPI = true + catch + printlog( CFN & "Could not access service, connection broken?" ) + sPath = convertpath( gOfficePath & "user/work" ) + bPathIsFromAPI = false + endcatch + + if ( GVERBOSE ) then + + printlog( CFN & "Path is: " & sPath ) + + ' Check path existence + if ( FileExists( sPath ) ) then + printlog( CFN & "Path exists." ) + else + warnlog( CFN & "Path does not exist." ) + endif + + ' Inform about the location from where the path was taken + if ( bPathIsFromAPI ) then + printlog( CFN & "Path was taken from API" ) + else + warnlog( CFN & "Path was taken from (hardcoded) fallback" ) + endif + + endif + + hGetWorkPath() = sPath & getPathSeparator + +end function +' +'------------------------------------------------------------------------------- +' +function hFileGetLocalPath( sSourcePath as string ) as string + + ' Isolate filename from path, prepend local work directory and return new file path + hFileGetLocalPath() = hGetWorkFile( hSplitString( sSourcePath, getPathSeparator, 0 ) ) + +end function +' +'------------------------------------------------------------------------------- +' +function hFileListCopyLocal( lsSourceList() as string ) as boolean + + ' Copy a list of files from testautomation to the local work directory + + const CFN = "global::tools::includes::required::t_files.inc:hFileListCopyLocal(): " + dim iCurrentPath as integer + dim cTargetPath as string + dim cSourcePath as string + + hFileListCopyLocal() = true + + for iCurrentPath = 1 to listcount( lsSourceList() ) + + cSourcePath = lsSourceList( iCurrentPath ) + cTargetPath = hFileGetLocalPath( cSourcePath ) + + FileCopy( cSourcePath, cTargetPath ) + + ' If any one copy operation fails we + if ( not FileExists( cTargetPath ) ) then + hFileListCopyLocal() = false + warnlog( CFN & "File was not copied: " & cSourcePath ) + endif + + next iCurrentPath + +end function +' +'------------------------------------------------------------------------------- +' +function hFileOpenLocally( byVal sSourcePath as string ) as boolean + + ' Issue #i112208# - implement a function that copies a file from testautomation + ' into the local work directory and opens it from there to avoid that the + ' document gets opened in read-only mode. See details of the implementation + ' in the issue description. + + ' Parameters + ' 1) Path as string, URLs are untested. + ' 2) Separator, usually "getPathSeparator" + ' 3) Item number, 0 = last item which usually is the file name from a path. + ' Begin counting with 1, while the function internally accesses item 0 + ' from the array. + + const CFN = "global::tools::includes::required::t_files.inc:hFileOpenLocally(): " + + dim sTargetPath as string + + sSourcePath = convertpath( sSourcePath ) + + ' If the source file does not exist we quit + if ( not FileExists( sSourcePath ) ) then + warnlog( CFN & "Source path/file does not exist: " & sSourcePath ) + hFileOpenLocally() = false + exit function + endif + + ' Find out what the name of the target file is going to be + sTargetPath = hFileGetLocalPath( sSourcePath ) ' The path + file + + ' For debugging purposes set global variable gVerbose to TRUE + if ( gVerbose ) then + printlog( CFN & "Copying file" ) + printlog( CFN & "From: " & sSourcePath ) + printlog( CFN & "To..: " & sTargetPath ) + endif + + ' Copy the file from anywhere to the local user directory if it does not + ' exist. This behavior was discussed on IRC + if ( FileExists( sTargetPath ) ) then + printlog( CFN & "Re-using existing local copy of workfile" ) + 'warnlog( CFN & "Target file exists, it has not been deleted by prior test" ) + endif + + FileCopy( sSourcePath, sTargetPath ) + + ' Verify that the file has been created. return an empty string and warn + if ( not FileExists( sTargetPath ) ) then + warnlog( CFN & "File was not copied: " & sTargetFile ) + hFileOpenLocally() = false + gLastWorkFile = "" + exit function + endif + + ' This is a hook that allows to access the filename under which the file + ' has been saved. Due to restrictive coding guidelines we cannot return + ' the new filename. + gLastWorkFile = sTargetPath + + ' Finally open the file from the local work directory. It should open + ' ready for editing + hFileOpenLocally() = hFileOpen( gLastWorkFile ) + +end function +' +'------------------------------------------------------------------------------- +' function hFileCloseAll() as integer dim iDocumentCount as integer : iDocumentCount = 0 diff --git a/testautomation/global/tools/includes/required/t_menu.inc b/testautomation/global/tools/includes/required/t_menu.inc index 830012cc7dae..b03062b39471 100644 --- a/testautomation/global/tools/includes/required/t_menu.inc +++ b/testautomation/global/tools/includes/required/t_menu.inc @@ -270,6 +270,12 @@ function hMenuFindSelect(MenuID as variant, SelectSlot as Boolean, ExpectedNr as warnlog "The real Position (Separators included) was: " + i endif i = RealEnd + else + if ( i = ExpectedNr ) then + if nID = "" then + warnlog "#i115132#Missing .uno Slots in context menus" + endif + endif endif next i else |