Skip to content

Commit

Permalink
Code update
Browse files Browse the repository at this point in the history
  • Loading branch information
IamWenboZhang committed Apr 22, 2020
1 parent c244c46 commit 2b37e63
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 52 deletions.
27 changes: 0 additions & 27 deletions FSSHTTPWOPIInspector/Test/WOPIautomation/Resource/Converter.bat
Original file line number Diff line number Diff line change
@@ -1,65 +1,38 @@
@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
echo found %target%
goto:eof

pause

40 changes: 25 additions & 15 deletions FSSHTTPWOPIInspector/Test/WOPIautomation/WOPIautomation/FSSHTTP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"];
Expand All @@ -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");
Expand All @@ -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();
Expand All @@ -278,28 +277,30 @@ 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."))
{
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
Expand All @@ -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()
{
Expand Down
46 changes: 36 additions & 10 deletions FSSHTTPWOPIInspector/Test/WOPIautomation/WOPIautomation/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}
Expand Down Expand Up @@ -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"));
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -945,6 +968,9 @@ public static void DeleteDefaultWordFormat()
}
}

/// <summary>
/// Delete the defaut excel empty format
/// </summary>
public static void DeleteDefaultExcelFormat()
{
Process[] pro = Process.GetProcessesByName("EXCEL");
Expand Down

0 comments on commit 2b37e63

Please sign in to comment.