Exceptions You have Handled in Your previous automation project

When the user needs to read and get the data from a file but cannot read the file due to some issues how to handle it?

  • Throw new exception
  • Catch the exception and print stackrace
private String readFileAsString(String filePath) {
try {
return new String(Files.readAllBytes(Paths.get(filePath)));
} catch (Exception e) {
throw new RuntimeException("Failed to read file: " + filePath, e);
}
}

When the user cannot find the note in the note view. It can be that the note is not displayed totally or the note number we are using exceeds the number of notes displayed in the note view

  •  It gives ArrayIndexOutOfBoundException
  • As the solution uses a try-catch block
  • Print the stack trace with the proper message

When we add explicit waiting in the script. However, the user's expected condition is not fulfilled within the duration. What can we do?

  • Use try-catch block
  • Catch the timeout exception and print the stack trace

When creating a new file 

  • Use try-catch block
  • If the user cannot create the file print information about the exception
  • IOException

When Reading a File 

  • Use try-catch block
  • If the user cannot find the file print information about the exception
  • FileNotFoundException

When expanding a tree node

  • We are using the template with keywords
  • Keywords can be in a parent-child hierarchy
  • Parent keywords come as collapsed default
  • So we have to expand to select the child keyword
  • NoSuchMethodException
  • IllegalAccessException
  • InvocationTargetException
  • We can throw new customized exceptions with proper message










    

Comments

Popular posts from this blog

False Positive

100% Percent Test Coverage