当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Repeating TestNG Selenium Test Cases (then repeating them again)

问题描述:

I am working on automating testing for a website using TestNG and selenium. This website handles data for a bunch of schools.

Currently, I am using the @Parameters annotation to repeat my tests across all browsers. However, I have certain test classes that need to be rerun for multiple schools (on top of being rerun for multiple browsers).

To be more specific, let's say I have this SchoolTest.java test class. I need to have this entire class rerun for each of 3 schools, and then each of those 3 schools rerun for each browser, for a total of 6 repeats (2*3).

How can I accomplish this? Pseudo code of what I am trying to accomplish is below.

For each browser

for each school

run TestNG test class.

网友答案:

Keeping your current code unchanged you can have this solution. Create separate test for the schools and the browser and pass them as parameters so in this case you will end up with six tests in testng.xml

    `<suite name="Parallel test runs" parallel="tests" thread-count="2">

    <test name="T_01">
    <parameter name="browser" value="chrome"/>
   <parameter name="SCHOOL" value="name1"/>

        <classes>
            <class name="testNG.Parallel.Test01" ></class>
        </classes>
    </test>

    <test name="T_02">
    <parameter name="browsername" value="ff"/>
    <parameter name="SCHOOL" value="name1"/> 
       <classes>
            <class name="testNG.Parallel.Test01" ></class>
        </classes>
    </test>
     <test name="T_03">
    <parameter name="browser" value="chrome"/>
   <parameter name="SCHOOL" value="name2"/>

        <classes>
            <class name="testNG.Parallel.Test01" ></class>
        </classes>
    </test>

    <test name="T_04">
    <parameter name="browsername" value="ff"/>
    <parameter name="SCHOOL" value="name2"/> 
       <classes>
            <class name="testNG.Parallel.Test01" ></class>
        </classes>
    </test>
    </suite>`

Or else you can have 3 @test methods for the schools and then create 2 tests in testng.xml and pass the browser as parameter.

分享给朋友:
您可能感兴趣的文章:
随机阅读: