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

Commit 1f6d351

Browse files
Merge pull request #69 from ZanattaMichael/68-parameterized-input-including-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
2 parents 90b3877 + a9bf65b commit 1f6d351

6 files changed

Lines changed: 57 additions & 13 deletions

File tree

Build/BuildVersion.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
1.0.1
1313
1.0.2
1414
1.0.3
15-
1.0.4
15+
1.0.4
16+
1.0.5

Module/Functions/Private/New-MVPActivity.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ function New-MVPActivity {
103103

104104
if ($invokeTearDown -and (-not $isPreParse)) {
105105
# Close the MVP Activity
106-
Stop-MVPActivity
106+
try {
107+
Stop-MVPActivity
108+
} catch {
109+
Write-Warning $_
110+
}
107111
}
108112

109113
} finally {

Module/Functions/Public/Cmdlets/Area.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ Area 'Article'
7171

7272
Select-DropDown -elementId $LocalizedData.ElementIdActivityType -selectedValue $matchedActivityType.Value
7373

74-
# We are using Views of Answers to dertmine if the Javascript has ran
74+
# Iterate through the HTML Structure and validate if the fields exist.
7575
$HTMLFormStructure | ForEach-Object {
76-
Wait-ForJavascript -ElementText $_.Name
76+
$Element = Find-SeElement -Driver ($Global:MVPDriver) -Id $_.Element -Timeout 1
77+
if (-not($Element)) {
78+
Throw $LocalizedData.ErrorJavaScriptTimeout
79+
}
7780
}
7881

7982
# Update the Area
@@ -87,7 +90,7 @@ Area 'Article'
8790
# it will retrigger by select the "Article"
8891
Start-Sleep -Seconds 1
8992
Select-DropDown -elementId $LocalizedData.ElementIdActivityType -selectedValue $LocalizedData.ElementValueArticle
90-
} -RetryLimit 10
93+
} -RetryLimit 5
9194

9295
# If it failed to select the Area, we need to fail the cmdlet
9396
if ($output -ne $true) {

Module/Functions/Public/Cmdlets/MVPActivity.ps1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,22 @@ MVPActivity is the top-level definition command, which groups the MVP contributi
232232
foreach($Argument in $ArgumentList) {
233233

234234
$params.ArgumentList = $Argument
235+
236+
ttry {
237+
238+
#Adding more feedback to the user.
239+
Write-Host ("[ADDING] TITLE: '{0}' - DATE: '{1}'" -f $params.ArgumentList.Title, $params.ArgumentList.Date)
240+
New-MVPActivity @params
241+
242+
} -catch {
235243

236-
New-MVPActivity @params
244+
Write-Warning "[ERROR] Failed to Add Activity (Most likley to bad Javascript). Retrying."
245+
# Refresh the page
246+
Enter-SeUrl 'https://mvp.microsoft.com/en-us/MyProfile/EditActivity' -Driver $Global:MVPDriver
247+
Start-Sleep -Seconds 5
237248

249+
}
250+
238251
}
239252

240253
} else {

Tests/Public/Area.tests.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ Describe "Area" {
6161
Global:Get-AreaGlobalMock
6262
Mock -CommandName "Get-ActivityTypes" -MockWith { Global:Get-ActivityTypesMockedData }
6363
Mock -CommandName "Select-DropDown" -MockWith {}
64-
Mock -CommandName "Wait-ForJavascript" -MockWith {}
64+
Mock -CommandName "Find-SeElement" -MockWith { return "MOCK VALUE" }
6565

6666
$Result = Area 'Test'
6767

6868
Should -Invoke "Get-HTMLFormStructure" -Exactly 1
6969
Should -Invoke "Test-SEDriver" -Exactly 1
7070
Should -Invoke "Test-CallStack" -Exactly 1
7171
Should -Invoke "Get-ActivityTypes" -Exactly 1
72-
Should -Invoke "Wait-ForJavascript" -Times 1
72+
Should -Invoke "Find-SeElement" -Times 1
7373
Should -Invoke "Start-Sleep" -Exactly 0
7474

7575
}
@@ -131,17 +131,17 @@ Describe "Area" {
131131

132132
}
133133

134-
it "Standard Execution however Wait-ForJavascript fails because the form is bad" {
134+
it "Standard Execution however the javascript fails (using Find-SeElement) and dosen't add an extra element" {
135135

136136
Global:Get-AreaGlobalMock
137137
Mock -CommandName "Get-ActivityTypes" -MockWith { Global:Get-ActivityTypesMockedData }
138138
Mock -CommandName "Select-DropDown" -MockWith {}
139-
Mock -CommandName "Wait-ForJavascript" -MockWith { Throw "TestError" }
139+
Mock -CommandName "Find-SeElement" -MockWith {}
140140
Mock -CommandName Write-Error -MockWith {}
141141

142-
{ Area 'Test' } | Should -Throw $LocalizedData.ErrorAreaFailur6e
142+
{ Area 'Test' } | Should -Throw $LocalizedData.ErrorAreaFailure
143143

144-
Should -Invoke "Wait-ForJavascript" -Times 1
144+
Should -Invoke "Find-SeElement" -Times 1
145145
Should -Invoke "Select-DropDown" -Times 2
146146
Should -Invoke "Write-Error" -Times 1
147147
Should -Invoke "Start-Sleep" -Times 1

Tests/Public/MVPActivity.tests.ps1

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Describe "MVPActivity" {
2222

2323
$null = MVPActivity -CSVPath $CSVPath
2424

25-
Should -Invoke "Write-Host" -Exactly 1
25+
Should -Invoke "Write-Host" -Exactly 3
2626
Should -Invoke "New-MVPActivity" -Exactly 2
2727

2828
}
@@ -40,4 +40,27 @@ Describe "MVPActivity" {
4040

4141
}
4242

43+
it "Should retry multiple times when the 'Add Activity' Form fails." -TestCases $goodTestCases {
44+
param($CSVPath)
45+
46+
Mock -CommandName 'New-MVPActivity' -MockWith { throw "Error" }
47+
Mock -CommandName 'Write-Host' -MockWith {}
48+
Mock -CommandName 'Write-Warning' -MockWith {}
49+
Mock -CommandName 'Enter-SeUrl' -MockWith {}
50+
Mock -CommandName 'Start-Sleep' -MockWith {}
51+
Mock -CommandName 'Write-Error' -MockWith {}
52+
53+
$Result = MVPActivity -CSVPath $CSVPath
54+
55+
$Result | Should -BeNullOrEmpty
56+
57+
Should -Invoke 'Write-Error' -Times 2
58+
Should -Invoke 'New-MVPActivity' -Times 1
59+
Should -Invoke 'Write-Host' -Times 1
60+
Should -Invoke 'Write-Warning' -Times 1
61+
Should -Invoke 'Enter-SeUrl' -Times 1
62+
Should -Invoke 'Start-Sleep' -Times 1
63+
64+
}
65+
4366
}

0 commit comments

Comments
 (0)