conftest.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. @File : conftest.py
  5. @Time : 2024/11/06 16:24:10
  6. @Author : dulip3ng
  7. @Version : 1.0
  8. @Desc : None
  9. '''
  10. import pytest
  11. from playwright.sync_api import sync_playwright, expect, Page
  12. from pages import nebula
  13. expect.set_options(timeout=30_000)
  14. @pytest.fixture(scope="module")
  15. def browser():
  16. with sync_playwright() as p:
  17. # 启动有头浏览器
  18. browser = p.chromium.launch(headless=False, slow_mo=300) # 设置headless=False来启用有头模式
  19. yield browser
  20. browser.close()
  21. @pytest.fixture(scope="module")
  22. def page(browser):
  23. # 为每个测试用例提供一个新的页面实例
  24. context = browser.new_context(viewport= {"width": 1920, "height": 1080})
  25. page = context.new_page()
  26. yield page
  27. page.close()
  28. context.close()
  29. @pytest.fixture(scope="module")
  30. def body_page(page):
  31. return nebula.new_body_page(page)
  32. @pytest.fixture(scope="module")
  33. def home_page(page):
  34. return nebula.new_home_page(page)
  35. @pytest.fixture(scope="module")
  36. def login_page(page):
  37. return nebula.new_login_page(page)
  38. @pytest.fixture(scope="module")
  39. def list_page(page):
  40. return nebula.new_list_page(page)
  41. @pytest.fixture(scope="module")
  42. def head_page(page):
  43. return nebula.new_head_page(page)
  44. @pytest.fixture(scope="module")
  45. def filter_page(page):
  46. return nebula.new_filter_page(page)
  47. @pytest.fixture(scope="module")
  48. def push_page(page):
  49. return nebula.new_push_page(page)