zoukankan      html  css  js  c++  java
  • VSTS For Testers读书笔记(4)

    四、编辑WebTest
    1、QueryString Parameters & Form Post Parameters
    2、添加验证规则和自定义验证规则


    1、QueryString Parameters & Form Post Parameters查询字符串参数和窗体发布参数

    查询字符串参数一般是URL中如XXX.asp?问号后的内容,窗体发布参数是请求页面中Form中的内容,同时也可以
    提取出隐藏的窗体参数,如AllGiftPwds={{$HIDDEN1.AllGiftPwds}},这些参数可以使用数据绑定来进行参数化,在后面会介绍到。

    2、添加验证规则和自定义验证规则

    添加验证规则:
          预定义的规则包括以下几个:
    查找文本
    窗体区域
    最大请求时间
    请求属性值
    所需的标记
         
          验证级别
          可以使用请求的“验证级别”来控制在特定负载测试中使用哪些验证规则。可以将每个规则的验证级别设置为“低”、“中”或“高”。通常,所设置的验证级别越高,测试的运行速度就越慢。
    见下图:
          
          验证规则的执行对性能有一定影响。
     将负载测试设置设为“低”可执行最少的请求设置级别,适合重载测试和压力运行。将负载测试设置设为“高”可执行最多的规则,适合轻量负载测试期间使用。

    自定义验证规则:
       通过从 ValidationRule 类派生,可以创建自己的验证规则。
    在VSTS For Testers中提供了Test API,因此可以通过建立类库,生成dll文件引用。
    1、创建一个自定义验证规则的类库项目

    2、在该类库项目中,添加一个对 Microsoft.VisualStudio.TestTools.WebTesting.dll 的引用。


    3、创建一个从 ValidationRule 类派生的类。实现 ValidateRuleName 成员。创建CustomValidateTag类,MSDN上提供了示例代码:
    using System;
    using System.Diagnostics;
    using System.Globalization;
    using Microsoft.VisualStudio.TestTools.WebTesting;

    namespace SampleWebTestRules
    {

    //*******************************************************************
    //The Required Tag Validation Rule is used to check that an HTML tag
    // with a particular name is found one or more times in the HTML
    // response.
    //********************************************************************
    public class CustomValidateTag : ValidationRule
    {

    //*********************************************************************
    // Name of the HTML tag that must exist in the HTML document in order
    // for the validation rule to succeed.
    //*********************************************************************
        public string RequiredTagName
        {
            get { return requiredTagName; }
            set { requiredTagName = value; }   
        }

    //*********************************************************************
    // The minimum number of times the HTML tag that must exist in the HTML
    // document for the validation rule to succeed.
    // ********************************************************************
        public int MinOccurrences
        {
            get { return minOccurrences; }
            set { minOccurrences = value; }
        }
       
    //***************************************************************
    /// Specify a user readable name for use in the user interface.
    //*****************************************************************
        public override string RuleName
        {
            get { return "Custom Validate Tag"; }
        }

        public override string RuleDescription
        {
            get { return "Validates that the specified tag exists on the page."; }
        }

       //*******************************************************************
    // Validate is called with the test case Context and the
    // request Context.
    // These allow the rule to examine both the request and the response
    // and make sure that the data matchs the required values.
    //********************************************************************
        public override void Validate(object sender, ValidationEventArgs e)
        {
            bool validated = false;

            int numTagsFound = 0;
            foreach (HtmlTag tag in e.Response.HtmlDocument.GetFilteredHtmlTags(requiredTagName))
            {
                Debug.Assert(string.Equals(tag.Name, requiredTagName, StringComparison.InvariantCultureIgnoreCase));
                if ( ++numTagsFound >= minOccurrences )
                {
                    validated = true;
                    break;
                }
            }

            e.IsValid = validated;

        // On failure, set the errorText
            if ( !validated )
            {
                if (numTagsFound > 0)
                {
                    e.Message = String.Format("Only found {0} occurences of the tag", numTagsFound);
                }
                else
                {
                    e.Message = String.Format("Did not find any occurances of tag '{0}'", requiredTagName);
                }
            }
        }

    //*******************************************************************
    // Private Members
    //*********************************************************************
    // Name of the tag required
        private string      requiredTagName;
    // Minimum number of times the tag must appear
        private int         minOccurrences;
    }
    }

    4、Build类库,生成dll文件


    5、在测试项目中,添加对包含自定义验证规则的类库项目的引用。


    6、在“添加验证规则”对话框中就可以显示自定义验证规则


    7、CustomeValidateTag Demo下载。

    OscarXie.net

    关注质量与体验——电子商务与自动化测试
    http://www.cnblogs.com/oscarxie/

  • 相关阅读:
    Linux 学习 step by step (1)
    ubuntu server nginx 安装与配置
    ubuntu server samba服务器配置
    iOS app集成支付宝支付流程及后台php订单签名处理
    mac 连接windows 共享内容
    linux 文件查找,which,whereis,locate,find
    ubuntu server vsftpd 虚拟用户及目录
    ubuntu server 安装 mantis bug tracker 中文配置
    ubuntu server vsftpd 匿名用户上传下载及目录设置
    linux 用户管理,用户权限管理,用户组管理
  • 原文地址:https://www.cnblogs.com/oscarxie/p/715665.html
Copyright © 2011-2022 走看看