Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

java - how to validate matching values from Excel with UI, inside the for loop test and show the result in extent report

I am using Selenium with JUnit and I need to verify a Reference number and Quantity from Excel sheet against UI values, from Step 8 onwards in given for loop.

Currently it is validated inside the method which I'm using in for loop we can check through sys logs, but I need the same validations in Extent Reports.

I am already using extent report below, but it shows all the test as passed even if logs are different, only because there is no assertion.

To Summarize: How do I insert assertion to check values inside FOR LOOP and make them PASS and FAIL in Extent Report.

Test File Code:

public class TestCase extends AppTest {

    private StringBuffer verificationErrors = new StringBuffer();

    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp();
        preparation = new Prep();
        application = new AppToTest();
        user = new Environment();
    }

    @Test
    public void testLAP_Creamix() throws Exception {
        try {
            launchMainApplication();

            Test_frMain Test_frMainPage = new Test_frMain(tool, test, user, application);

            HashMap<String, ArrayList<String>> win = CreamixWindowsDataset.main();
            SortedSet<String> keys = new TreeSet<>(win.keySet());
            ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("Test_Report.html");
            ExtentReports extent = new ExtentReports();
            extent.attachReporter(htmlReporter);

            ExtentTest test1 = extent.createTest("Creamix test");

            for (String i : keys) {
                System.out.println("########### Test = " + win.get(i).get(0) + " ###########");
                Lapeyre_frMainPage.EnterTaille(win.get(i).get(1));
                Lapeyre_frMainPage.SelectCONFIGURATION(win.get(i).get(2));
                Lapeyre_frMainPage.SelectPLANVASQUE(win.get(i).get(3));
                Lapeyre_frMainPage.SelectCOULEUR(win.get(i).get(4));
                Lapeyre_frMainPage.SelectPOIGNEES(win.get(i).get(5));
                Lapeyre_frMainPage.SelectTYPE_DE_MEUBLE(win.get(i).get(6));
                Lapeyre_frMainPage.SelectCHOISISSEZ(win.get(i).get(7));

                Lapeyre_frMainPage.VerifyREFERENCE(win.get(i).get(8));(FROM HERE Validation Starts)
                Lapeyre_frMainPage.VerifyQUANTITY(win.get(i).get(9));
                Lapeyre_frMainPage.VerifyREFERENCETwo(win.get(i).get(10));
                Lapeyre_frMainPage.VerifyQUANTITYTwo(win.get(i).get(11));
                Lapeyre_frMainPage.VerifyREFERENCEThree(win.get(i).get(12));
                Lapeyre_frMainPage.VerifyQUANTITYThree(win.get(i).get(13));
                Lapeyre_frMainPage.VerifyREFERENCEFour(win.get(i).get(14));
                Lapeyre_frMainPage.VerifyQUANTITYFour(win.get(i).get(15));
                Lapeyre_frMainPage.VerifyREFERENCEFive(win.get(i).get(16));
                Lapeyre_frMainPage.VerifyQUANTITYFive(win.get(i).get(17));
                Lapeyre_frMainPage.VerifyREFERENCESix(win.get(i).get(18));
                Lapeyre_frMainPage.VerifyQUANTITYSix(win.get(i).get(19));
                Lapeyre_frMainPage.VerifyREFERENCESeven(win.get(i).get(20));
                Lapeyre_frMainPage.VerifyQUANTITYSeven(win.get(i).get(21));
                Lapeyre_frMainPage.VerifyPanierPrice(win.get(i).get(22));
                Lapeyre_frMainPage.VerifyECO_PARTPrice(win.get(i).get(23));

                Lapeyre_frMainPage.ClickCREAMIXReinit();(Reset button to test next scenario)

                test1.pass("Scenario " + win.get(i).get(0) + " is passed");
                System.out.println("########### Test End ##############");
                extent.flush();

            }

            test.setResult("pass");
        } catch (AlreadyRunException e) {
        } catch (Exception e) {
            verificationErrors.append(e.getMessage());
            throw e;
        }

    }

    @Override
    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }
}
question from:https://stackoverflow.com/questions/65661428/how-to-validate-matching-values-from-excel-with-ui-inside-the-for-loop-test-and

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Given your current code, I would suggest that you replace all the .VerifyX() methods to .GetX() methods and instead assert the two values in the script. For example,

Lapeyre_frMainPage.VerifyREFERENCE(win.get(i).get(8));

would be changed to

assertEquals("Verify REFERENCE 1", win.get(i).get(8), Lapeyre_frMainPage.GetREFERENCE());

.GetREFERENCE() would return the value from the UI instead of doing the verification.


For this to work, you need to change each of the VerifyX() methods to return the string from the UI. From your code in the comments, here's an example.

public void GetREFERENCE()
{
    return tool.searchUsingXPath("//tbody//tr[1]//td//div[2]").getText().trim();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...