0
0
Selenium Javatesting~10 mins

TestNG annotations (@Test, @BeforeMethod, @AfterMethod) in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to mark the method as a test method using TestNG.

Selenium Java
public class SampleTest {
    [1]
    public void testLogin() {
        // test code here
    }
}
Drag options to blanks, or click blank then click option'
A@BeforeMethod
B@BeforeClass
C@Test
D@AfterMethod
Attempts:
3 left
💡 Hint
Common Mistakes
Using @BeforeMethod or @AfterMethod instead of @Test for test methods.
Forgetting to add any annotation.
2fill in blank
medium

Complete the code to run setup code before each test method.

Selenium Java
public class SampleTest {
    [1]
    public void setup() {
        // setup code here
    }

    @Test
    public void testLogin() {
        // test code here
    }
}
Drag options to blanks, or click blank then click option'
A@BeforeMethod
B@AfterMethod
C@Test
D@BeforeClass
Attempts:
3 left
💡 Hint
Common Mistakes
Using @BeforeClass which runs only once before all tests.
Using @AfterMethod which runs after tests.
3fill in blank
hard

Fix the error in the code to run cleanup code after each test method.

Selenium Java
public class SampleTest {
    @BeforeMethod
    public void setup() {
        // setup code
    }

    @Test
    public void testLogin() {
        // test code
    }

    [1]
    public void cleanup() {
        // cleanup code
    }
}
Drag options to blanks, or click blank then click option'
A@Test
B@BeforeMethod
C@BeforeClass
D@AfterMethod
Attempts:
3 left
💡 Hint
Common Mistakes
Using @BeforeMethod instead of @AfterMethod for cleanup.
Using @Test annotation on cleanup method.
4fill in blank
hard

Fill both blanks to run setup before and cleanup after each test method.

Selenium Java
public class SampleTest {
    [1]
    public void setup() {
        // setup code
    }

    @Test
    public void testLogin() {
        // test code
    }

    [2]
    public void cleanup() {
        // cleanup code
    }
}
Drag options to blanks, or click blank then click option'
A@BeforeMethod
B@Test
C@AfterMethod
D@BeforeClass
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up @BeforeMethod and @AfterMethod annotations.
Using @BeforeClass which runs only once before all tests.
5fill in blank
hard

Fill all three blanks to create a test class with setup, test, and cleanup methods correctly annotated.

Selenium Java
public class SampleTest {
    [1]
    public void setup() {
        // setup code
    }

    [2]
    public void testLogin() {
        // test code
    }

    [3]
    public void cleanup() {
        // cleanup code
    }
}
Drag options to blanks, or click blank then click option'
A@BeforeMethod
B@Test
C@AfterMethod
D@BeforeClass
Attempts:
3 left
💡 Hint
Common Mistakes
Annotating test method with @BeforeMethod or @AfterMethod.
Forgetting to annotate setup or cleanup methods.