New Web Test Plugin: Add Session Cookie
Showing
1 changed file
with
29 additions
and
0 deletions
... | @@ -52,6 +52,35 @@ namespace LIL_VSTT_Plugins | ... | @@ -52,6 +52,35 @@ namespace LIL_VSTT_Plugins |
52 | } | 52 | } |
53 | } | 53 | } |
54 | 54 | ||
55 | [DisplayName("Add Session Cookie")] | ||
56 | [Description("Adds a cookie to the webtest cookie collection for this test and all of its requests.")] | ||
57 | public class AddTestSessionCookie : WebTestPlugin | ||
58 | { | ||
59 | [DisplayName("Cookie Name"), DefaultValue(""), Description("Name of the cookie to set.")] | ||
60 | public string CookieName { get; set; } | ||
61 | [DisplayName("Cookie Value"), DefaultValue(""), Description("Value of the cookie to set.")] | ||
62 | public string CookieValue { get; set; } | ||
63 | [DisplayName("Cookie Value Parameter Name"), DefaultValue(""), Description("Parameter for the cookie value. If the parameter is not found, the Cookie Value will be used instead.")] | ||
64 | public string CookieParameter { get; set; } | ||
65 | [DisplayName("Cookie Path"), DefaultValue("/"), Description("Path for the cookie to set. Cookie will only be sent if the URL Path matches.")] | ||
66 | public string CookiePath { get; set; } | ||
67 | [DisplayName("Cookie Domain"), DefaultValue(""), Description("Domain for the cookie to set. Cookie will only be sent if the host name matches.")] | ||
68 | public string CookieDomain { get; set; } | ||
69 | [DisplayName("Skip URL Encode"), DefaultValue(false), Description("By default the cookie value is URL Encoded for transfer. This will turn it off.")] | ||
70 | public bool SkipURLEncode { get; set; } | ||
71 | public override void PreWebTest(object sender, PreWebTestEventArgs e) | ||
72 | { | ||
73 | if (!String.IsNullOrEmpty(CookieParameter) && e.WebTest.Context.ContainsKey(CookieParameter)) | ||
74 | CookieValue = e.WebTest.Context[CookieParameter].ToString(); | ||
75 | if (!SkipURLEncode) | ||
76 | { | ||
77 | CookieValue = System.Net.WebUtility.UrlEncode(CookieValue); | ||
78 | CookieName = System.Net.WebUtility.UrlEncode(CookieName); | ||
79 | } | ||
80 | e.WebTest.Context.CookieContainer.Add(new System.Net.Cookie(CookieName, CookieValue, CookiePath, CookieDomain)); | ||
81 | } | ||
82 | } | ||
83 | |||
55 | [DisplayName("Add Parameter To Reporting Name")] | 84 | [DisplayName("Add Parameter To Reporting Name")] |
56 | [Description("This request plugin will add the specified parameter to the end of the reporting name of the request")] | 85 | [Description("This request plugin will add the specified parameter to the end of the reporting name of the request")] |
57 | public class AddParameterToReportingName : WebTestRequestPlugin | 86 | public class AddParameterToReportingName : WebTestRequestPlugin | ... | ... |
-
Please register or sign in to post a comment