Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In one of my project I need to handle captcha string in order to create test data of 6000 + records for every run and I need to run this test at least 10+ times for every release. But the problem is this site got enabled captcha to create pre-requisite script. Following are the way you can handle captch for testing purpose
- Ask Dev if they can disable captcha during testing
- Ask Dev to pass same value everytime if possible until you complete testing
- Write plugin as follows (you need to get Security Key from Dev) - attach it to webtest and replace the value with the cpatcha value. In my project I had followed this approach to simulate production scenario
Plugin Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Security.Cryptography;
namespace MyCustomClass
{
public class HandleCaptcha : Microsoft.VisualStudio.TestTools.WebTesting.WebTestRequestPlugin
{
public override void PostRequest(object sender, Microsoft.VisualStudio.TestTools.WebTesting.PostRequestEventArgs e)
{
base.PostRequest(sender, e);
if (e.WebTest.Context.ContainsKey("Captcha"))
{
string Captcha = e.WebTest.Context["Captcha"].ToString();
Captcha = System.Web.HttpUtility.UrlDecode(Captcha);
e.WebTest.Context["Captcha"] = Decrypt(Captcha, true);
}
}
public static string Decrypt(string decryptValue, bool useHashing)
{
//Impliment your logic here based on the the algorithme that your dev has used
return decryptValue;
}
}
Attach this plugin and provide the value in Form post parameters/String Body/Query String Parameter or whereever requireired as follows