Reputation: 346
Coded UI Test in Visual Studio Permium 2010 - C#
I have a bunch of coded UI test and for one of them I would like to prompt the user to enter an access code, which will then be used later in the automated testing.
These are data driven tests, however the access code is not available before the testing starts. One of the automated steps is to register a user online where they receive an access code via email.
I'd like to have a prompt come up during the test where the user can enter in the access code before the automated test continues.
I considered querying the database to get the access code, but this isn't an option as the code is stored in active directory and the tester machines won't have access to that, so I'm forced to do this. Any advice would be greatly appreciated. Thanks!
Upvotes: 0
Views: 2951
Reputation: 441
Couldn't you automate the checking of the email rather than using user input or spoofing off the bat? Is the validating the sending and receiving of the email part of the testing? parameters?
In our testing we have a real dummy email account on our corporate server that we check using the Webmail interface and scrape the included password programatically. We have to loop and wait until the email arrives, although we've capped it at 5mins. If the email doesn't arrive in the given wait time, then we spoof, first failing the verification point for the email validation.
Otherwise all you'd need was for your code to popup a messagebox with a text input field to read in. Check out this thread for the how-to Messagebox with input field
Upvotes: 1
Reputation: 713
Perhaps the better solution would be to abstract your email interface for your server and in your test suite create a mock email interface that can intercept the message to receive the email with the access code. That way, you're also not dependent on network availability to run your tests.
Some code to explain what I mean:
interface IEmailAPI{
void SendMessage(string from, string to, string subject, string body);
}
class RealEmailAPI : IEmailAPI
{
System.Net.Mail.SmtpClient client;
public RealEmailAPI(string host, int port)
{
client = new System.Net.Mail.SmtpClient(host, port);
}
public void SendMessage(string from, string to, string subject, string body)
{
client.Send(from, to, subject, body);
}
}
class MockEmailAPI : IEmailAPI
{
public string LastAccessCode{get;private set;}
public void SendMessage(string from, string to, string subject, string body)
{
var findCode = new System.Text.RegularExpressions.Regex(""); // whatever this takes
LastAccessCode = findCode.Match(body).Value;
}
}
class MyServer
{
IEmailAPI emailer;
public MyServer(IEmailAPI emailSystem)
{
this.emailer = emailSystem;
}
public void SendAccessCode(string to, string code)
{
this.emailer.SendMessage("[email protected]", to, "Access Code", code);
}
}
class TestMyServer
{
public void TestAPICodeGen()
{
var email = new MockEmailAPI();
var server = new MyServer(email);
var code = "XYZZY";
server.SendAccessCode("[email protected]", code);
Assert.AreEqual(code, email.LastAccessCode);
}
}
Upvotes: 3