我在 PyCharm 中有示例项目 - 由一个简单的测试组成,该测试检查登录到给定的正确 Slack 工作区。它有内部web_drivers目录,用于测试的 webdriver 设置和实际测试,fechromedriverconftest.pytests.py
conftest.py
import os
import pytest
from selenium import webdriver
@pytest.fixture(scope='class')
def driver_get(request):
web_driver = webdriver.Chrome(executable_path=os.path.join("web_drivers","chromedriver.exe"))
yield web_driver
def fin():
web_driver.close()
request.addfinalizer(fin)
测试.py
import pytest
class TestSlackWorkspace(object):
@pytest.fixture(autouse=True)
def setup(self, driver_get):
self.driver = driver_get
self.driver.get("https://slack.com/signin")
self.input_field = self.driver.find_element_by_xpath(
"//input[@type='text' and @id='domain']")
self.continue_button = self.driver.find_element_by_xpath(
"//button[@id='submit_team_domain']")
def test_correct_workspace(self):
self.input_field.send_keys("test")
self.continue_button.click()
assert self.driver.find_element_by_xpath("//h1[@id='signin_header']"
).is_displayed(), "Login page should be displayed"
现在的问题是将测试划分到页面初始化部分 -def setup和实际测试执行部分 -def test_correct_workspace到不同的类和文件(类似于页面对象模式)
所以基数conftest.py应该是一样的,除以test.py即
页面.py
class SlackWorkspace(object):
@pytest.fixture(autouse=True)
def __init__(self, driver_get):
self.driver = driver_get
self.driver.get("https://slack.com/signin")
self.input_field = self.driver.find_element_by_xpath("//input[@type='text' and @id='domain']")
self.continue_button = self.driver.find_element_by_xpath("//button[@id='submit_team_domain']")
但肯定它不会以这种形式工作:
1)driver_get应该以某种方式导入到页面初始化文件和转发器到__init__- ?
2)页面初始化应该以某种方式与其他文件中的测试实现相关联-?
不知道如何在单独的文件之间组织所有这些导入
相关分类