0
0
Selenium Javatesting~5 mins

Custom annotations in Selenium Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a custom annotation in Java testing?
A custom annotation is a user-defined marker or metadata that you create to add extra information to your test code, which can be processed at runtime or compile time to influence test behavior.
Click to reveal answer
beginner
How do you define a custom annotation in Java?
You define a custom annotation using the @interface keyword, specify retention policy (like RUNTIME), and optionally target elements (like METHOD or FIELD).
Click to reveal answer
intermediate
Why use custom annotations in Selenium tests?
Custom annotations help organize tests, add metadata like test priority or author, and enable reusable logic such as custom waits or setup steps, making tests cleaner and easier to maintain.
Click to reveal answer
intermediate
What is the RetentionPolicy.RUNTIME in custom annotations?
RetentionPolicy.RUNTIME means the annotation is available during runtime via reflection, allowing test frameworks to read and act on the annotation while tests run.
Click to reveal answer
beginner
Give an example of a simple custom annotation for marking tests as 'Critical'.
Example:

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface CriticalTest {
  String value() default "";
}

This annotation can be placed on test methods to mark them as critical.
Click to reveal answer
Which keyword is used to create a custom annotation in Java?
A@interface
B@annotation
Cinterface
D@custom
What does RetentionPolicy.RUNTIME mean for a custom annotation?
AAnnotation is available only in source code
BAnnotation is available at runtime via reflection
CAnnotation is discarded after compilation
DAnnotation is only for documentation
Why might you use custom annotations in Selenium tests?
ATo add metadata and control test execution
BTo replace WebDriver entirely
CTo write CSS selectors
DTo compile Java code faster
Which Java package is commonly used to access annotations at runtime?
Ajava.util.stream
Bjava.io
Cjava.lang.reflect
Djava.net
What element type would you specify to apply a custom annotation only to methods?
AElementType.FIELD
BElementType.TYPE
CElementType.PARAMETER
DElementType.METHOD
Explain how to create and use a custom annotation in Selenium Java tests.
Think about how annotations add metadata and how Selenium tests can read them.
You got /5 concepts.
    Describe the benefits of using custom annotations in test automation.
    Consider how annotations help manage many tests in a project.
    You got /5 concepts.