From 7fc9343ed0a1182b5b627d54464b0fb361d89448 Mon Sep 17 00:00:00 2001 From: Michael Zanatta Date: Tue, 14 Feb 2023 20:11:22 +1000 Subject: [PATCH 1/5] Swapping Wait-ForJavascript with Find-SEElement --- Module/Functions/Public/Cmdlets/Area.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Module/Functions/Public/Cmdlets/Area.ps1 b/Module/Functions/Public/Cmdlets/Area.ps1 index 3acae46..146a43c 100644 --- a/Module/Functions/Public/Cmdlets/Area.ps1 +++ b/Module/Functions/Public/Cmdlets/Area.ps1 @@ -71,9 +71,12 @@ Area 'Article' Select-DropDown -elementId $LocalizedData.ElementIdActivityType -selectedValue $matchedActivityType.Value - # We are using Views of Answers to dertmine if the Javascript has ran + # Iterate through the HTML Structure and validate if the fields exist. $HTMLFormStructure | ForEach-Object { - Wait-ForJavascript -ElementText $_.Name + $Element = Find-SeElement -Driver ($Global:MVPDriver) -Id $_.Element -Timeout 2 + if (-not($Element)) { + Throw $LocalizedData.ErrorJavaScriptTimeout + } } # Update the Area From 8616a959e75ef1ca96e0e64a84d1ef1507aa5fc6 Mon Sep 17 00:00:00 2001 From: Michael Zanatta Date: Wed, 15 Feb 2023 19:12:53 +1000 Subject: [PATCH 2/5] [Area] Changing Timout lookup time Wrapping Stop-MVPActivity within Try/Catch Wrapping New-MVPAcitivity within ttry to catch save issues --- Module/Functions/Private/New-MVPActivity.ps1 | 6 +++++- Module/Functions/Public/Cmdlets/Area.ps1 | 4 ++-- Module/Functions/Public/Cmdlets/MVPActivity.ps1 | 13 ++++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Module/Functions/Private/New-MVPActivity.ps1 b/Module/Functions/Private/New-MVPActivity.ps1 index 692dcf6..e3dd930 100644 --- a/Module/Functions/Private/New-MVPActivity.ps1 +++ b/Module/Functions/Private/New-MVPActivity.ps1 @@ -103,7 +103,11 @@ function New-MVPActivity { if ($invokeTearDown -and (-not $isPreParse)) { # Close the MVP Activity - Stop-MVPActivity + try { + Stop-MVPActivity + } catch { + Write-Warning $_ + } } } finally { diff --git a/Module/Functions/Public/Cmdlets/Area.ps1 b/Module/Functions/Public/Cmdlets/Area.ps1 index 146a43c..5977cf0 100644 --- a/Module/Functions/Public/Cmdlets/Area.ps1 +++ b/Module/Functions/Public/Cmdlets/Area.ps1 @@ -73,7 +73,7 @@ Area 'Article' # Iterate through the HTML Structure and validate if the fields exist. $HTMLFormStructure | ForEach-Object { - $Element = Find-SeElement -Driver ($Global:MVPDriver) -Id $_.Element -Timeout 2 + $Element = Find-SeElement -Driver ($Global:MVPDriver) -Id $_.Element -Timeout 1 if (-not($Element)) { Throw $LocalizedData.ErrorJavaScriptTimeout } @@ -90,7 +90,7 @@ Area 'Article' # it will retrigger by select the "Article" Start-Sleep -Seconds 1 Select-DropDown -elementId $LocalizedData.ElementIdActivityType -selectedValue $LocalizedData.ElementValueArticle - } -RetryLimit 10 + } -RetryLimit 5 # If it failed to select the Area, we need to fail the cmdlet if ($output -ne $true) { diff --git a/Module/Functions/Public/Cmdlets/MVPActivity.ps1 b/Module/Functions/Public/Cmdlets/MVPActivity.ps1 index a27a1f4..7493dcf 100644 --- a/Module/Functions/Public/Cmdlets/MVPActivity.ps1 +++ b/Module/Functions/Public/Cmdlets/MVPActivity.ps1 @@ -232,9 +232,16 @@ MVPActivity is the top-level definition command, which groups the MVP contributi foreach($Argument in $ArgumentList) { $params.ArgumentList = $Argument - - New-MVPActivity @params - + + ttry { + New-MVPActivity @params + } -catch { + Write-Warning "Failed to Add Activity. Retrying." + # Refresh the page + Enter-SeUrl 'https://mvp.microsoft.com/en-us/MyProfile/EditActivity' -Driver $Global:MVPDriver + Start-Sleep -Seconds 5 + } + } } else { From 44eaa6a53492265269f9eb55e3555fe2af1ddfb6 Mon Sep 17 00:00:00 2001 From: Michael Zanatta Date: Fri, 17 Feb 2023 06:06:14 +1000 Subject: [PATCH 3/5] Adding Verbosity to the Console --- Module/Functions/Public/Cmdlets/MVPActivity.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Module/Functions/Public/Cmdlets/MVPActivity.ps1 b/Module/Functions/Public/Cmdlets/MVPActivity.ps1 index 7493dcf..c4e762b 100644 --- a/Module/Functions/Public/Cmdlets/MVPActivity.ps1 +++ b/Module/Functions/Public/Cmdlets/MVPActivity.ps1 @@ -233,13 +233,19 @@ MVPActivity is the top-level definition command, which groups the MVP contributi $params.ArgumentList = $Argument - ttry { + ttry { + + #Adding more feedback to the user. + Write-Host ("[ADDING] TITLE: '{0}' - DATE: '{1}'" -f $params.ArgumentList.Title, $params.ArgumentList.Date) New-MVPActivity @params + } -catch { - Write-Warning "Failed to Add Activity. Retrying." + + Write-Warning "[ERROR] Failed to Add Activity (Most likley to bad Javascript). Retrying." # Refresh the page Enter-SeUrl 'https://mvp.microsoft.com/en-us/MyProfile/EditActivity' -Driver $Global:MVPDriver Start-Sleep -Seconds 5 + } } From 8d111f2bb6895cadde5e7a25d0e9afc3548e8ef6 Mon Sep 17 00:00:00 2001 From: Michael Zanatta Date: Sat, 18 Feb 2023 13:32:53 +1000 Subject: [PATCH 4/5] Updating existing test-cases Adding new test case to 'fail' Activity form --- Tests/Public/Area.tests.ps1 | 12 ++++++------ Tests/Public/MVPActivity.tests.ps1 | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Tests/Public/Area.tests.ps1 b/Tests/Public/Area.tests.ps1 index 3a1722b..7cba8f4 100644 --- a/Tests/Public/Area.tests.ps1 +++ b/Tests/Public/Area.tests.ps1 @@ -61,7 +61,7 @@ Describe "Area" { Global:Get-AreaGlobalMock Mock -CommandName "Get-ActivityTypes" -MockWith { Global:Get-ActivityTypesMockedData } Mock -CommandName "Select-DropDown" -MockWith {} - Mock -CommandName "Wait-ForJavascript" -MockWith {} + Mock -CommandName "Find-SeElement" -MockWith { return "MOCK VALUE" } $Result = Area 'Test' @@ -69,7 +69,7 @@ Describe "Area" { Should -Invoke "Test-SEDriver" -Exactly 1 Should -Invoke "Test-CallStack" -Exactly 1 Should -Invoke "Get-ActivityTypes" -Exactly 1 - Should -Invoke "Wait-ForJavascript" -Times 1 + Should -Invoke "Find-SeElement" -Times 1 Should -Invoke "Start-Sleep" -Exactly 0 } @@ -131,17 +131,17 @@ Describe "Area" { } - it "Standard Execution however Wait-ForJavascript fails because the form is bad" { + it "Standard Execution however the javascript fails (using Find-SeElement) and dosen't add an extra element" { Global:Get-AreaGlobalMock Mock -CommandName "Get-ActivityTypes" -MockWith { Global:Get-ActivityTypesMockedData } Mock -CommandName "Select-DropDown" -MockWith {} - Mock -CommandName "Wait-ForJavascript" -MockWith { Throw "TestError" } + Mock -CommandName "Find-SeElement" -MockWith {} Mock -CommandName Write-Error -MockWith {} - { Area 'Test' } | Should -Throw $LocalizedData.ErrorAreaFailur6e + { Area 'Test' } | Should -Throw $LocalizedData.ErrorAreaFailure - Should -Invoke "Wait-ForJavascript" -Times 1 + Should -Invoke "Find-SeElement" -Times 1 Should -Invoke "Select-DropDown" -Times 2 Should -Invoke "Write-Error" -Times 1 Should -Invoke "Start-Sleep" -Times 1 diff --git a/Tests/Public/MVPActivity.tests.ps1 b/Tests/Public/MVPActivity.tests.ps1 index 9d3e8c9..e5e723b 100644 --- a/Tests/Public/MVPActivity.tests.ps1 +++ b/Tests/Public/MVPActivity.tests.ps1 @@ -22,7 +22,7 @@ Describe "MVPActivity" { $null = MVPActivity -CSVPath $CSVPath - Should -Invoke "Write-Host" -Exactly 1 + Should -Invoke "Write-Host" -Exactly 3 Should -Invoke "New-MVPActivity" -Exactly 2 } @@ -40,4 +40,27 @@ Describe "MVPActivity" { } + it "Should retry multiple times when the 'Add Activity' Form fails." -TestCases $goodTestCases { + param($CSVPath) + + Mock -CommandName 'New-MVPActivity' -MockWith { throw "Error" } + Mock -CommandName 'Write-Host' -MockWith {} + Mock -CommandName 'Write-Warning' -MockWith {} + Mock -CommandName 'Enter-SeUrl' -MockWith {} + Mock -CommandName 'Start-Sleep' -MockWith {} + Mock -CommandName 'Write-Error' -MockWith {} + + $Result = MVPActivity -CSVPath $CSVPath + + $Result | Should -BeNullOrEmpty + + Should -Invoke 'Write-Error' -Times 2 + Should -Invoke 'New-MVPActivity' -Times 1 + Should -Invoke 'Write-Host' -Times 1 + Should -Invoke 'Write-Warning' -Times 1 + Should -Invoke 'Enter-SeUrl' -Times 1 + Should -Invoke 'Start-Sleep' -Times 1 + + } + } \ No newline at end of file From a9bf65b6a09ec26a582a09f867057a6494ab5d4c Mon Sep 17 00:00:00 2001 From: Michael Zanatta Date: Sat, 18 Feb 2023 13:40:58 +1000 Subject: [PATCH 5/5] Update Version --- Build/BuildVersion.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Build/BuildVersion.txt b/Build/BuildVersion.txt index 02ba23f..bf0357e 100644 --- a/Build/BuildVersion.txt +++ b/Build/BuildVersion.txt @@ -12,4 +12,5 @@ 1.0.1 1.0.2 1.0.3 -1.0.4 \ No newline at end of file +1.0.4 +1.0.5 \ No newline at end of file