Pytest 如何把瀏覽器引數化?

lyyyyyyy發表於2020-11-24

如題,我定義了一個firefox和一個chrome的fixture,現在想用引數化的形式來做到用chrome和firefox分別開啟一次瀏覽器去訪問百度,請教應該如何去實現呢?

import pytest
import os
from selenium import webdriver


@pytest.fixture(name='chrome')
def chrome_driver():
driver = webdriver.Chrome()
driver.maximize_window()
yield driver
driver.close()


@pytest.fixture(name='firefox')
def firefox_driver():
driver = webdriver.Firefox()
driver.maximize_window()
yield driver
driver.close()


def open_url(driver, url):
driver.get(url)


@pytest.mark.demo1
def test_login(chrome):
open_url(chrome, "https://www.baidu.com")


if __name__ == '__main__':
pytest.main(['-m demo1', os.path.abspath(__file__)])

相關文章