Vsts for testers Reading Notes (5)

Source: Internet
Author: User

4. Edit webtest
3. Add extraction rules and custom Extraction Rules
Add extraction rules
1. When a part of data must be captured from a specific page and used on another page, Extraction Rules must be used. You can use the Extraction Rules to copy strings from the response and store the strings in context variables for any subsequent requests. By displaying the details pane, you can check the context in the Web Test viewer.
2. webtest provides six Extraction Rules:


Custom Extraction Rules
You can create your own Extraction Rules by deriving from the extractionrule class.
1. Create a class library project for custom Extraction Rules

2. Similarly, you must add a reference to Microsoft. visualstudio. testtools. webtesting in the class library.

3. Create a slave Class. Implementation And Member. Create the myextractionrule class. An example is provided on msdn.Code:
Using system;
Using system. Collections. Generic;
Using Microsoft. visualstudio. testtools. webtesting;
Using system. Globalization;

Namespace classlibrary2
{
Public class myextractionrule: extractionrule
{

Private string name;

Public string name
{
Get {return name ;}
Set {name = value ;}
}

Public override string rulename
{
Get {return "myextractionrulename ";}
}

Public override string ruledescription
{
Get {return "myextractionruledescription ";}
}

Public override void extract (Object sender, extractioneventargs E)
{
If (E. Response. htmldocument! = NULL)
{
Foreach (htmltag tag in E. Response. htmldocument. getfilteredhtmltags (New String [] {"input "}))
{
If (string. Equals (tag. getattributevalueasstring ("name"), name, stringcomparison. invariantcultureignorecase ))
{
String formfieldvalue = tag. getattributevalueasstring ("value ");
If (formfieldvalue = NULL)
{
Formfieldvalue = string. empty;
}

E. webtest. Context. Add (this. contextparametername, formfieldvalue );
E. Success = true;
Return;
}
}
}
E. Success = false;
E. Message = string. Format (cultureinfo. currentculture, "not found: {0}", name );
}
}
}

4. Build

5. Add a reference to the test project

6. Display custom Extraction Rules in the "add Extraction Rules" dialog box.

7. Download myextractionrule demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.