0
0
Selenium Javatesting~10 mins

Data providers for parameterization 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 declare a DataProvider method in TestNG.

Selenium Java
import org.testng.annotations.DataProvider;

@DataProvider(name = "testData")
public Object[][] [1]() {
    return new Object[][] {
        {"user1", "pass1"},
        {"user2", "pass2"}
    };
}
Drag options to blanks, or click blank then click option'
AfetchData
BdataProvider
CprovideData
DgetData
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid method names or keywords as method names.
Forgetting to annotate the method with @DataProvider.
2fill in blank
medium

Complete the test method annotation to use the DataProvider named "testData".

Selenium Java
import org.testng.annotations.Test;

@Test(dataProvider = [1])
public void loginTest(String username, String password) {
    // test code here
}
Drag options to blanks, or click blank then click option'
A"dataProvider"
B"userPass"
C"testData"
D"loginData"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the method name instead of the DataProvider name.
Forgetting to put the name in quotes.
3fill in blank
hard

Fix the error in the DataProvider method signature to make it valid.

Selenium Java
@DataProvider(name = "loginData")
public [1] loginData() {
    return new Object[][] {
        {"admin", "1234"},
        {"guest", "guest"}
    };
}
Drag options to blanks, or click blank then click option'
AObject[][]
Bvoid
CString[][]
Dint[][]
Attempts:
3 left
💡 Hint
Common Mistakes
Using void as return type.
Using primitive arrays like int[][] instead of Object[][].
4fill in blank
hard

Fill both blanks to correctly link the DataProvider to the test method and accept parameters.

Selenium Java
@Test(dataProvider = [1])
public void [2](String user, String pass) {
    System.out.println("User: " + user + ", Pass: " + pass);
}
Drag options to blanks, or click blank then click option'
A"loginData"
BloginTest
C"testData"
DdataTest
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching DataProvider names.
Incorrect method names that do not follow Java naming rules.
5fill in blank
hard

Fill all three blanks to create a DataProvider method and a test method that uses it with parameters.

Selenium Java
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

@DataProvider(name = [1])
public Object[][] [2]() {
    return new Object[][] {
        {"admin", "admin123"},
        {"user", "user123"}
    };
}

@Test(dataProvider = [3])
public void verifyLogin(String username, String password) {
    System.out.println(username + " logs in with " + password);
}
Drag options to blanks, or click blank then click option'
A"userData"
BuserData
DuserDataProvider
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in @DataProvider and @Test annotations.
Putting quotes around method names.