tests/e2e: fix enroll tests

This commit is contained in:
Jens Langhammer 2021-02-27 22:09:40 +01:00
parent a1af93f8be
commit 07379acf7f
2 changed files with 54 additions and 49 deletions

View File

@ -90,43 +90,7 @@ class TestFlowsEnroll(SeleniumTestCase):
self.driver.get(self.live_server_url) self.driver.get(self.live_server_url)
flow_executor = self.get_shadow_root("ak-flow-executor") self.initial_stages()
identification_stage = self.get_shadow_root(
"ak-stage-identification", flow_executor
)
wait = WebDriverWait(identification_stage, self.wait_timeout)
wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "#enroll")))
identification_stage.find_element(By.CSS_SELECTOR, "#enroll").click()
flow_executor = self.get_shadow_root("ak-flow-executor")
prompt_stage = self.get_shadow_root("ak-stage-prompt", flow_executor)
wait = WebDriverWait(prompt_stage, self.wait_timeout)
wait.until(
ec.presence_of_element_located((By.CSS_SELECTOR, "input[name=username]"))
)
prompt_stage.find_element(By.CSS_SELECTOR, "input[name=username]").send_keys(
"foo"
)
prompt_stage.find_element(By.CSS_SELECTOR, "input[name=password]").send_keys(
USER().username
)
prompt_stage.find_element(
By.CSS_SELECTOR, "input[name=password_repeat]"
).send_keys(USER().username)
prompt_stage.find_element(By.CSS_SELECTOR, ".pf-c-button").click()
flow_executor = self.get_shadow_root("ak-flow-executor")
prompt_stage = self.get_shadow_root("ak-stage-prompt", flow_executor)
prompt_stage.find_element(By.CSS_SELECTOR, "input[name=name]").send_keys(
"some name"
)
prompt_stage.find_element(By.CSS_SELECTOR, "input[name=email]").send_keys(
"foo@bar.baz"
)
prompt_stage.find_element(By.CSS_SELECTOR, ".pf-c-button").click()
self.wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "ak-sidebar"))) self.wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "ak-sidebar")))
self.driver.get(self.shell_url("authentik_core:user-settings")) self.driver.get(self.shell_url("authentik_core:user-settings"))
@ -196,18 +160,16 @@ class TestFlowsEnroll(SeleniumTestCase):
FlowStageBinding.objects.create(target=flow, stage=user_login, order=4) FlowStageBinding.objects.create(target=flow, stage=user_login, order=4)
self.driver.get(self.live_server_url) self.driver.get(self.live_server_url)
self.driver.find_element(By.CSS_SELECTOR, "#enroll").click() self.initial_stages()
self.driver.find_element(By.ID, "id_username").send_keys("foo")
self.driver.find_element(By.ID, "id_password").send_keys(USER().username) # Email stage
self.driver.find_element(By.ID, "id_password_repeat").send_keys(USER().username) flow_executor = self.get_shadow_root("ak-flow-executor")
self.driver.find_element(By.CSS_SELECTOR, ".pf-c-button").click() email_stage = self.get_shadow_root("ak-stage-email", flow_executor)
self.driver.find_element(By.ID, "id_name").send_keys("some name")
self.driver.find_element(By.ID, "id_email").send_keys("foo@bar.baz") wait = WebDriverWait(email_stage, self.wait_timeout)
self.driver.find_element(By.CSS_SELECTOR, ".pf-c-button").click()
# Wait for the success message so we know the email is sent # Wait for the success message so we know the email is sent
self.wait.until( wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, ".pf-c-form p")))
ec.presence_of_element_located((By.CSS_SELECTOR, ".pf-c-form > p"))
)
# Open Mailhog # Open Mailhog
self.driver.get("http://localhost:8025") self.driver.get("http://localhost:8025")
@ -227,3 +189,46 @@ class TestFlowsEnroll(SeleniumTestCase):
self.driver.get(self.shell_url("authentik_core:user-settings")) self.driver.get(self.shell_url("authentik_core:user-settings"))
self.assert_user(User.objects.get(username="foo")) self.assert_user(User.objects.get(username="foo"))
def initial_stages(self):
"""Fill out initial stages"""
# Identification stage, click enroll
flow_executor = self.get_shadow_root("ak-flow-executor")
identification_stage = self.get_shadow_root(
"ak-stage-identification", flow_executor
)
wait = WebDriverWait(identification_stage, self.wait_timeout)
wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "#enroll")))
identification_stage.find_element(By.CSS_SELECTOR, "#enroll").click()
# First prompt stage
flow_executor = self.get_shadow_root("ak-flow-executor")
prompt_stage = self.get_shadow_root("ak-stage-prompt", flow_executor)
wait = WebDriverWait(prompt_stage, self.wait_timeout)
wait.until(
ec.presence_of_element_located((By.CSS_SELECTOR, "input[name=username]"))
)
prompt_stage.find_element(By.CSS_SELECTOR, "input[name=username]").send_keys(
"foo"
)
prompt_stage.find_element(By.CSS_SELECTOR, "input[name=password]").send_keys(
USER().username
)
prompt_stage.find_element(
By.CSS_SELECTOR, "input[name=password_repeat]"
).send_keys(USER().username)
prompt_stage.find_element(By.CSS_SELECTOR, ".pf-c-button").click()
# Second prompt stage
flow_executor = self.get_shadow_root("ak-flow-executor")
prompt_stage = self.get_shadow_root("ak-stage-prompt", flow_executor)
prompt_stage.find_element(By.CSS_SELECTOR, "input[name=name]").send_keys(
"some name"
)
prompt_stage.find_element(By.CSS_SELECTOR, "input[name=email]").send_keys(
"foo@bar.baz"
)
prompt_stage.find_element(By.CSS_SELECTOR, ".pf-c-button").click()

View File

@ -220,7 +220,7 @@ def apply_migration(app_name: str, migration_name: str):
return wrapper_outter return wrapper_outter
def retry(max_retires=1, exceptions=None): def retry(max_retires=3, exceptions=None):
"""Retry test multiple times. Default to catching Selenium Timeout Exception""" """Retry test multiple times. Default to catching Selenium Timeout Exception"""
if not exceptions: if not exceptions: