0
0
Selenium Javatesting~20 mins

Custom annotations in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom Annotations Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a custom annotation usage in Selenium Java
Consider the following custom annotation and its usage in a Selenium test class. What will be the output when the test method runs?
Selenium Java
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.junit.jupiter.api.Test;

@Retention(RetentionPolicy.RUNTIME)
@interface Retry {
    int value() default 1;
}

public class SampleTest {

    @Retry(3)
    @Test
    public void flakyTest() {
        System.out.println("Test executed");
    }
}
ATest executed
BTest executed printed 3 times
CCompilation error due to missing annotation processor
DRuntime error due to annotation misuse
Attempts:
2 left
💡 Hint
Custom annotations alone do not change method execution unless processed.
assertion
intermediate
2:00remaining
Assertion to verify custom annotation presence
Given a Selenium test method annotated with a custom annotation @SlowTest, which assertion correctly verifies that the method has this annotation at runtime?
Selenium Java
import java.lang.reflect.Method;

public class TestUtils {
    public static boolean hasSlowTestAnnotation(Method method) {
        // Fill in assertion here
    }
}
Areturn method.getDeclaredAnnotations().contains(SlowTest.class);
Breturn method.isAnnotationPresent(SlowTest.class);
Creturn method.getAnnotation(SlowTest.class) != null;
Dreturn method.getAnnotationsByType(SlowTest.class).length == 0;
Attempts:
2 left
💡 Hint
Use the standard Java reflection method to check annotation presence.
🔧 Debug
advanced
2:00remaining
Debugging missing retention policy in custom annotation
A custom annotation @CriticalTest is defined without specifying @Retention. When trying to detect this annotation at runtime in Selenium tests, it is always missing. What is the cause?
Selenium Java
public @interface CriticalTest {
    String value() default "";
}

// Later in test code
boolean present = testMethod.isAnnotationPresent(CriticalTest.class);
AThe annotation defaults to CLASS retention, so it is not available at runtime.
BThe annotation must be public to be detected at runtime.
CThe annotation requires @Target to specify applicable elements.
DThe annotation processor is missing, causing detection failure.
Attempts:
2 left
💡 Hint
Check the default retention policy of Java annotations.
framework
advanced
2:00remaining
Implementing retry logic using custom annotation in Selenium Java
Which approach correctly implements retry logic for a Selenium test method annotated with @Retry(count=3) using JUnit 5 extensions?
AAdd a while loop inside the test method to retry based on @Retry annotation value.
BUse @BeforeEach to loop the test method execution count times manually.
CCreate a JUnit 5 Extension that reads @Retry and reruns the test method up to count times on failure.
DUse @Test(timeout=3) to retry the test 3 times automatically.
Attempts:
2 left
💡 Hint
JUnit 5 extensions allow intercepting test execution lifecycle.
🧠 Conceptual
expert
2:00remaining
Why use custom annotations in Selenium test automation?
Which of the following best explains the main advantage of using custom annotations in Selenium test automation frameworks?
AThey enforce strict typing on test method parameters.
BThey automatically improve test execution speed without code changes.
CThey replace the need for writing assertions in test methods.
DThey allow adding metadata to tests that can be processed to modify test behavior dynamically.
Attempts:
2 left
💡 Hint
Think about how annotations can influence test execution.