Skip navigation links
com.auxiliary.testcase.templet

Class AbstractCaseTemplet

    • Field Detail

      • REPLACE_WORD_SIGN

        protected final String REPLACE_WORD_SIGN
        标记用于需要替换的词语
        Since:
        autest 4.0.0
        See Also:
        Constant Field Values
      • placeholder

        protected Placeholder placeholder
        存储xml文件中所有的占位符
        Since:
        4.2.0
    • Constructor Detail

      • AbstractCaseTemplet

        protected AbstractCaseTemplet()
        定义无参构造,方便子类使用
        Since:
        autest 4.0.0
    • Method Detail

      • addReplaceWord

        public void addReplaceWord(String word,
                                   String replaceWord)
        Description copied from interface: AddPlaceholder
        该方法用于添加被替换的词语以及替换的内容
        Specified by:
        addReplaceWord in interface AddPlaceholder
        Parameters:
        word - 需要替换的内容
        replaceWord - 替换后的内容
      • addReplaceFunction

        public void addReplaceFunction(String regex,
                                       DataFunction function)
        Description copied from interface: AddPlaceholder
        用于添加待替换的词语及相应的替换方法

        该方法允许添加待替换词语的处理方式,在写入用例时,若指定的待替换内容符合此方法指定的正则时,则会使用存储的替换方式, 对词语进行替换。例如,占位符前后标志均为“#”,则:

          @Test
         public void addReplaceWordTest_DataDriverFunction() {
          // 定义词语匹配规则和处理方式,当匹配到正则后,将获取“随机:”后的字母
          // 若字母为“N”,则随机生成两位数字字符串
          // 若字母为“Y”,则随机生成两位中文字符串
          test.addReplaceWord(new DataDriverFunction("随机:[NC]", text -> {
              return "N".equals(text.split(":")[1]) ? RandomString.randomString(2, 2, StringMode.NUM)
                      : RandomString.randomString(2, 2, StringMode.CH);
          }));
         }
         

        部分定义方法可调用工具类Functions类获取,以其中一个方法为例,其传参方法为如下:

         DataDriverFunction driverFunction = Functions.randomCarId();
         addReplaceFunction(DataDriverFunction.getRegex(), DataDriverFunction.getFunction());
         

        Specified by:
        addReplaceFunction in interface AddPlaceholder
        Parameters:
        regex - 需要替换的内容正则表达式
        function - 替换词语使用的函数
      • getPlaceholder

        public Placeholder getPlaceholder()
        该方法用于返回当前存储的占位符类对象
        Returns:
        占位符类对象
        Since:
        autest 4.2.0

Copyright © 2024. All rights reserved.