无法调用来自班级chrome_configuration
的方法Profile
,我想在TestBase
班级调用该方法:
class TestBase:
driver = None
def setup(self):
Profile.chrome_configuration()
class Profile:
driver = None
def chrome_configuration(self):
self.driver = webdriver.Chrome()
self.driver.set_window_size(1900, 1200)
self.driver.maximize_window()
答案 0 :(得分:1)
您必须实例化该类或使该方法保持静态。以下是每个选项的示例。
#By initializing the profile class
class TestBase(object):
driver = None
profile = Profile()
def setup(self):
profile.chrome_configuration()
#By making the method static
class Profile(object):
driver = None
@staticmethod
def chrome_configuration(self):
self.driver = webdriver.Chrome()
self.driver.set_window_size(1900, 1200)
self.driver.maximize_window()
此外,您的所有课程应始终从2.x中的object
继承。它被称为新式课程。