Commit b78c0546 b78c054636ccbd4530e65eb8d514ca357de3c9a8 by Christian Gerdes

New plugins

Convert Date Parameter to Age
Clean Temp Files
1 parent 727db387
...@@ -24,6 +24,67 @@ using System.Net; ...@@ -24,6 +24,67 @@ using System.Net;
24 24
25 namespace LIL_VSTT_Plugins 25 namespace LIL_VSTT_Plugins
26 { 26 {
27 [DisplayName("Convert Date Parameter to Age")]
28 [Description("Converts the date in given parameters into todays age and saves with suffix as new parameter")]
29 public class ConvertDateToAge : WebTestPlugin
30 {
31 [DisplayName("Parameter RegEx"), DefaultValue(""), Description("Regular expression. If the parameter exists in context and matches it will be convertet into a date. Will not fail the script if date cannot be converted.")]
32 public string ParameterRegEx { get; set; }
33 [DisplayName("Date Format"), DefaultValue("yyyy-MM-dd"), Description("The format of the date string in the parameter to convert from, see https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings")]
34 public string DateFormat { get; set; }
35 [DisplayName("Age Parameter Suffix"), DefaultValue("_Age"), Description("The suffix to be added for new parameters. If set to null or empty the original parameter will be overwritten.")]
36 public string Suffix { get; set; }
37
38 Regex regex = null;
39
40 public override void PreWebTest(object sender, PreWebTestEventArgs e)
41 {
42 base.PreWebTest(sender, e);
43 if (regex == null) regex = new Regex(ParameterRegEx);
44 Dictionary<string, object> temp = new Dictionary<string, object>();
45 bool convertSuccess = false;
46
47 // Iterate through all context variables
48 foreach (KeyValuePair<string, object> obj in e.WebTest.Context)
49 {
50 if(regex.IsMatch(obj.Key))
51 {
52 try
53 {
54 // Try to convert to a date using the specified format
55 DateTime parsedDate;
56 convertSuccess = DateTime.TryParseExact(obj.Value.ToString(), DateFormat, null, System.Globalization.DateTimeStyles.None, out parsedDate);
57
58 // Save the age
59 if (convertSuccess) temp.Add(obj.Key + Suffix, CalculateAge(parsedDate));
60 else e.WebTest.AddCommentToResult("Failed to calculate age using \"" + obj.Value.ToString() + "\" of parameter \"" + obj.Key + "\"" + " and format \"" + DateFormat + "\"");
61 }
62 catch (Exception ex)
63 {
64 e.WebTest.AddCommentToResult("Failed to convert date parameter to age: " + ex.Message);
65 }
66 }
67 }
68
69 // Add the new ones to the webtest context
70 foreach (KeyValuePair<string, object> obj in temp)
71 {
72 e.WebTest.Context[obj.Key] = obj.Value;
73 e.WebTest.AddCommentToResult("Saved value \"" + obj.Value + "\" into \"" + obj.Key + "\"");
74 }
75 }
76
77 public static int CalculateAge(DateTime birthDay)
78 {
79 int years = DateTime.Now.Year - birthDay.Year;
80
81 if ((birthDay.Month > DateTime.Now.Month) || (birthDay.Month == DateTime.Now.Month && birthDay.Day > DateTime.Now.Day))
82 years--;
83
84 return years;
85 }
86 }
87
27 [DisplayName("Force UrlEncoded Cookies")] 88 [DisplayName("Force UrlEncoded Cookies")]
28 [Description("Reparses all cookies set by the server and stores the value in UrlEncoded format. Cookies with illegal characters will otherwise cause none of the previous set cookies to be added to new requests.")] 89 [Description("Reparses all cookies set by the server and stores the value in UrlEncoded format. Cookies with illegal characters will otherwise cause none of the previous set cookies to be added to new requests.")]
29 public class DebugCookies : WebTestPlugin 90 public class DebugCookies : WebTestPlugin
......
...@@ -23,6 +23,39 @@ using System.Text.RegularExpressions; ...@@ -23,6 +23,39 @@ using System.Text.RegularExpressions;
23 namespace LIL_VSTT_Plugins 23 namespace LIL_VSTT_Plugins
24 { 24 {
25 /// <summary> 25 /// <summary>
26 /// LoadTest Clear Temp
27 /// </summary>
28 [DisplayName("Clean Temp Files")]
29 [Description("(C) Copyright 2020 LIGHTS IN LINE AB\r\nCrashed loadtests can leave a lot of test logs in the temp folder of the agent. This plugin removes them before starting a new loadtest.")]
30 public class CleanTempFolder : ILoadTestPlugin
31 {
32 //store the load test object.
33 LoadTest mLoadTest;
34
35 public void Initialize(LoadTest loadTest)
36 {
37 mLoadTest = loadTest;
38 loadTest.LoadTestStarting += new EventHandler(mLoadTest_Starting);
39 }
40 void mLoadTest_Starting(object sender, EventArgs e)
41 {
42 System.IO.DirectoryInfo di = new DirectoryInfo(System.IO.Path.GetTempPath());
43
44 foreach (FileInfo file in di.GetFiles("*.dat"))
45 {
46 try
47 {
48 file.Delete();
49 }
50 catch (Exception) { };
51
52 }
53 File.Create(System.IO.Path.GetTempPath() + "\\Cleaned_DAT_by_plugin.txt");
54 }
55 }
56
57
58 /// <summary>
26 /// LoadTest Plugin DisableSSLSessionCache 59 /// LoadTest Plugin DisableSSLSessionCache
27 /// </summary> 60 /// </summary>
28 [DisplayName("SSL Session Cache Disabled")] 61 [DisplayName("SSL Session Cache Disabled")]
......
...@@ -29,7 +29,7 @@ namespace LIL_VSTT_Plugins ...@@ -29,7 +29,7 @@ namespace LIL_VSTT_Plugins
29 public bool DontStopIteration { get; set; } 29 public bool DontStopIteration { get; set; }
30 30
31 Random rnd = new Random(); 31 Random rnd = new Random();
32 Regex rx = new Regex("externalSystemRequestLimitReached\"?:?true", RegexOptions.IgnoreCase); 32 Regex rx = new Regex("externalSystemRequestLimitReached\".?:.?true", RegexOptions.IgnoreCase);
33 33
34 public override void PreRequest(object sender, PreRequestEventArgs e) 34 public override void PreRequest(object sender, PreRequestEventArgs e)
35 { 35 {
......
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <LoadTest Name="LoadTest1" Description="" Owner="" storage="d:\git\vstt-plugins\testproject1\loadtest1.loadtest" Priority="2147483647" Enabled="true" CssProjectStructure="" CssIteration="" DeploymentItemsEditable="" WorkItemIds="" TraceLevel="None" CurrentRunConfig="Run Settings1" Id="0e35c1c4-9214-4fc4-907f-42e11a00845a" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010"> 2 <LoadTest Name="LoadTest1" Description="" Owner="" storage="c:\ws\repos\vstt-plugins\testproject1\loadtest1.loadtest" Priority="2147483647" Enabled="true" CssProjectStructure="" CssIteration="" DeploymentItemsEditable="" WorkItemIds="" TraceLevel="None" CurrentRunConfig="Run Settings1" Id="0e35c1c4-9214-4fc4-907f-42e11a00845a" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
3 <Scenarios> 3 <Scenarios>
4 <Scenario Name="Scenario1" DelayBetweenIterations="5" PercentNewUsers="0" IPSwitching="true" TestMixType="PercentageOfUsersRunning" ApplyDistributionToPacingDelay="true" MaxTestIterations="0" DisableDuringWarmup="false" DelayStartTime="0" AllowedAgents=""> 4 <Scenario Name="Scenario1" DelayBetweenIterations="5" PercentNewUsers="0" IPSwitching="true" TestMixType="PercentageOfUsersRunning" ApplyDistributionToPacingDelay="true" MaxTestIterations="0" DisableDuringWarmup="false" DelayStartTime="0" AllowedAgents="">
5 <ThinkProfile Value="0.2" Pattern="Off" /> 5 <ThinkProfile Value="0.2" Pattern="Off" />
6 <LoadProfile Pattern="Constant" InitialUsers="1" /> 6 <LoadProfile Pattern="Constant" InitialUsers="1" />
7 <TestMix> 7 <TestMix>
8 <TestProfile Name="WebTest1" Path="webtest1.webtest" Id="c649760b-6dd8-4210-8a6d-3c6596d08668" Percentage="100" Type="Microsoft.VisualStudio.TestTools.WebStress.DeclarativeWebTestElement, Microsoft.VisualStudio.QualityTools.LoadTest, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 8 <TestProfile Name="WebTest1" Path="webtest1.webtest" Id="c649760b-6dd8-4210-8a6d-3c6596d08668" Percentage="100" Type="Microsoft.VisualStudio.TestTools.WebStress.DeclarativeWebTestElement, Microsoft.VisualStudio.QualityTools.LoadTest, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
9 </TestMix> 9 </TestMix>
10 <BrowserMix> 10 <BrowserMix>
11 <BrowserProfile Percentage="100"> 11 <BrowserProfile Percentage="100">
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
92 <Counter Name="Avg. Response Time" /> 92 <Counter Name="Avg. Response Time" />
93 <Counter Name="Avg. Connection Wait Time"> 93 <Counter Name="Avg. Connection Wait Time">
94 <ThresholdRules> 94 <ThresholdRules>
95 <ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 95 <ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
96 <RuleParameters> 96 <RuleParameters>
97 <RuleParameter Name="DependentCategory" Value="LoadTest:Page" /> 97 <RuleParameter Name="DependentCategory" Value="LoadTest:Page" />
98 <RuleParameter Name="DependentCounter" Value="Avg. Page Time" /> 98 <RuleParameter Name="DependentCounter" Value="Avg. Page Time" />
...@@ -157,7 +157,7 @@ ...@@ -157,7 +157,7 @@
157 <Counter Name="Current Bandwidth" RangeGroup="Network Bytes" /> 157 <Counter Name="Current Bandwidth" RangeGroup="Network Bytes" />
158 <Counter Name="Bytes Total/sec" RangeGroup="Network Bytes"> 158 <Counter Name="Bytes Total/sec" RangeGroup="Network Bytes">
159 <ThresholdRules> 159 <ThresholdRules>
160 <ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 160 <ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
161 <RuleParameters> 161 <RuleParameters>
162 <RuleParameter Name="DependentCategory" Value="Network Interface" /> 162 <RuleParameter Name="DependentCategory" Value="Network Interface" />
163 <RuleParameter Name="DependentCounter" Value="Current Bandwidth" /> 163 <RuleParameter Name="DependentCounter" Value="Current Bandwidth" />
...@@ -303,7 +303,7 @@ ...@@ -303,7 +303,7 @@
303 <Counter Name="Current Bandwidth" RangeGroup="Network Bytes" /> 303 <Counter Name="Current Bandwidth" RangeGroup="Network Bytes" />
304 <Counter Name="Bytes Total/sec" RangeGroup="Network Bytes"> 304 <Counter Name="Bytes Total/sec" RangeGroup="Network Bytes">
305 <ThresholdRules> 305 <ThresholdRules>
306 <ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 306 <ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
307 <RuleParameters> 307 <RuleParameters>
308 <RuleParameter Name="DependentCategory" Value="Network Interface" /> 308 <RuleParameter Name="DependentCategory" Value="Network Interface" />
309 <RuleParameter Name="DependentCounter" Value="Current Bandwidth" /> 309 <RuleParameter Name="DependentCounter" Value="Current Bandwidth" />
...@@ -416,7 +416,7 @@ ...@@ -416,7 +416,7 @@
416 </CounterSet> 416 </CounterSet>
417 </CounterSets> 417 </CounterSets>
418 <RunConfigurations> 418 <RunConfigurations>
419 <RunConfiguration Name="Run Settings1" Description="" ResultsStoreType="Database" TimingDetailsStorage="AllIndividualDetails" SaveTestLogsOnError="true" SaveTestLogsFrequency="1" MaxErrorDetails="200" MaxErrorsPerType="1000" MaxThresholdViolations="1000" MaxRequestUrlsReported="1000" UseTestIterations="false" RunDuration="60" WarmupTime="0" CoolDownTime="0" TestIterations="12" WebTestConnectionModel="ConnectionPerUser" WebTestConnectionPoolSize="50" SampleRate="5" ValidationLevel="High" SqlTracingConnectString="" SqlTracingConnectStringDisplayValue="" SqlTracingDirectory="" SqlTracingEnabled="false" SqlTracingFileCount="2" SqlTracingRolloverEnabled="true" SqlTracingMinimumDuration="500" RunUnitTestsInAppDomain="true" CoreCount="0" ResourcesRetentionTimeInMinutes="0" AgentDiagnosticsLevel="Warning"> 419 <RunConfiguration Name="Run Settings1" Description="" ResultsStoreType="Database" TimingDetailsStorage="AllIndividualDetails" SaveTestLogsOnError="true" SaveTestLogsFrequency="1" MaxErrorDetails="200" MaxErrorsPerType="1000" MaxThresholdViolations="1000" MaxRequestUrlsReported="1000" UseTestIterations="true" RunDuration="60" WarmupTime="0" CoolDownTime="0" TestIterations="5" WebTestConnectionModel="ConnectionPerUser" WebTestConnectionPoolSize="50" SampleRate="5" ValidationLevel="High" SqlTracingConnectString="" SqlTracingConnectStringDisplayValue="" SqlTracingDirectory="" SqlTracingEnabled="false" SqlTracingFileCount="2" SqlTracingRolloverEnabled="true" SqlTracingMinimumDuration="500" RunUnitTestsInAppDomain="true" CoreCount="0" UseMultipleIPs="false" TestAgentConfiguration="Default" AgentDiagnosticsLevel="Warning">
420 <CounterSetMappings> 420 <CounterSetMappings>
421 <CounterSetMapping ComputerName="[CONTROLLER MACHINE]"> 421 <CounterSetMapping ComputerName="[CONTROLLER MACHINE]">
422 <CounterSetReferences> 422 <CounterSetReferences>
...@@ -432,4 +432,7 @@ ...@@ -432,4 +432,7 @@
432 </CounterSetMappings> 432 </CounterSetMappings>
433 </RunConfiguration> 433 </RunConfiguration>
434 </RunConfigurations> 434 </RunConfigurations>
435 <LoadTestPlugins>
436 <LoadTestPlugin Classname="LIL_VSTT_Plugins.CleanTempFolder, LIL_VSTT_Plugins, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" DisplayName="Clean Temp Files" Description="(C) Copyright 2020 LIGHTS IN LINE AB&#xD;&#xA;Crashed loadtests can leave a lot of test logs in the temp folder of the agent. This plugin removes them before starting a new loadtest." />
437 </LoadTestPlugins>
435 </LoadTest> 438 </LoadTest>
...\ No newline at end of file ...\ No newline at end of file
......
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <WebTest Name="WebTest1" Id="c649760b-6dd8-4210-8a6d-3c6596d08668" Owner="" Priority="2147483647" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="WebTest1.a5a27e2d-474c-43bb-be4d-1b12e85851a0.rec.webtestresult" ResultsLocale=""> 2 <WebTest Name="WebTest1" Id="c649760b-6dd8-4210-8a6d-3c6596d08668" Owner="" Priority="2147483647" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="WebTest1.a5a27e2d-474c-43bb-be4d-1b12e85851a0.rec.webtestresult" ResultsLocale="">
3 <Items> 3 <Items>
4 <Request Method="GET" Guid="8abd3e84-6029-47ca-a3b0-abb2fb28d548" Version="1.1" Url="http://localhost:8080/EmailValidator" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False" /> 4 <Request Method="GET" Guid="0af8c656-b702-4c75-a66d-6e26af1030ae" Version="1.1" Url="http://localhost/" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False" />
5 </Items> 5 </Items>
6 <ContextParameters>
7 <ContextParameter Name="Parameter1" Value="This is not a date" />
8 <ContextParameter Name="TestParam1" Value="2020-10-07" />
9 </ContextParameters>
6 <WebTestPlugins> 10 <WebTestPlugins>
7 <WebTestPlugin Classname="LIL_VSTT_Plugins.SetWebTestParameter, LIL_VSTT_Plugins, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" DisplayName="SetWebTestParameter" Description=""> 11 <WebTestPlugin Classname="LIL_VSTT_Plugins.ConvertDateToAge, LIL_VSTT_Plugins, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" DisplayName="Convert Date Parameter to Age" Description="Converts the date in given parameters into todays age and saves with suffix as new parameter">
8 <RuleParameters> 12 <RuleParameters>
9 <RuleParameter Name="Parameter_Name" Value="UserName" /> 13 <RuleParameter Name="ParameterRegEx" Value="Param1" />
10 <RuleParameter Name="DebugMode" Value="False" /> 14 <RuleParameter Name="DateFormat" Value="yyyy-MM-dd" />
11 <RuleParameter Name="DebugLogFile" Value="C:\Temp\SetTestParameterDebug.log" /> 15 <RuleParameter Name="Suffix" Value="" />
12 <RuleParameter Name="Connection_String" Value="UserdataFew1.csv" />
13 <RuleParameter Name="Has_col_name" Value="False" />
14 <RuleParameter Name="Autosplit" Value="False" />
15 <RuleParameter Name="IgnoreBlanks" Value="True" />
16 <RuleParameter Name="LogFilePathString" Value="C:\Temp\Fungerande.log" />
17 <RuleParameter Name="LogFileAppendID" Value="False" />
18 <RuleParameter Name="LogFileAppendName" Value="False" />
19 <RuleParameter Name="Use_UniqueTestIteration" Value="False" />
20 <RuleParameter Name="Use_UniqueIteration" Value="False" />
21 <RuleParameter Name="Use_UniqueFiles" Value="False" />
22 <RuleParameter Name="Use_Unique" Value="False" />
23 <RuleParameter Name="Use_Random" Value="False" />
24 <RuleParameter Name="Use_Seq" Value="True" />
25 <RuleParameter Name="Use_Loop" Value="False" />
26 <RuleParameter Name="ThrowException" Value="False" />
27 <RuleParameter Name="Log_To_File" Value="False" />
28 <RuleParameter Name="Test_Names" Value="" />
29 <RuleParameter Name="Scenario_Names" Value="" />
30 <RuleParameter Name="Agent_Names" Value="" />
31 </RuleParameters> 16 </RuleParameters>
32 </WebTestPlugin> 17 </WebTestPlugin>
33 </WebTestPlugins> 18 </WebTestPlugins>
......