I am using JUnit to make automation test , the context is changed to hybrid App , after tests I`m making output excel file with the result. I am new to the automation and found a way if something is not found and etc. to use try / catch block to fill the excel file with the result . Everything looks that work like a charm I think ,but I have issue when there is a long Test Case ( with a lot of test steps) , if something goes to the "catch block" the test steps in the excel file are marked as "Pass" after the "Fail" test step . Which I want to fix . Is there a way if some test step is marked as "FAIL" , all the other test steps under him to be marked also like "FAIL" or something like that .
public class LoginProcess extends Settings {
static SXSSFWorkbook workbook;
public static String[] columns = { "TestStep", "ExpectedResult", "Pass/Fail" };
public static List<TestCaseForExcel> testCases = new ArrayList<>();
@Before
public void BeforeTest() throws MalformedURLException, InterruptedException {
Capabilities();
}
@Test
public void TC_1_LoginProcess() throws MalformedURLException, InterruptedException {
try {
driver.findElement(By.xpath("/html/body/div[2]")).isDisplayed();
testCases.add(new TestCaseForExcel("Opened Customer application", "Splash screen opened", "PASS"));
} catch (Exception e) {
testCases.add(new TestCaseForExcel("Opened Customer application", "Splash screen opened", "FAIL"));
}
// Click on Login Button
try {
driver.findElement(By.className("button-simple")).click();
testCases.add(new TestCaseForExcel("Press Login button", "Login screen opened", "PASS"));
} catch (Exception e ) {
testCases.add(new TestCaseForExcel("Press Login button", "Login screen openedd", "FAIL"));
}
}
In that case if the xpath is broken , and the element is not shown , the 2nd test step is written as "PASS" ,and its not even properly checked ,because of the first test step "FAIL"