![](/img/trans.png)
[英]Using data-provider and parallel in Testng, how to run before method, after method and test in same thread for a given test.?
[英]How should I run the same test case without running the @before method from TestNG?
我应该如何在不运行 @before 方法的情况下运行相同的测试用例?
public class CommissionHistorySingledownloadTest extends TestBase
{
@FindBy(id = "UserId")
WebElement UserID;
LoginPage loginPage;
HomePage homepage;
CommissionHistorySingledownload CommissionHistory;
public CommissionHistorySingledownloadTest()
{
super();
}
@BeforeMethod
public void setUp()
{
initialization();
loginPage = new LoginPage();
homepage = loginPage.login(prop.getProperty("email"), prop.getProperty("password"));
CommissionHistory = homepage.navigate();
TestUtil.setusername();
}
@DataProvider(name="getusername")
public Iterator<Object[]> getusername() {
ArrayList<Object[]> testdata = TestUtil.getusername();
return testdata.iterator();
}
@Test(dataProvider="getusername")
public void GrandTotal_CommissionComparision(String UserName) throws InterruptedException
{
{
Double value1= null;
Double value2= null;
Double value3 =0.00;
Double sum=null;
Select user = new Select (driver.findElement(By.id("UserId")));
String u =UserName;
System.out.println(u);
user.selectByValue(u);
CommissionHistory.Common();
/*
* Select user = new Select (UserID); String u =""; user.selectByValue(u);
*/
Boolean c = CommissionHistory.verifytablepresent();
if (c==true)
{
value1 = CommissionHistory.totalCommission1();
String g= CommissionHistory.verifycommissiontables();
if (g=="0")
{
value2 = CommissionHistory.rowcount0();
}
if (g=="1")
{
value2 = CommissionHistory.rowcount0();
value3 = CommissionHistory.rowcount1();
}
else
System.out.println("g value not found");
System.out.println("Value 2: "+value2 );
System.out.println("Value 3 "+value3 );
sum =value2+value3;
System.out.println("Value 1: "+ value1);
System.out.println("Sum of Value 2 and 3 is: "+sum );
Assert.assertEquals(value1, sum,"GrandTotal_CommissionComparision Match Failed");
}
else
{
System.out.println("No data found");
}
}
}
@AfterMethod
public void tearDown()
{
driver.quit();
}
}
initialization()方法正在打开浏览器。
@DataProvider(name="getusername")会在迭代中一一给出来自excel的数据
所以我想为多个用户运行它,并且由于@before 类,它多次打开浏览器。
有什么方法可以测试多个数据而无需一次又一次地打开浏览器//?
@BeforeMethod
将为套件中的每个测试运行。 使用@BeforeClass
在所有测试之前运行一次该方法。
@BeforeClass
public void setUp() { }
您可以在 Testng 中使用 invocationCount 功能,因此它在单个线程中运行 5 次。 正如家伙建议用 @BeforeClass 替换 @beforeMethod ,如果您作为 Suite 运行,最好相应地将其更改为 @BeforeSuite 。
@Test(invocationCount = 5, threadPoolSize = 1)
public void GrandTotal_CommissionComparision(){
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.