[英]Calling profile from another class with Python/Selenium
Having trouble calling the method chrome_configuration
that comes from class Profile
, I want to call that method on TestBase
class: 调用来自Profile
类的chrome_configuration
方法遇到麻烦,我想在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()
You must instantiate the class or make the method static. 您必须实例化该类或使该方法静态。 Below are examples of each option. 以下是每个选项的示例。
#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()
In addition, all your classes should always inherit from object
in 2.x. 另外,所有类都应始终从2.x中的object
继承。 It's called new-style classes. 这称为新型类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.