簡體   English   中英

TestNG多重測試類-運行其他類

[英]TestNG Multiple Test Class - Running other classes

我有一個要執行4個測試的多重Test類,但是,我要執行的4個測試是不同類文件中的不同類。 因此,我想在我的多個Test類別中一次將每個類別稱為1。 因此,代碼是在各個類中執行的,而多個Test類實際上只是根據優先級來處理每個測試的執行。 我只是不確定如何調用另一個要執行的類。

我的多班:

@Test(priority = 0) //Set Priority of Test - Priority of test always starts from Zero
    public void one() {

  System.out.println("This is Test Case 1");
    }
         //Test 2
     @Test(priority = 1) // Test priority 1
    public void Two(){

  System.out.println("This is Test Case 2");
      }

我需要在@Test塊中執行我的外部類。 自動化的新手,也許我的問題是我對Java的了解?

如何傳遞我的參數:

public class TestNGDataProvider {

  private WebDriver driver;
 private static Logger logger1 = LogManager.getLogger("Logger1");

 @Test(dataProvider = "Authentication")
 public void testMethod1(String sUsername, String sPassword, String sMemorableWord) {

  DOMConfigurator.configure("log4j.xml");

driver = new FirefoxDriver();

  logger1.info("New Instance of firefox created");
  //Add wait to allow web elements to load

  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

  logger1.info("Timeout Applied for 10 seconds to Allow Load of Elements");
  //Launch FireFoxDriver - Open WebPage

  driver.get("http://localhost/2010A15/");

  logger1.info("Website Launched");
  Reporter.log("Website Lauched Successfully  | "); //Main Event Logger/Report

  //Find Login Element
  driver.findElement(By.id("WEB_LoginButton")).click();

  logger1.info("Login Button Clicked");
  //Find User name Element

     driver.findElement(By.id("dijit_form_ValidationTextBox_1")).sendKeys(sUsername);

  logger1.info("Username Entered");

  //Find Password Element

  driver.findElement(By.id("dijit_form_ValidationTextBox_2")).sendKeys(sPassword);




     @DataProvider(name = "Authentication")
     public static Object[][] credentials() {
return new Object[][] { { "jane20@servicecharges.co.uk", "password1", "smith" }, { "rob23@orchard.co.uk", "password1", "smith" }, { "jeff23@hotmail.com", "password1", "smith" }}; 
 }}

據我了解,您已經在單獨的類文件中處理了測試邏輯,並在Main類文件中執行了測試邏輯。 因此,如果您有以下2個測試類,

public class TestLogic1
{  
   public void testMethod1()
    {
       System.out.println("Test 1 executing");
    }
}
public class TestLogic2
{  
   public void testMethod2()
    {
       System.out.println("Test 2 executing");
    }
}

然后,您可以在執行類中調用以下測試方法,

public class TestExecute
{  
   TestLogic1 method1=new TestLogic1();
   TestLogic2 method2=new TestLogic2();

   @Test(priority=1)
   public void test1()
    {
       method1.testMethod1();
    }
@Test(priority=2)
   public void test2()
    {
       method2.testMethod2();
    }
}

編輯:假設您在一個類中編寫了@Test方法和@DataProvider,並在另一類中處理了它的執行順序。 使用下面的代碼來使它與DataProvider中的參數一起使用。

 public class TestExecute{

TestNGDataProvider tg=new TestNGDataProvider();

@Test(dataProvider = "Authentication",dataProviderClass = TestNGDataProvider.class)
 public void test1(String login,String user,String pass) throws InterruptedException {

    tg.testMethod1(login,user,pass);
}
 }

希望這是您想要的。 可以在這里查看有關TestNG數據提供程序的更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM