Bird
Raised Fist0
Selenium Pythontesting~20 mins

HTML report generation in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
HTML Report Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Selenium HTML report generation snippet
What will be the output status in the generated HTML report after running this Selenium test code snippet?
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import unittest
from HtmlTestRunner import HTMLTestRunner

class TestGoogleSearch(unittest.TestCase):
    def setUp(self):
        options = Options()
        options.add_argument('--headless')
        self.driver = webdriver.Chrome(options=options)

    def test_search(self):
        self.driver.get('https://www.google.com')
        search_box = self.driver.find_element(By.NAME, 'q')
        search_box.send_keys('OpenAI')
        search_box.submit()
        WebDriverWait(self.driver, 10).until(
            EC.title_contains('OpenAI')
        )
        self.assertIn('OpenAI', self.driver.title)

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main(testRunner=HTMLTestRunner(output='reports'))
ATest fails because the search box locator is incorrect, and the report shows one failed test.
BTest passes and the HTML report shows one passed test with no errors.
CTest raises a TimeoutException and the report shows an error in the test execution.
DTest passes but the HTML report is not generated due to missing output directory.
Attempts:
2 left
💡 Hint
Check if the locator and wait condition match the page behavior and if the HTMLTestRunner output folder is specified.
❓ assertion
intermediate
1:30remaining
Correct assertion for verifying HTML report content
Which assertion correctly verifies that the generated HTML report contains the text 'Tests run: 1' indicating one test was executed?
Selenium Python
with open('reports/TestGoogleSearch.html', 'r', encoding='utf-8') as report_file:
    report_content = report_file.read()
Aassert 'Tests run: 1' in report_content
Bassert report_content.contains('Tests run: 1')
Cassert report_content.index('Tests run: 1') > 0
Dassert report_content.find('Tests run: 1') == -1
Attempts:
2 left
💡 Hint
Use Python's 'in' keyword to check substring presence.
❓ locator
advanced
1:30remaining
Best locator strategy for report download button in Selenium
You want to automate clicking a 'Download Report' button in the HTML report page. The button has the text 'Download Report' and a unique id 'download-btn'. Which locator is the best practice to use in Selenium for this button?
Adriver.find_element(By.CLASS_NAME, 'download-btn')
Bdriver.find_element(By.XPATH, "//button[text()='Download Report']")
Cdriver.find_element(By.CSS_SELECTOR, 'button#download-btn')
Ddriver.find_element(By.ID, 'download-btn')
Attempts:
2 left
💡 Hint
ID selectors are unique and fastest for locating elements.
🔧 Debug
advanced
2:00remaining
Debugging missing HTML report generation
A Selenium test run with HTMLTestRunner does not generate any HTML report files. Which is the most likely cause?
AThe output folder path passed to HTMLTestRunner does not exist and is not created automatically.
BThe test cases have syntax errors preventing execution.
CThe test methods are not prefixed with 'test_'
DThe test runner is not called with unittest.main()
Attempts:
2 left
💡 Hint
Check if the output directory exists before running tests.
❓ framework
expert
3:00remaining
Configuring parallel test execution with HTML report generation
You want to run multiple Selenium tests in parallel using unittest and generate a single consolidated HTML report. Which approach is correct?
AUse unittest's built-in parallel execution with HTMLTestRunner; it merges reports automatically.
BUse threading in test code and write custom code to combine HTML reports after execution.
CRun tests in parallel with a third-party runner like pytest-xdist and generate separate HTML reports, then merge manually.
DRun tests sequentially to avoid report conflicts; HTMLTestRunner does not support parallel runs.
Attempts:
2 left
💡 Hint
Consider limitations of unittest and HTMLTestRunner with parallel execution.

Practice

(1/5)
1. What is the main purpose of generating an HTML report in Selenium Python testing?
easy
A. To avoid writing assertions
B. To speed up test execution
C. To make test results easy to read and share
D. To write test cases faster

Solution

  1. Step 1: Understand the role of HTML reports

    HTML reports present test results in a clear, visual format that anyone can read.
  2. Step 2: Compare with other options

    Speeding tests, writing tests faster, or avoiding assertions are unrelated to HTML reports.
  3. Final Answer:

    To make test results easy to read and share -> Option C
  4. Quick Check:

    HTML reports = clear, shareable results [OK]
