简体   繁体   English

我应该如何在不运行 TestNG 的 @before 方法的情况下运行相同的测试用例?

[英]How should I run the same test case without running the @before method from TestNG?

How should I run the same test case without running the @before method?我应该如何在不运行 @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() method is opening the browser. initialization()方法正在打开浏览器。

@DataProvider(name="getusername") will give data from excel one by one in Iteration @DataProvider(name="getusername")会在迭代中一一给出来自excel的数据

So I want to run it for multiple users and it is opening the browser multiple times because of @before class.所以我想为多个用户运行它,并且由于@before 类,它多次打开浏览器。

Is there any way in which I can test the multiple data without opening the browser again and again //?有什么方法可以测试多个数据而无需一次又一次地打开浏览器//?

@BeforeMethod will run for every test in the suite. @BeforeMethod将为套件中的每个测试运行。 Use @BeforeClass to run the method once before all tests.使用@BeforeClass在所有测试之前运行一次该方法。

@BeforeClass
public void setUp() { }

You can use invocationCount feature in Testng, so here it's running 5 times in a single thread .您可以在 Testng 中使用 invocationCount 功能,因此它在单个线程中运行 5 次。 As guy suggested replace @beforeMethod with @BeforeClass , if you are running as a Suite , better to change it to @BeforeSuite accordingly .正如家伙建议用 @BeforeClass 替换 @beforeMethod ,如果您作为 Suite 运行,最好相应地将其更改为 @BeforeSuite 。

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

    }

暂无
暂无

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

相关问题 在Testng中使用数据提供程序和并行方法,如何在给定测试的同一线程中在方法之前,方法之后和测试中运行? - Using data-provider and parallel in Testng, how to run before method, after method and test in same thread for a given test.? TestNG - 如何在每次测试结束时运行相同的方法 - TestNG - how to run the same method at the end of each test 如果测试用例在 testNG 中失败,如何运行 class - How to run class if test case failed in testNG 如何禁止测试在 TestNG 的子类中运行? - How do I disable a test from running in a subclass in TestNG? 如何在仅使用TestNG的特定测试案例之前运行特定方法? - How to run specific method before of only specific test cases using TestNG? TestNG如何在每个测试用例中使用DataProvider之前重新初始化它? - TestNG How to reinitialize DataProvider before it is used in each test case? 从testng.xml运行测试用例时,如何解决SessionID = null问题 - How to resolve the SessionID=null issue when running the test case from testng.xml 如何在多个并行线程中运行单个 testng 测试用例 - How to run a single testng test case in multiple parallel threads 如何配置 TestNG 在 IntelliJ 中只运行一个测试用例? - How to configure TestNG to run just a single test case in IntelliJ? 从Java main方法调用时如何确定TestNG测试用例的优先级 - How to prioritize TestNG test case when called from java main method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM