0
0
Selenium Pythontesting~10 mins

Parameterized tests in Selenium Python - Interactive Code Practice

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

Complete the code to import the parameterized decorator from the correct module.

Selenium Python
from [1] import parameterized

class TestLogin:
    @parameterized.expand([
        ("user1", "pass1"),
        ("user2", "pass2")
    ])
    def test_login(self, username, password):
        pass
Drag options to blanks, or click blank then click option'
Aparameterized
Bunittest
Cpytest
Dselenium
Attempts:
3 left
💡 Hint
Common Mistakes
Importing parameterized from unittest or selenium instead of the parameterized module.
2fill in blank
medium

Complete the code to use the parameterized decorator to run the test with multiple username and password pairs.

Selenium Python
@parameterized.expand([
    ("user1", "pass1"),
    ("user2", [1])
])
def test_login(self, username, password):
    pass
Drag options to blanks, or click blank then click option'
A"pass3"
B"password"
C"pass2"
D"1234"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a password not matching the test data pairs.
3fill in blank
hard

Fix the error in the test method signature to accept parameters from the parameterized decorator.

Selenium Python
@parameterized.expand([
    ("user1", "pass1"),
    ("user2", "pass2")
])
def test_login(self, [1]):
    pass
Drag options to blanks, or click blank then click option'
Ausername, password
Buser, pass
Cself
Dargs
Attempts:
3 left
💡 Hint
Common Mistakes
Using only one parameter or incorrect parameter names.
4fill in blank
hard

Fill both blanks to assert the page title after login using parameterized username and password.

Selenium Python
def test_login(self, username, password):
    self.driver.get("http://example.com/login")
    self.driver.find_element_by_id("username").send_keys(username)
    self.driver.find_element_by_id("password").send_keys(password)
    self.driver.find_element_by_id("submit").click()
    assert self.driver.title [1] [2]
Drag options to blanks, or click blank then click option'
A==
B"Dashboard"
C"Home"
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or incorrect expected title strings.
5fill in blank
hard

Fill all three blanks to create a parameterized test that checks login with multiple credentials and asserts the welcome message.

Selenium Python
from parameterized import parameterized

class TestLogin:
    @parameterized.expand([
        ("user1", "pass1", [1]),
        ("user2", "pass2", [2])
    ])
    def test_login(self, username, password, expected_message):
        self.driver.get("http://example.com/login")
        self.driver.find_element_by_id("username").send_keys(username)
        self.driver.find_element_by_id("password").send_keys(password)
        self.driver.find_element_by_id("submit").click()
        message = self.driver.find_element_by_id("welcome").text
        assert message == [3]
Drag options to blanks, or click blank then click option'
A"Welcome user1!"
B"Welcome user2!"
Cexpected_message
D"Welcome!"
Attempts:
3 left
💡 Hint
Common Mistakes
Using string literals directly in the assertion instead of the expected_message variable.