-
-
Save SalmonMode/6132f03132b73e1afa940e75d4947153 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pypcom import PC # from my POM | |
class FormHeader(PC): | |
_locator = (By.CSS_SELECTOR, "div[class*='Header']") | |
class InputField(PC): | |
def __init__(self, *locator): | |
self._locator = locator | |
class LoginForm(PC): | |
_locator = (By.CSS_SELECTOR, "form") | |
header = FormHeader() | |
username = InputField(By.CSS_SELECTOR, "input#username") | |
password = InputField(By.CSS_SELECTOR, "input#password") | |
def fill_out(self, username, password): | |
self.wait_until(lamba d: self.header.is_displayed(), 3) # the lambda will return True, False, or throw an error each time it's called | |
self.username = username # types username into username field | |
self.password = password # types password into password field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pypcom import PC # from my POM | |
class FormHeader(PC): | |
_locator = (By.CSS_SELECTOR, "div[class*='Header']") | |
class UsernameField(PC): | |
_locator = (By.CSS_SELECTOR, "input#username") | |
class PasswordField(PC): | |
_locator = (By.CSS_SELECTOR, "input#password") | |
def form_loaded(component, **kwargs): | |
def callable(driver): | |
return component.header.is_displayed() # .is_displayed call is deferred to the actual WebElement | |
return callable | |
class LoginForm(PC): | |
_locator = (By.CSS_SELECTOR, "form") | |
_expected_conditions = { | |
"loaded": form_loaded, | |
} | |
header = FormHeader() | |
username = UsernameField() | |
password = PasswordField() | |
def fill_out(self, username, password): | |
self.wait_until("loaded", 3) # references "loaded" in self._expected_conditions | |
self.username = username # types username into username field | |
self.password = password # types password into password field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pypcom import Page # from my POM | |
from login_form_components import LoginForm | |
class LoginPage(Page): | |
login_form = LoginForm() | |
def login(self, **credentials): | |
self.login_form.fill_out(**credentials) | |
self.login_form.submit() # .submit call is deferred to the actual WebElement | |
self.login_form.wait_until_not("present", 5) # built in wait condition provided by pypcom, which is actually just the normal selenium EC.presence_of_element_located |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pypcom import PC # from my POM | |
class FormHeader(PC): | |
_locator = (By.CSS_SELECTOR, "div[class*='Header']") | |
class InputField(PC): | |
def __init__(self, *locator): | |
self._locator = locator | |
def form_loaded(component, **kwargs): | |
def callable(driver): | |
return component.header.is_displayed() # .is_displayed call is deferred to the actual WebElement | |
return callable | |
class LoginForm(PC): | |
_locator = (By.CSS_SELECTOR, "form") | |
_expected_conditions = { | |
"loaded": form_loaded, | |
} | |
header = FormHeader() | |
username = InputField(By.CSS_SELECTOR, "input#username") | |
password = InputField(By.CSS_SELECTOR, "input#password") | |
def fill_out(self, username, password): | |
self.wait_until("loaded", 3) # references "loaded" in self._expected_conditions | |
self.username = username # types username into username field | |
self.password = password # types password into password field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium.webdriver import Chrome | |
from login_page import LoginPage | |
driver = Chrome() | |
driver.get("https://mywebsite.com/login") | |
page = LoginPage(driver) | |
page.login(username="myusername", password="mypassword) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment