Selenium Automated Validation Frameworks 2 — Questions and Answers
Question 1: In TestNG, which annotation runs a method once before all tests in a class?
- @BeforeClass (Correct answer)
- @BeforeTest
- @BeforeSuite
- @BeforeMethod
Correct answer: @BeforeClass
@BeforeClass executes a setup method once before any test method in the current class runs.
Question 2: Which JUnit 5 annotation replaces JUnit 4's @Test for parameterized inputs?
- @ParameterizedTest (Correct answer)
- @DataTest
- @TestWithParams
- @RepeatTest
Correct answer: @ParameterizedTest
@ParameterizedTest in JUnit 5 allows a test method to run multiple times with different arguments.
Question 3: What is the purpose of soft assertions in a Selenium test framework?
- Continue test execution after a failure and report all failures at the end (Correct answer)
- Stop the test immediately on first failure
- Skip the remaining assertions in a test
- Retry the assertion up to 3 times automatically
Correct answer: Continue test execution after a failure and report all failures at the end
Soft assertions collect all assertion failures and report them together after the test finishes, unlike hard assertions that stop on first failure.
Question 4: In TestNG, how do you declare that test B must run after test A?
- @Test(dependsOnMethods="testA") (Correct answer)
- @Test(runAfter="testA")
- @Test(order=2)
- @Test(sequence="testA")
Correct answer: @Test(dependsOnMethods="testA")
The dependsOnMethods attribute in @Test specifies that the annotated method depends on another named test method.
Question 5: Which AssertJ method checks that a list contains exactly the specified elements in any order?
- containsExactlyInAnyOrder() (Correct answer)
- containsOnly()
- containsExactly()
- containsAll()
Correct answer: containsExactlyInAnyOrder()
containsExactlyInAnyOrder() verifies the iterable has exactly those elements regardless of order, with no extra elements allowed.
Question 6: What does the @DataProvider annotation in TestNG return?
- Object[][] (Correct answer)
- List<Object>
- Map<String, Object>
- String[]
Correct answer: Object[][]
A @DataProvider method must return a two-dimensional Object array, where each inner array is one set of parameters for a test iteration.
Question 7: In a Page Object Model framework, where should explicit WebDriver waits be placed?
- Inside the Page Object class methods (Correct answer)
- In the test class directly
- In a global static utility only
- Inside @BeforeClass setup
Correct answer: Inside the Page Object class methods
Waits belong inside Page Object methods so the abstraction layer handles synchronization, keeping test classes clean and readable.
In TestNG, which annotation runs a method once before all tests in a class?