Hybrid Framework - How to pass on the parameter from @Test to the keyword function? | Selenium Forum
P
Pravin V. Kumbhare Posted on 08/02/2022

I'm implementing the Hybrid Framework for Rediff application.

Here's my @Test verifyStockQuantity:

@Test
@Parameters({"action"})
public void verifyStockQuantity(String action, ITestContext context) throws ParseException {
ds.infoLogGen("@Test addNewStock started");
Xlsx_Reader excel=new Xlsx_Reader(System.getProperty("user.dir")+"\\src\\test\\resources\\testcases\\Testcases.xlsx");
ds.executeTest(excel, "TestCases", "verifyStockQuantity");
ds.infoLogGen("@Test addNewStock completed");

I'm implementing the function validateStockQuantity as below.

public void validateStockQuantity(String action, int quantity){
int expQty = 0;
String qtyBefTxn = (String) context.getAttribute("qtyBefTxn");
String qtyAftTxn = (String) context.getAttribute("qtyAftTxn");
if(action.equalsIgnoreCase("Buy") || action.equalsIgnoreCase("AddStock"))
expQty = Integer.parseInt(qtyBefTxn) + quantity;
else if (action.equalsIgnoreCase("Sell")) {
expQty = Integer.parseInt(qtyBefTxn) - quantity;
}
if (Integer.parseInt(qtyAftTxn) == expQty)
infoLogGen("Verified stock quantity: Quantity Before Transaction: " + qtyBefTxn + " | Quantity After Transaction: " + qtyAftTxn);
else if (Integer.parseInt(qtyAftTxn) != expQty)
reportFailure(("Verified stock quantity: Quantity Before Transaction: " + qtyBefTxn + " | Quantity After Transaction: " + qtyAftTxn), true);
}

How do I access the parameter "action" in this function?