带有 testng 和 POI 的数据提供者读取 excel 表并对不匹配的发票行执行 7 个步骤,而匹配发票编号仅执行 2 个步骤

问题描述 投票:0回答:0

我有下面的测试读取一个 excel 发票文件,发票 ID 作为列之一。它是一个排序表,因此某些行可能具有相同的发票编号。我需要为每个不同的发票号运行 7 个步骤,但如果发票与之前的发票号匹配,则只执行第 6 步和第 7 步。目前,下面的代码适用于不同的行。我需要合并具有相同发票编号的多个订单项。请帮助。

公共类 DataStagingPOM {

WebDriver driver;
public LoginPage login;
public EPCInvoiceDashboard epcInvDashboard;
public CommonPageElements commonPageElements;   

String multipleLineInvoiceNumber = null;
String homepageURL = "https://portal-int.a********/";
String epcURLInvoiceSite = "https://portal-int.*************/";


@SuppressWarnings("deprecation")
@BeforeMethod
public void setUp() {       
    System.setProperty("webdriver.chrome.driver", "C:chromedriver.exe");
    System.setProperty("webdriver.http.factory", "jdk-http-client");


    
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("--remote-allow-origins=*");

    driver = new ChromeDriver();    
    driver.manage().window().maximize();
    
    driver.get(homepageURL);
    driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);


}

@SuppressWarnings({ "deprecation", "deprecation" })
@Test(dataProvider = "Login", dataProviderClass = DataProviderReadFromExcelInvoice.class)
public void loginAndExcecuteSteps(String INVOICE_ID, String DTL_INVOICE_ID, String INV_SRVC_PRVDR_ID, String INV_ELEC_FILE_IND, String INVOICE_BUS_PARTY_CD, String INV_BUS_PARTY_ID, String EMAIL_ADDR, String DTL_INV_FUND_REQ_SEQ_NO,String DTL_BILL_FRQ_CD, String DTL_CUSTOMER_BILLED_DT, String DTL_CUS_SRVC_PROD_DLVRY_DT, String DTL_INV_TOT_UNDISCOUNTED_AMT, String DTL_INV_REQ_AMT, String PAYEE_ID) throws InterruptedException {


    System.out.println("Invoice Number: " +INVOICE_ID); 
    System.out.println("Email Number: " +EMAIL_ADDR);   
    String year = null;
    multipleLineInvoiceNumber = DTL_INVOICE_ID;
    
    login = new LoginPage(driver);
    login.loginWithValidEmail(EMAIL_ADDR); //STEP 1

    commonPageElements = new CommonPageElements(driver);            
    commonPageElements.landingPageTitle(INVOICE_BUS_PARTY_CD);

    driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);

    epcInvDashboard = new EPCInvoiceDashboard(driver);
    epcInvDashboard.navigateToEPCInvoiceSite();
    
    commonPageElements.moveFocusToNewTab();
    System.out.println(driver.getCurrentUrl());
    String invoiceBusPartyCD = epcInvDashboard.identifyApplicantOrServiceProvider(INVOICE_BUS_PARTY_CD);
    
    System.out.println(invoiceBusPartyCD);
    
    if (invoiceBusPartyCD.equals("APPLICANT")) {
        epcInvDashboard.searchApplicantAndClickFileLink(INV_BUS_PARTY_ID); //STEP 2
        epcInvDashboard.saveAndContinueFCC472Bear(PAYEE_ID, INVOICE_ID); //STEP3
        year = epcInvDashboard.returnYearFromExcel(DTL_INV_FUND_REQ_SEQ_NO); //STEP4
        epcInvDashboard.selectYearFromDropdown(year); //STEP 5
        

/***如果发票编号与下一行发票编号匹配,则重复下面的第 6 步和第 7 步,否则运行所有步骤。示例第 1-5 行具有相同的发票,然后第一行执行所有步骤,但接下来的 4 个发票将仅执行第 6 步和第 7 步。第 6 行将再次执行所有步骤,如果下一行匹配发票编号而不是第 6 步和第 7 步。行号保持不变,所以我从上次执行的继续。/

        epcInvDashboard.searchFRNNumberAndClickResultRow(DTL_INV_FUND_REQ_SEQ_NO); //STEP 6
        epcInvDashboard.addNewInvoiceLine(DTL_INV_TOT_UNDISCOUNTED_AMT, DTL_INV_REQ_AMT, DTL_BILL_FRQ_CD, DTL_CUSTOMER_BILLED_DT, DTL_CUS_SRVC_PROD_DLVRY_DT); //STEP 7
        
    }
    else if (invoiceBusPartyCD.equals("SERVICE PROVIDER"))
    {
        epcInvDashboard.searchServiceProviderAndClickFileLink(INV_SRVC_PRVDR_ID);
        epcInvDashboard.saveAndContinueFCC474SPI(INVOICE_ID);
        year = epcInvDashboard.returnYearFromExcel(DTL_INV_FUND_REQ_SEQ_NO);
        epcInvDashboard.selectYearFromDropdown(year);

/***如果发票编号与下一行发票编号匹配,则重复下面的第 6 步和第 7 步,否则运行所有步骤。示例第 1-5 行具有相同的发票,然后第一行执行所有步骤,但接下来的 4 个发票将仅执行第 6 步和第 7 步。第 6 行将再次执行所有步骤,如果下一行匹配发票编号而不是第 6 步和第 7 步。行号保持不变,所以我从上次执行的继续。/

        epcInvDashboard.searchFRNNumberAndClickResultRow(DTL_INV_FUND_REQ_SEQ_NO);
        epcInvDashboard.addNewInvoiceLine(DTL_INV_TOT_UNDISCOUNTED_AMT, DTL_INV_REQ_AMT, DTL_BILL_FRQ_CD, DTL_CUSTOMER_BILLED_DT, DTL_CUS_SRVC_PROD_DLVRY_DT);
    }
    else
        System.out.println("Neither APPLICANT or SERVICE PROVIDER matched!!!");

}


@AfterMethod
public void tearDown() {
    
    System.out.println("-----------------------------------------------------------");
    System.out.println("-----------------------------------------------------------");

    //if (driver != null)
    //  driver.quit();
}


    

}

目前,上述代码适用于不同的行/发票编号。我需要合并具有相同发票编号的多个订单项。请帮忙。我编写了 dataproviderclass 和 util 类,需要知道如何在 dataprovider 测试类中保留行信息,我是否需要两种测试方法,即

@Test(dataProvider = "Login", dataProviderClass = DataProviderReadFromExcelInvoice.class)
public void loginAndExcecute5Steps() 

@Test(dataProvider = "Login", dataProviderClass = DataProviderReadFromExcelInvoice.class)
public void loginAndExcecute6and7Steps(String INVOICE_ID, String DTL_INVOICE_ID, String 
excel apache-poi testng testng-dataprovider
© www.soinside.com 2019 - 2024. All rights reserved.