Saturday, 20 January 2024

Exception Handling

Where you have used exception handling in your framework?

  • When asserting a value in field if user could not find the filed catch the exception and print stackrace
    • NoSuchFieldException
    • IllegalAccessException
  • When user try to expand a node and if there is a node which cannot expand catch exception and print stackrace
    • NoSuchMethodException
    • IllegalAccessException
    • InvocationTargetException

 try {

        Field m_keywordStr = comp.getClass().getDeclaredField("m_keywordTxt");
m_keywordStr.setAccessible(true);
String actual_keyword = (String) m_keywordStr.get(comp);
all_available.add(actual_keyword.trim());
if (actual_keyword.trim().equals(keyword.trim())) {
found = true;
Field m_valueStr = comp.getClass().getDeclaredField("m_valueTxt");
m_valueStr.setAccessible(true);
String actual_value = (String) m_valueStr.get(comp);
verifyEquals(actual_value, value, "Expected and Actual values not matched for the Keyword, " + keyword);
break;
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
if (!found) {
throw new ScriptException("Expected keyword NOT found in the Journal Table. Expected: " + keyword + " Available keywords: " + all_available.toString());
}


// expanding all nodes in the tree
try {
Method expandAll = tree1.getClass().getMethod("expandAll");
expandAll.invoke(tree1);
waitFor(1);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new ScriptException("Error when expanding the keywords in New Note template. " + e.getMessage());
}

No comments:

Post a Comment

Reverse Words in a Sentence