Selenium 如何使用testNG执行多个测试用例

Selenium 如何使用testNG执行多个测试用例,selenium,testng,Selenium,Testng,我想了解如何使用testNg执行多个测试用例。假设我的web应用程序由10个页面组成,那么我们如何执行下面的测试用例 1) 第一个TC-遍历或导航至第1、2、3、4、5和6页 2) 第二个TC-遍历或导航至第1、2、3、8、9和10页 3) 第三个TC-遍历或导航至第1、2、6、7、8页 所有页面都有相应的优先级。第1页有优先权1,第2页有优先权2等 我们是否需要在每个@Test注释中调用相关的方法(在每个页面中定义的方法) 谢谢 如果有多个页面,则可以为每个网页设置页面对象类。该类可以有多个方

我想了解如何使用testNg执行多个测试用例。假设我的web应用程序由10个页面组成,那么我们如何执行下面的测试用例

1) 第一个TC-遍历或导航至第1、2、3、4、5和6页

2) 第二个TC-遍历或导航至第1、2、3、8、9和10页

3) 第三个TC-遍历或导航至第1、2、6、7、8页

所有页面都有相应的优先级。第1页有优先权1,第2页有优先权2等

我们是否需要在每个@Test注释中调用相关的方法(在每个页面中定义的方法)


谢谢

如果有多个页面,则可以为每个网页设置页面对象类。该类可以有多个方法,这些方法实现为可以在该页上执行的操作,并且可能返回它导航到的下一页的对象。使用页面对象类的这些对象及其方法,您可以设计将被视为测试用例的测试方法

例如。 -对于登录页面,使用页面上所有必需的元素定义Login.java,并定义方法如下

public Homepage loginAction(String Username, String Password){
      // write code to perform login opeartion
      // it returns Homepage object that you can store in Homepage type variable and you can call other operations of Homepage on that object.
}
一旦所有页面对象类都准备好使用,就可以通过调用tat方法编写测试用例

例如:


如果有多个页面,则可以为每个网页设置页面对象类。该类可以有多个方法,这些方法实现为可以在该页上执行的操作,并且可能返回它导航到的下一页的对象。使用页面对象类的这些对象及其方法,您可以设计将被视为测试用例的测试方法

例如。 -对于登录页面,使用页面上所有必需的元素定义Login.java,并定义方法如下

public Homepage loginAction(String Username, String Password){
      // write code to perform login opeartion
      // it returns Homepage object that you can store in Homepage type variable and you can call other operations of Homepage on that object.
}
一旦所有页面对象类都准备好使用,就可以通过调用tat方法编写测试用例

例如:


似乎每个页面都有一个
@Test
注释方法。如果它们能够像您提到的那样在逻辑上正确地遍历,那么要为您的测试用例运行它们,我将从TC中删除优先级,并将此xml与
preserve order=“true”
一起使用,以便它们以相同的顺序运行。您可以以相同的方式向下面添加更多TC。看看

下面的xml将按顺序调用方法,您需要确保它们可以正确地转到页面

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="yourSuiteName" >

    <test name="1stTC" preserve-order="true">

        <classes>  
         <class name="yourPackage.YourClass" >
               <methods> 
                  <include name="method1" />
                  <include name="method2" /> 
                  <include name="method3" />
                  <include name="method4" />
                   <include name="method5" />
                  <include name="method6" />
               </methods> 
          </class>
       <classes> 
      </test>

<test name="2ndTC" preserve-order="true"> 
       <classes>         
           <class name="yourPackage.YourClass">
               <methods> 
                  <include name="method1" />
                  <include name="method2" /> 
                  <include name="method3" />
                  <include name="method8" /> 
                  <include name="method9" />
                  <include name="method10" />
               </methods>
          </class>
        </classes>
    </test>
</suite>

似乎每个页面都有一个
@Test
注释方法。如果它们能够像您提到的那样在逻辑上正确地遍历,那么要为您的测试用例运行它们,我将从TC中删除优先级,并将此xml与
preserve order=“true”
一起使用,以便它们以相同的顺序运行。您可以以相同的方式向下面添加更多TC。看看

下面的xml将按顺序调用方法,您需要确保它们可以正确地转到页面

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="yourSuiteName" >

    <test name="1stTC" preserve-order="true">

        <classes>  
         <class name="yourPackage.YourClass" >
               <methods> 
                  <include name="method1" />
                  <include name="method2" /> 
                  <include name="method3" />
                  <include name="method4" />
                   <include name="method5" />
                  <include name="method6" />
               </methods> 
          </class>
       <classes> 
      </test>

<test name="2ndTC" preserve-order="true"> 
       <classes>         
           <class name="yourPackage.YourClass">
               <methods> 
                  <include name="method1" />
                  <include name="method2" /> 
                  <include name="method3" />
                  <include name="method8" /> 
                  <include name="method9" />
                  <include name="method10" />
               </methods>
          </class>
        </classes>
    </test>
</suite>