【问题标题】:How should I run the same test case without running the @before method from TestNG?如果不从 TestNG 运行 @before 方法,我应该如何运行相同的测试用例?
【发布时间】:2020-01-13 12:52:24
【问题描述】:

我应该如何运行相同的测试用例而不运行@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")会在Iteration中一一给出excel中的数据

所以我想为多个用户运行它,并且由于 @before 类而多次打开浏览器。

有什么方法可以在不反复打开浏览器的情况下测试多个数据//?

【问题讨论】:

    标签: java selenium testng


    【解决方案1】:

    @BeforeMethod 将为套件中的每个测试运行。在所有测试之前使用@BeforeClass 运行该方法一次。

    @BeforeClass
    public void setUp() { }
    

    【讨论】:

      【解决方案2】:

      您可以在 Testng 中使用 invocationCount 功能,所以这里它在单个线程中运行 5 次。正如家伙建议的那样,用@BeforeClass 替换@beforeMethod ,如果您作为套件运行,最好将其更改为 @BeforeSuite 。

       @Test(invocationCount = 5, threadPoolSize = 1)
          public void GrandTotal_CommissionComparision(){
      
          }
      

      【讨论】:

        猜你喜欢
        • 2014-11-25
        • 2019-04-12
        • 2015-03-21
        • 1970-01-01
        • 1970-01-01
        • 2018-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多