0
0
Selenium Pythontesting~5 mins

Parameterize with test data in Selenium Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does it mean to parameterize tests with test data?
Parameterizing tests means running the same test multiple times with different input values. This helps check how the software behaves with various data without writing separate tests for each case.
Click to reveal answer
beginner
Why is parameterizing tests useful in Selenium testing?
It saves time by reusing the same test code for many inputs. It also helps find bugs that only appear with certain data, making tests more thorough and efficient.
Click to reveal answer
intermediate
How can you parameterize tests in Python using pytest?
You can use the @pytest.mark.parametrize decorator to pass a list of input values to a test function. The test runs once for each set of inputs automatically.
Click to reveal answer
intermediate
Show a simple example of parameterizing a Selenium test with pytest.
Example:

import pytest
from selenium.webdriver.common.by import By

@pytest.mark.parametrize('username,password', [
  ('user1', 'pass1'),
  ('user2', 'pass2')
])
def test_login(driver, username, password):
  driver.get('http://example.com/login')
  driver.find_element(By.ID, 'user').send_keys(username)
  driver.find_element(By.ID, 'pass').send_keys(password)
  driver.find_element(By.ID, 'submit').click()
  assert 'Welcome' in driver.page_source
Click to reveal answer
intermediate
What are best practices when choosing test data for parameterized tests?
Choose data that covers normal cases, edge cases, and invalid inputs. This ensures the software is tested well and can handle different situations gracefully.
Click to reveal answer
What is the main benefit of parameterizing tests?
ARun the same test with different inputs automatically
BWrite separate tests for each input
CSkip tests that fail
DMake tests run faster by skipping assertions
Which Python decorator is commonly used to parameterize tests in pytest?
A@pytest.mark.parametrize
B@pytest.testdata
C@pytest.run
D@pytest.input
In Selenium tests, what should you do after entering parameterized input data?
AIgnore the input and check logs
BClose the browser immediately
CClick submit or perform the action to test
DRestart the test
Which of these is NOT a good type of test data to include when parameterizing?
ANormal expected inputs
BEdge cases like empty strings
CInvalid or unexpected inputs
DOnly one fixed input
What happens if an assertion fails in one parameterized test case?
AAll test cases stop immediately
BOnly that test case fails, others continue
CThe test runner ignores the failure
DThe test automatically retries
Explain how to use pytest to parameterize a Selenium test with multiple username and password pairs.
Think about how to repeat the same test with different inputs automatically.
You got /4 concepts.
    Describe why parameterizing tests improves test coverage and efficiency.
    Consider how testing many cases helps find more issues without extra work.
    You got /4 concepts.