Hint: HTML reports show results clearly for sharing [OK]
Common Mistakes:
  • Thinking HTML reports speed up tests
  • Confusing report generation with test writing
  • Believing reports remove need for assertions
2. Which Python package is commonly used with unittest to generate HTML reports in Selenium tests?
easy
A. pytest-html
B. unittest-html
C. selenium-html
D. HtmlTestRunner

Solution

  1. Step 1: Identify the package for unittest HTML reports

    HtmlTestRunner is designed to work with unittest for HTML report generation.
  2. Step 2: Eliminate other options

    pytest-html is for pytest, selenium-html and unittest-html are not standard packages.
  3. Final Answer:

    HtmlTestRunner -> Option D
  4. Quick Check:

    unittest + HtmlTestRunner = HTML reports [OK]
Hint: HtmlTestRunner works with unittest for HTML reports [OK]
Common Mistakes:
  • Choosing pytest-html for unittest tests
  • Assuming selenium-html is a real package
  • Confusing unittest-html as official
3. Given this code snippet using HtmlTestRunner, what folder will the HTML report be saved in?
import unittest
import HtmlTestRunner

class TestExample(unittest.TestCase):
    def test_pass(self):
        self.assertTrue(True)

if __name__ == '__main__':
    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='reports'))
medium
A. Current directory
B. reports folder
C. HtmlTestRunner folder
D. No folder, prints to console only

Solution

  1. Step 1: Check the output parameter in HTMLTestRunner

    The output='reports' argument tells HtmlTestRunner to save reports in the 'reports' folder.
  2. Step 2: Understand default behavior

    Without output specified, reports save in current directory, but here 'reports' is explicit.
  3. Final Answer:

    reports folder -> Option B
  4. Quick Check:

    output='reports' means save in reports folder [OK]
Hint: output='foldername' sets report save location [OK]
Common Mistakes:
  • Assuming reports save in current directory by default
  • Thinking HtmlTestRunner creates its own folder
  • Believing reports print only to console
4. What is wrong with this code snippet for generating an HTML report using HtmlTestRunner?
import unittest
import HtmlTestRunner

class TestExample(unittest.TestCase):
    def test_fail(self):
        self.assertEqual(1, 2)

if __name__ == '__main__':
    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output=''))
medium
A. Empty output string causes report not to save
B. assertEqual syntax is incorrect
C. Missing import for HtmlTestRunner
D. Test class must inherit from HtmlTestRunner

Solution

  1. Step 1: Check the output parameter usage

    Setting output='' means no folder is specified, which can cause HtmlTestRunner to fail saving reports properly.
  2. Step 2: Verify other parts

    assertEqual syntax is correct, HtmlTestRunner is imported, and test class inheritance is correct.
  3. Final Answer:

    Empty output string causes report not to save -> Option A
  4. Quick Check:

    output='' disables report folder, causing save issues [OK]
Hint: Provide a valid folder name in output to save reports [OK]
Common Mistakes:
  • Thinking assertEqual(1, 2) is syntax error
  • Believing test class must inherit HtmlTestRunner
  • Ignoring output parameter effect
5. You want to generate an HTML report that shows detailed pass/fail results and saves in a folder named 'test_reports'. Which code snippet correctly sets this up using HtmlTestRunner with unittest?
hard
A. unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='test_reports'))
B. unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(report='test_reports'))
C. unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(folder='test_reports'))
D. unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(path='test_reports'))

Solution

  1. Step 1: Identify correct parameter for output folder

    HtmlTestRunner uses 'output' parameter to specify the folder for saving reports.
  2. Step 2: Check other parameter names

    'report', 'folder', and 'path' are not valid parameters for HtmlTestRunner's HTMLTestRunner class.
  3. Final Answer:

    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='test_reports')) -> Option A
  4. Quick Check:

    Use output='foldername' to save reports correctly [OK]
Hint: Use output='foldername' to set report save location [OK]
Common Mistakes:
  • Using wrong parameter names like report or folder
  • Not specifying output folder at all
  • Confusing HtmlTestRunner options with other packages
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard