It works at first but I think the inheritance gets all messed up because there is a BasePage class within MainPage and LoginPage after reusing a function which is in BasePage I get this error. Strangely only the BasePage function doesnt work and the MainPage class still does.
I updated the code in the post before that.
Error:
Error Traceback (most recent call last): File "C:\Python\Python38-32\lib\unittest\case.py", line 60, in testPartExecutor yield File "C:\Python\Python38-32\lib\unittest\case.py", line 676, in run self._callTestMethod(testMethod) File "C:\Python\Python38-32\lib\unittest\case.py", line 633, in _callTestMethod method() File "C:\MEGA\Private_Project\POM\tests\test_sign_in_page.py", line 11, in test_sign_in_with_in_valid_user result = login_page.login() File "C:\MEGA\Private_Project\POM\pages\login_page.py", line 44, in login self.age_gender_verification() File "C:\MEGA\Private_Project\POM\pages\login_page.py", line 74, in age_gender_verification MainPage(self).login_click() File "C:\MEGA\Private_Project\POM\pages\main_page.py", line 35, in login_click self.switch_to_login_iframe() File "C:\MEGA\Private_Project\POM\pages\main_page.py", line 31, in switch_to_login_iframe self.switch_iframe(self.iframe) File "C:\MEGA\Private_Project\POM\pages\base_page.py", line 46, in switch_iframe self.driver.switch_to.frame(element) AttributeError: 'LoginPage' object has no attribute 'switch_to'
base_page.py import time from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException,NoSuchElementException # this Base class is serving basic attributes for every single page inherited from Page class from utils import users class BasePage(object): def __init__(self, driver, base_url='https://soundcloud.com/'): print("base_page __init__") self.base_url = base_url self.driver = driver #self.driver.get(base_url) def find_element(self, *locator): self.wait_element(locator) return self.driver.find_element(*locator) def check_element(self, *locator): time.sleep(1) try: return self.driver.find_element(*locator) except NoSuchElementException: return False def open(self, url): url = self.base_url + url self.driver.get(url) def get_title(self): return self.driver.title def get_url(self): return self.driver.current_url def hover(self, *locator): element = self.find_element(*locator) hover = ActionChains(self.driver).move_to_element(element) hover.perform() def switch_iframe(self, element): self.driver.switch_to.frame(element) def switch_window(self, x): self.driver.switch_to.window(self.driver.window_handles[x]) def wait_element(self, *locator): try: WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(*locator)) except TimeoutException: print("\n * ELEMENT NOT FOUND WITHIN GIVEN TIME! --> %s" %(locator[1])) self.driver.quit()Maybe the POM model I am using is wrong or am I doing something wrong?
my problem is that after intialising MainPage which clicks the login button and returns LoginPage which trys to login with email and password I sometimes need to restart the login process from the LoginPage class function and use the MainPage login click function again but this POM model from github:
https://github.com/gunesmes/page-object-...-selenium/ doesnt really seem to allow it because I cant somehow easily jump between the classes with the same objects and functions.