|
11 | 11 | import sys
|
12 | 12 | import time
|
13 | 13 | import unittest
|
| 14 | +from pyvirtualdisplay import Display |
14 | 15 | from seleniumbase.config import settings
|
15 | 16 | from seleniumbase.core import browser_launcher
|
16 | 17 | from seleniumbase.core import log_helper
|
@@ -303,12 +304,18 @@ def setUp(self):
|
303 | 304 | self.is_pytest = False
|
304 | 305 | if self.is_pytest:
|
305 | 306 | self.with_selenium = pytest.config.option.with_selenium
|
| 307 | + self.headless = pytest.config.option.headless |
| 308 | + self.headless_active = False |
306 | 309 | self.with_testing_base = pytest.config.option.with_testing_base
|
307 | 310 | self.log_path = pytest.config.option.log_path
|
308 | 311 | self.browser = pytest.config.option.browser
|
309 | 312 | self.data = pytest.config.option.data
|
310 | 313 | self.demo_mode = pytest.config.option.demo_mode
|
311 | 314 | self.demo_sleep = pytest.config.option.demo_sleep
|
| 315 | + if self.headless: |
| 316 | + self.display = Display(visible=0, size=(1200, 800)) |
| 317 | + self.display.start() |
| 318 | + self.headless_active = True |
312 | 319 | if self.with_selenium:
|
313 | 320 | self.driver = browser_launcher.get_driver(self.browser)
|
314 | 321 |
|
@@ -336,6 +343,8 @@ def tearDown(self):
|
336 | 343 | test_logpath, self.driver, self.browser)
|
337 | 344 | # Handle page source logging
|
338 | 345 | log_helper.log_page_source(test_logpath, self.driver)
|
339 |
| - |
340 | 346 | # Finally close the browser
|
341 | 347 | self.driver.quit()
|
| 348 | + if self.headless: |
| 349 | + if self.headless_active: |
| 350 | + self.display.stop() |
0 commit comments