Will my class inherit all of the properties of the main class when it's defined within it? My code is:
class DashboardPage(BasePage):
def __ini__(self,driver):
super().__init__(driver)
class MeetingsPage():
def createMeeting(self):
pass
def editMeeting(self):
pass
class EmailsPage():
def writeEmail(self):
pass
Will the MeetingsPage/EmailPage inherit properties/methods of the BasePage?
In Python the syntax for a derived class definition looks like DerivedClassName(BaseClassName):
or multiple inheritance class DerivedClassName(Base1, Base2, Base3):
. As you can see your classes (MeetingsPage/EmailPage) have not been derived from BasePage
. So they do not inherit any properties and methods from BasePage
.
Read, please, doc https://docs.python.org/2/tutorial/classes.html#inheritance
No. You are only restricting the scope. If you want the nested class to inherit from a base class, do so as normal (eg class X(Y):
).
No it will not. A nested class behaves like any "outer" (un-nested) class. It can be instantiated like this.
Ex: obj = DashboardPage().MeetingsPage()
The methods of a nested class may access the instance attributes of the nested class instance but not of any outer class instance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.