conftest.py 934 B

12345678910111213141516171819202122232425262728293031323334
  1. import datetime
  2. import os
  3. import pytest
  4. @pytest.fixture
  5. def chrome_options(chrome_options):
  6. chrome_options.add_argument('headless')
  7. chrome_options.add_argument('disable-gpu')
  8. chrome_options.add_argument('window-size=1200x600')
  9. return chrome_options
  10. @pytest.fixture
  11. def selenium(selenium):
  12. selenium.implicitly_wait(0.1)
  13. return selenium
  14. # original taken from https://github.com/theserverlessway/pytest-chrome/blob/master/tests/conftest.py
  15. @pytest.fixture
  16. def screenshot(selenium):
  17. def shot(name=''):
  18. directory = 'screenshots'
  19. if not os.path.exists(directory):
  20. os.makedirs(directory)
  21. identifier = datetime.datetime.now().isoformat()
  22. if name:
  23. identifier = f'{identifier}-{name}'
  24. filename = f'{directory}/{identifier}.png'
  25. print(f'Storing Screenshot to {filename}')
  26. selenium.get_screenshot_as_file(filename)
  27. return shot