[英]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.