首页 > 解决方案 > 如何使用 IAnnotationTransformer 在 testng xml 中获取测试名称或参数名称?

问题描述

我想用变压器类设置组名,但是在类中 testName 为空。我怎样才能得到你能帮助我吗?

这是我的 xml 文件

<test name="Firefox">
            <parameter name="browser" value="firefox"/>
            <groups>
                <run>
                    <include name="zalenium"/>
                </run>
            </groups>
            <classes>
                <class
                        name="demo.RunnerTest"/>
            </classes>
        </test>

和我的transformerClass

public class MyTransformer implements IAnnotationTransformer {

    @Override
    public void transform(ITestAnnotation annotation, Class testClass,
                          Constructor testConstructor, Method testMethod) {
        System.out.println(annotation.getTestName());
        if (annotation.getTestName() == "Firefox") {
            String grps[] = new String[]{"regression"};
            annotation.setGroups(grps);
            System.out.println("groups..." + Arrays.toString(annotation.getGroups()));

            //prints groups...[regression]

        }
    }
}

现在在 ss 中的 testName

标签: javaseleniumtestng

解决方案


推荐阅读