在我的PyCharm编辑器中,我有一个test_suite.py文件和一个functions.py文件。在函数文件中,我编写了一个类来建立一个Chrome webdriver和一个单独的类来建立Firefox webdriver。在这个文件中,我目前正在将firefox部分的每个函数复制/粘贴到chrome部分,我担心这会创建一个没有正确组织的大量测试用例。
Functions.py文件如下所示:
import libraries
from libraries import *
import ini
from ini import *
class ChromeBase(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.base_url = baseurl
self.verificationErrors = []
self.accept_next_alert = True
self.driver.implicitly_wait(3)
def testcase1(self):
global resultfail
resultfail = 'unable to do what you want'
try:self.driver.find_element_by_link_text("sign in").click()
except failed() as e: self.verificationErrors.append(str(e))
def testcase2(self):
self.signin('test@user.com', 'xxx')
def testcase3(self):
self.driver.set_window_size(1920, 1020)
self.signin('test2@user.com', 'xxx')
class baseline(unittest.TestCase):
def setUp(self):
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.path.join(os.path.expanduser("~"), "Downloads\\"))
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv, application/octet-stream')
self.driver = webdriver.Firefox(profile)
self.base_url = baseurl
self.verificationErrors = []
self.accept_next_alert = True
self.driver.implicitly_wait(3)
def testcase1(self):
global resultfail
resultfail = 'unable to do what you want'
try:self.driver.find_element_by_link_text("sign in").click()
except failed() as e: self.verificationErrors.append(str(e))
def testcase2(self):
self.signin('test@user.com', 'xxx')
def testcase3(self):
self.driver.set_window_size(1920, 1020)
self.signin('test2@user.com', 'xxx')
在我的test_suite文件中,我正在调用不同的webdrivers:
class TestCase(baseline):
def test_case1(self):
print('testcase1')
self.driver.get(self.base_url)
self.testcase1()
self.testcase2()
self.testcase3()
class TestCase(ChromeBase):
def test_case1(self):
print('testcase1')
self.driver.get(self.base_url)
self.testcase1()
self.testcase2()
self.testcase3()
我可以在PyCharm编辑器中组织项目以便于阅读并以简洁的方式调用不同的Web驱动程序吗?
如何进行此操作,以便当我点击绿色的“播放”按钮时,我可以管理是为所有网络浏览器还是仅为特定的网络浏览器运行案例?
干杯