简体   繁体   English

TestNG多重测试类-运行其他类

[英]TestNG Multiple Test Class - Running other classes

I have a multiple Test class which I want to execute 4 tests, however, the 4 tests I want to execute are different classes in different class files. 我有一个要执行4个测试的多重Test类,但是,我要执行的4个测试是不同类文件中的不同类。 So I want to call each class 1 at a time in my multiple Test class. 因此,我想在我的多个Test类别中一次将每个类别称为1。 So The code is being executed in the individual classes and the multiple Test class literally just handles the execution of each test based on priority. 因此,代码是在各个类中执行的,而多个Test类实际上只是根据优先级来处理每个测试的执行。 I am just unsure how to call another class to be executed. 我只是不确定如何调用另一个要执行的类。

My multi class: 我的多班:

@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");
      }

I need to execute my external classes in the @Test blocks. 我需要在@Test块中执行我的外部类。 New to automation maybe my problem is my understand of java? 自动化的新手,也许我的问题是我对Java的了解?

How am Passing My parameters: 如何传递我的参数:

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" }}; 
 }}

As per my understanding, you have handled test logic in separate class files & executing those in Main class file. 据我了解,您已经在单独的类文件中处理了测试逻辑,并在Main类文件中执行了测试逻辑。 So if you have below 2 classes for tests, 因此,如果您有以下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");
    }
}

Then you can call, these test methods in your execution class as, 然后,您可以在执行类中调用以下测试方法,

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();
    }
}

Edit: Assuming you have written @Test method & @DataProvider in one class & handling it's execution sequence in other class. 编辑:假设您在一个类中编写了@Test方法和@DataProvider,并在另一类中处理了它的执行顺序。 Use below code to get it working with parameters from 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);
}
 }

Hope this is what you are looking for. 希望这是您想要的。 Also look here For more details on TestNG Data Providers. 可以在这里查看有关TestNG数据提供程序的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM