开发者

Problems in creating a webtest to test logins

I'm needing some help with a coded web test.

I created a coded web test to see how many accounts are valid to log into my application. I have a lot of accounts (2000+) and I need to know which of them are valid. Basically, I recorded a web test that hits an URL and searches for some certain text that appears in the page after the login. Then I created an xml file containing all account names and passwords and set it as credentials data source. Then modified the testrun.testrunconfig to specify "one test per datasource row" to have the test run for every row in the xml file.

After this, I converted the test to a "coded" web test. So far so good. The problem arises when I try to create a file (to programmatically add the successful logins in a file). I have a StreamWriter declared privately and try to initialize it in the test constructor, but this throws an error: "could not run webtest xxx on agent yyy: exception has been thrown by the target of an invocation". I tried to initialize the stream in the same line where it's declared, but I get the same results.

Does anyone have any idea on how can I accomplish the desired test? I know that I can accomplish this without a coded web test, but to collect the successful login information I have to go line by line in the test result开发者_如何学Go and see what are the ones that passed. If anyone has a better idea, it's very welcomed!

Best regards

Beto


You can certainly achieve what you are asking, since I have also implemented a similar test.

There must be an error in your code that is causing that exception at runtime.

Instead of using controller/agent rig, try running the test locally first, so that you might get a better error message than the generic "could not run webtest".

Alternatively, if you posted the code perhaps someone could spot the error.


I would follow agentnega's suggestion to run the test locally in order to get a more clear message for the error. Maybe there is something wrong with the file path.

Besides this, I would keep the test as recorded, instead of converting it to a coded one. I would set a context variable to the path of the file that will have the successful logins at the end, preferably relative to the test deployment directory. Then write a request plugin class, derived from WebTestRequestPlugin, and override the PostRequest() method in way similar to this one:

public override void PostRequest(object sender, PostRequestEventArgs e)
{
    if(Outcome.Pass == e.Request.Outcome)
    {
        string path = Path.Combine(e.WebTest.Context["$TestDeploymentDir"].ToString(), e.WebTest.Context["logins.txt"].ToString());

        StreamWriter sw = null;
        if (!File.Exists(path)) 
        {
            sw = File.CreateText(path);
        }
        else
        {
            sw = File.AppendText(path);
        }
        sw.WriteLine(e.WebTest.Context["Username"]);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