From 2b37e63d9a7578e5363a4580ec26a8662f8356e5 Mon Sep 17 00:00:00 2001 From: IamWenboZhang Date: Wed, 22 Apr 2020 12:33:47 +0000 Subject: [PATCH] Code update --- .../WOPIautomation/Resource/Converter.bat | 27 ----------- .../WOPIautomation/WOPIautomation/FSSHTTP.cs | 40 ++++++++++------ .../WOPIautomation/WOPIautomation/Utility.cs | 46 +++++++++++++++---- 3 files changed, 61 insertions(+), 52 deletions(-) diff --git a/FSSHTTPWOPIInspector/Test/WOPIautomation/Resource/Converter.bat b/FSSHTTPWOPIInspector/Test/WOPIautomation/Resource/Converter.bat index f94939d..5ca6d81 100644 --- a/FSSHTTPWOPIInspector/Test/WOPIautomation/Resource/Converter.bat +++ b/FSSHTTPWOPIInspector/Test/WOPIautomation/Resource/Converter.bat @@ -1,60 +1,34 @@ @echo on -::\Resource\Converter.bat "\"{0}\" \"{1}\" \"{2}\" \"{3}\"", fiddlerPath, userName, outputPath, newName -::{0} fiddlerPath:C:\Users\wopiuser\AppData\Local\Programs\Fiddler\ -::{1} userName:wopiuser -::{2} outputPath:C:\v-fanfan\Update-FSSHTTP_FSSHTTPB-Inspectors-for-Fiddler\FSSHTTPWOPIInspector\Test\WOPIautomation\TestResults\ -::{3} newName:CoautherWithConflict -::%arg1%=fiddlerPath set arg1=%1 -::%arg2%=userName set arg2=%2 -::%arg3%=outputPath set arg3=%3 -::%arg4%=newName set arg4=%4 -echo "if exist C:\Users\"%arg2%"\Documents\Fiddler2\Captures\dump.saz del C:\Users\"%arg2%"\Documents\Fiddler2\Captures\dump.saz" if exist C:\Users\%arg2%\Documents\Fiddler2\Captures\dump.saz del C:\Users\%arg2%\Documents\Fiddler2\Captures\dump.saz -echo "cmd /c call "%arg1%"\ExecAction.exe stop" cmd /c call %arg1%\ExecAction.exe stop timeout /t 5 -echo "cmd /c call "%arg1%"\ExecAction.exe dump" cmd /c call %arg1%\ExecAction.exe dump -echo "set target=C:\Users\"%arg2%"\Documents\Fiddler2\Captures\dump.saz" set target=C:\Users\%arg2%\Documents\Fiddler2\Captures\dump.saz -echo "call:checkFile" call:checkFile -echo "cmd /c call "%arg1%"\ExecAction.exe quit" cmd /c call %arg1%\ExecAction.exe quit -echo "if not exist C:\Users\"%arg2%"\Documents\Fiddler2\Captures\dump.saz timeout /t 10" if not exist C:\Users\%arg2%\Documents\Fiddler2\Captures\dump.saz timeout /t 10 -echo "if not exist "%arg3%" mkdir %arg3%" if not exist %arg3% mkdir %arg3% -echo "if exist "%arg3%"\"%arg4%".saz del "%arg3%"\"%arg4%".saz" if exist %arg3%\%arg4%.saz del %arg3%\%arg4%.saz -echo "copy C:\Users\"%arg2%"\Documents\Fiddler2\Captures\dump.saz "%arg3% copy C:\Users\%arg2%\Documents\Fiddler2\Captures\dump.saz %arg3% -echo "set target="%arg3%"\dump.saz" set target=%arg3%\dump.saz -echo "call:checkFile" call:checkFile -echo "ren "%arg3%"\dump.saz %arg4%.saz" ren %arg3%\dump.saz %arg4%.saz -echo "set target=C:\Users\"%arg2%"\Documents\Fiddler2\Captures\dump.saz" set target=C:\Users\%arg2%\Documents\Fiddler2\Captures\dump.saz -echo "checkFile" call:checkFile ::-------------------------------------------------------- ::-- Function section starts below here ::-------------------------------------------------------- :checkFile - passing a variable by reference -echo "if exist "%target%" goto foundId" if exist %target% goto foundId rem if not exist wait for 10 seconds timeout /t 10 >null -echo "checkFile" goto:checkFile :foundId @@ -62,4 +36,3 @@ echo found %target% goto:eof pause - diff --git a/FSSHTTPWOPIInspector/Test/WOPIautomation/WOPIautomation/FSSHTTP.cs b/FSSHTTPWOPIInspector/Test/WOPIautomation/WOPIautomation/FSSHTTP.cs index 30570b5..885aaf2 100644 --- a/FSSHTTPWOPIInspector/Test/WOPIautomation/WOPIautomation/FSSHTTP.cs +++ b/FSSHTTPWOPIInspector/Test/WOPIautomation/WOPIautomation/FSSHTTP.cs @@ -204,7 +204,7 @@ public void Excel___CheckOutOnOpeningExcelTest() } [TestMethod, TestCategory("FSSHTTP")] - public void Excel___VersioningHistroyExcelTest() + public void VersioningHistroy() { // Upload a excel document. SharepointClient.UploadFile(excel); @@ -217,8 +217,7 @@ public void Excel___VersioningHistroyExcelTest() Browser.Wait(By.LinkText("Open in Excel")); var elementOpenInExcel = Browser.webDriver.FindElement(By.LinkText("Open in Excel")); Browser.Click(elementOpenInExcel); - - /* + // Sign in Excel Desktop App. Utility.WaitForExcelDocumentOpenning2(excelFilename, true); string username = ConfigurationManager.AppSettings["UserName"]; @@ -238,10 +237,8 @@ public void Excel___VersioningHistroyExcelTest() Thread.Sleep(1500); //Utility.OfficeSignIn(username, password); } - */ - - // Wait for excel is opened - // Sign in Excel Desktop App. + + // Wait for excel is opened Utility.WaitForExcelDocumentOpenning2(excelFilename, true); Excel.Application excelToOpen = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application"); @@ -260,6 +257,8 @@ public void Excel___VersioningHistroyExcelTest() Utility.EditExcelWorkbook(excelFilename); } + Thread.Sleep(3000); + // Edit Excel Cell Content. for (int i = 1; i < 2; i++) excelWorkSheet.Cells[i, 1] = DateTime.Now.ToString(); @@ -278,13 +277,16 @@ public void Excel___VersioningHistroyExcelTest() excelToOpen = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application"); excelWorkbook = (Excel.Workbook)excelToOpen.ActiveWorkbook; - //Excel.Worksheet excelWorkSheet = (Excel.Worksheet)excelWorkbook.ActiveSheet; + Thread.Sleep(6000); // Resolve 'UPLOAD FAILED' if (Utility.FindCondition(excelFilename, "We're sorry, someone updated the server copy and it's not possible to upload your changes now.")) { Utility.ResloveUploadFailed(excelFilename, false); - } + } + + //Version History Restore + Utility.VersionHistroyRestore(excelFilename); // Click 'Edit Workbook' button if we opened this workbook read-only from the server. if (Utility.FindCondition(excelFilename, "We opened this workbook read-only from the server.")) @@ -292,14 +294,13 @@ public void Excel___VersioningHistroyExcelTest() Utility.EditExcelWorkbook(excelFilename); } - //Version History Restore - Utility.VersionHistroyRestore(excelFilename); - - // Close and release word process - // Close excel file. - excelWorkbook.Close(); + // Close and release excel process + excelToOpen = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application"); + excelWorkbook = (Excel.Workbook)excelToOpen.ActiveWorkbook; Utility.DeleteDefaultExcelFormat(); + excelWorkbook.Close(); excelToOpen.Quit(); + Marshal.ReleaseComObject(excelWorkbook); Marshal.ReleaseComObject(excelToOpen); // Delete the new upload document @@ -311,6 +312,15 @@ public void Excel___VersioningHistroyExcelTest() Assert.IsTrue(parsingResult, "Case failed, check the details information in error.txt file."); } + [TestMethod, TestCategory("FSSHTTP")] + public void TestParserFile() + { + //bool result = FormatConvert.SaveSAZ(TestBase.testResultPath, testName, out file); + //Assert.IsTrue(result, "The saz file should be saved successfully."); + bool parsingResult = MessageParser.ParseMessageUsingWOPIInspector(@"C:\Users\plugdevuser19\Documents\Fiddler2\Captures\dump.saz"); + Assert.IsTrue(parsingResult, "Case failed, check the details information in error.txt file."); + } + [TestMethod, TestCategory("FSSHTTP")] public void Excel___FlagExcelTest() { diff --git a/FSSHTTPWOPIInspector/Test/WOPIautomation/WOPIautomation/Utility.cs b/FSSHTTPWOPIInspector/Test/WOPIautomation/WOPIautomation/Utility.cs index a2235aa..87ac5e0 100644 --- a/FSSHTTPWOPIInspector/Test/WOPIautomation/WOPIautomation/Utility.cs +++ b/FSSHTTPWOPIInspector/Test/WOPIautomation/WOPIautomation/Utility.cs @@ -614,7 +614,7 @@ public static AutomationElement GetExcelOnlineWindow(string name) foreach (Process p in pro) { title = p.MainWindowTitle; - if (title == (name + ".xlsx - Read-Only - Excel")) + if (title == (name + ".xlsx - Read-Only - Excel")|| title == (name + ".xlsx - Excel")) { var desktop = AutomationElement.RootElement; ele = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, title)); @@ -629,17 +629,31 @@ public static AutomationElement GetExcelRestoreWindow(string name) Process[] pro = Process.GetProcessesByName("EXCEL"); string title = ""; AutomationElement ele = null; - WaitForElement(AutomationElement.RootElement, new PropertyCondition(AutomationElement.NameProperty, name + ".xlsx - Excel"), TreeScope.Children); + var desktop = AutomationElement.RootElement; + Condition Con_ExcelWinTitle =new OrCondition(new PropertyCondition(AutomationElement.NameProperty, name + ".xlsx - Excel"), new PropertyCondition(AutomationElement.NameProperty, name + ".xlsx - Read-Only - Excel")); + WaitForElement(AutomationElement.RootElement, Con_ExcelWinTitle, TreeScope.Children); foreach (Process p in pro) { title = p.MainWindowTitle; - if (title != (name + ".xlsx - Excel")) + while (title == (name + ".xlsx - Excel") || title == (name + ".xlsx - Read-Only - Excel")) { - var desktop = AutomationElement.RootElement; - ele = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, title)); - break; + Thread.Sleep(2000); + pro = Process.GetProcessesByName("EXCEL"); + foreach (Process process in pro) + { + title = process.MainWindowTitle; + if (title != (name + ".xlsx - Excel")&& title!= (name + ".xlsx - Read-Only - Excel")) + { + desktop = AutomationElement.RootElement; + ele = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, title)); + return ele; + } + } } + + ele = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, title)); + return ele; } return ele; } @@ -811,12 +825,15 @@ public static void VersionHistroyRestore(string name) { // Get EXCEL Process AutomationElement docOnline = GetExcelOnlineWindow(name); - + // Click 'Edit Workbook' button. Condition Con_EditWorkbook = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Edit Workbook")); AutomationElement item_EditWorkbook = docOnline.FindFirst(TreeScope.Descendants, Con_EditWorkbook); - InvokePattern Pattern_EditWorkbook = (InvokePattern)item_EditWorkbook.GetCurrentPattern(InvokePattern.Pattern); - Pattern_EditWorkbook.Invoke(); + if (item_EditWorkbook!=null) + { + InvokePattern Pattern_EditWorkbook = (InvokePattern)item_EditWorkbook.GetCurrentPattern(InvokePattern.Pattern); + Pattern_EditWorkbook.Invoke(); + } // Click 'File' on Menu Bar. Condition File_Tab = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "File Tab")); @@ -828,7 +845,7 @@ public static void VersionHistroyRestore(string name) // Select 'Info' under 'File'. Condition Group_Info = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem), new PropertyCondition(AutomationElement.NameProperty, "Info")); Condition Con_Info = new PropertyCondition(AutomationElement.NameProperty, "Info"); - AutomationElement item_Info = docOnline.FindFirst(TreeScope.Children, Con_Info); + AutomationElement item_Info = docOnline.FindFirst(TreeScope.Descendants, Con_Info); item_Info = docOnline.FindFirst(TreeScope.Descendants, Group_Info); SelectionItemPattern selectionItemPattern = item_Info.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; selectionItemPattern.Select(); @@ -841,6 +858,12 @@ public static void VersionHistroyRestore(string name) pattern_VersionHistroy = item_VersionHistroy.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern; pattern_VersionHistroy.Toggle(); + // Click 'Edit Workbook' button if we opened this workbook read-only from the server. + if (Utility.FindCondition(name, "We opened this workbook read-only from the server.")) + { + Utility.EditExcelWorkbook(name); + } + // Find 'Version Histroy' on the left. Condition Con_VersionHistroyBar = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ToolBar), new PropertyCondition(AutomationElement.NameProperty, "Version History")); AutomationElement item_VersionHistroyBar = docOnline.FindFirst(TreeScope.Descendants, Con_VersionHistroyBar); @@ -945,6 +968,9 @@ public static void DeleteDefaultWordFormat() } } + /// + /// Delete the defaut excel empty format + /// public static void DeleteDefaultExcelFormat() { Process[] pro = Process.GetProcessesByName("EXCEL");