test_sign_in_page.py
from tests.base_test import BaseTest from pages.main_page import MainPage class TestSignInPage(BaseTest): def test_sign_in_with_in_valid_user(self): main_page = MainPage(self.driver) login_page = main_page.login_click() result = login_page.login()main_page.py
from pages.base_page import BasePage from pages.login_page import LoginPage from utils import users from utils.locators import * class MainPage(BasePage): def __init__(self, driver): print("user_page __init__") self.locator = UserPageLocators self.user = users.get_user("google") super().__init__(driver) # Python3 version def check_page_loaded(self): return True if self.find_element(*self.locator.LOGO) else False def click_sign_in_button(self): self.find_element(*self.locator.LOGIN).click() def click_facebook_login_button(self): self.find_element(*self.locator.FACEBOOK_LOGIN).click() def click_google_login_button(self): self.find_element(*self.locator.GOOGLE_LOGIN).click() def click_apple_login_button(self): self.find_element(*self.locator.APPPLE_LOGIN).click() def switch_to_login_iframe(self): self.iframe = self.find_element(*self.locator.IFRAME) self.switch_iframe(self.iframe) def login_click(self): self.click_sign_in_button() self.switch_to_login_iframe() if self.user["provider"] == "google": self.click_google_login_button() elif self.user["provider"] == "facebook": self.click_facebook_login_button() elif self.user["provider"] == "apple": self.click_apple_login_button() return LoginPage(self.driver, self.user)login_page.py
import time from utils.locators import * from pages.base_page import BasePage class LoginPage(BasePage): def __init__(self, driver, user): self.user = user if self.user["provider"] == "google": self.locator = GoogleLoginPageLocators elif self.user["provider"] == "facebook": self.locator = FacebookLoginPageLocators elif self.user["provider"] == "apple": self.locator = AppleLoginPageLocators super().__init__(driver) def enter_email(self, email): self.find_element(*self.locator.EMAIL).send_keys(email) def enter_password(self, password): self.find_element(*self.locator.PASSWORD).send_keys(password) def click_login_button(self): self.find_element(*self.locator.SUBMIT).click() def click_continue_button(self): self.find_element(*self.locator.CONTINUE).click() def switch_window(self, x): self.driver.switch_to.window(self.driver.window_handles[x]) def login(self): if self.user["provider"] == "google": self.login_google() elif self.user["provider"] == "facebook": self.login_facebook() elif self.user["provider"] == "apple": self.login_apple() if self.check_element(*self.locator.IFRAME): self.age_gender_verification() else: print("wtf") def age_gender_verification(self): #change frame for verification self.iframe = self.find_element(*self.locator.IFRAME) self.switch_iframe(self.iframe) #enter age self.find_element(*self.locator.AGE).send_keys(self.user["age"]) #enter gender self.find_element(*self.locator.GENDER_SELECT).click() if self.user["gender"] == "male": self.find_element(*self.locator.GENDER_MALE).click() else: self.find_element(*self.locator.GENDER_FEMALE).click() #Click Validation Continue self.find_element(*self.locator.VALIDATION_CONTINUE).click() #If error then restart the login proccess if self.check_element(*self.locator.VALIDATION_ERROR): from pages.main_page import MainPage #switch back from iframe self.driver.switch_to.default_content() #click close self.find_element(*self.locator.VALIDATION_CLOSE).click() #relogin MainPage(self).login_click() else: print("fail") def login_facebook(self): self.switch_window(1) print(self.user) self.enter_email(self.user["email"]) self.enter_password(self.user["password"]) self.click_login_button() self.switch_window(0) def login_google(self): self.switch_window(1) print(self.user) self.enter_email(self.user["email"]) self.click_continue_button() time.sleep(1) self.enter_password(self.user["password"]) self.click_login_button() self.switch_window(0) def login_apple(self): self.switch_window(1) print(self.user) self.enter_email(self.user["email"]) self.enter_password(self.user["password"]) self.click_login_button() self.switch_window(0)Error Message:
Error:ImportError: cannot import name 'LoginPage' from partially initialized module 'pages.login_page' (most likely due to a circular import)
for the missing classes please look at the github link https://github.com/gunesmes/page-object-python-selenium