【发布时间】:2015-12-22 09:43:46
【问题描述】:
我有一个多个测试类,我想执行 4 个测试,但是,我想执行的 4 个测试是不同类文件中的不同类。所以我想在我的多个测试类中一次调用每个类 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" }};
}}
【问题讨论】:
-
那么,您有 4 个 diff 类和 4 种测试方法,并且您希望所有测试类都应该根据优先级运行所有 4 个测试用例,对吗?
标签: java selenium selenium-webdriver testng