Skip to content
This repository has been archived by the owner on Nov 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #69 from ZanattaMichael/68-parameterized-input-inc…
Browse files Browse the repository at this point in the history
…luding-csv-javascript-in-portal-causing-the-form-to-crash-or-to-load-incorrectly

68 parameterized input including csv javascript in portal causing the form to crash or to load incorrectly
  • Loading branch information
ZanattaMichael authored Feb 18, 2023
2 parents 90b3877 + a9bf65b commit 1f6d351
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Build/BuildVersion.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
1.0.1
1.0.2
1.0.3
1.0.4
1.0.4
1.0.5
6 changes: 5 additions & 1 deletion Module/Functions/Private/New-MVPActivity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions Module/Functions/Public/Cmdlets/Area.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 1
if (-not($Element)) {
Throw $LocalizedData.ErrorJavaScriptTimeout
}
}

# Update the Area
Expand All @@ -87,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) {
Expand Down
15 changes: 14 additions & 1 deletion Module/Functions/Public/Cmdlets/MVPActivity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,22 @@ MVPActivity is the top-level definition command, which groups the MVP contributi
foreach($Argument in $ArgumentList) {

$params.ArgumentList = $Argument

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 {

New-MVPActivity @params
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

}

}

} else {
Expand Down
12 changes: 6 additions & 6 deletions Tests/Public/Area.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ 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'

Should -Invoke "Get-HTMLFormStructure" -Exactly 1
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

}
Expand Down Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion Tests/Public/MVPActivity.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
Expand All @@ -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

}

}

0 comments on commit 1f6d351

Please sign in to comment.