我应该如何在Python Webdriver中组织多个web驱动程序的测试用例?
在我的PyCharm编辑器中,我有一个test_suite.py文件和一个functions.py文件。在函数文件中,我编写了一个类来建立chromewebdriver,另一个类来建立firefoxwebdriver。在这个文件中,我目前正在将firefox部分的所有功能复制/粘贴到chrome部分,我担心这将创建一个没有正确组织的大量测试用例页面 Functions.py文件如下所示:我应该如何在Python Webdriver中组织多个web驱动程序的测试用例?,python,selenium,selenium-webdriver,webdriver,project-organization,Python,Selenium,Selenium Webdriver,Webdriver,Project Organization,在我的PyCharm编辑器中,我有一个test_suite.py文件和一个functions.py文件。在函数文件中,我编写了一个类来建立chromewebdriver,另一个类来建立firefoxwebdriver。在这个文件中,我目前正在将firefox部分的所有功能复制/粘贴到chrome部分,我担心这将创建一个没有正确组织的大量测试用例页面 Functions.py文件如下所示: import libraries from libraries import * import ini fr
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')
在我的测试套件文件中,我调用了不同的Web驱动程序:
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驱动程序
我该如何做才能在单击绿色播放按钮时管理是为所有web浏览器还是仅为特定web浏览器运行案例
干杯为什么要为firefox和chrome分别上课?为什么不一节课呢?使用这种方法,当你不得不在另外两个浏览器上运行测试时,你会怎么做。谢谢Gaurang,我不确定我是否理解如何组合不同的类。如果我只想运行Firefox测试,而不想运行Chrome/其他浏览器呢?创建一个类,根据传递的字符串返回驱动程序对象。