Skip to content

Commit

Permalink
Merge pull request #873 from mastastny/fix_billing_address_form
Browse files Browse the repository at this point in the history
UI tests fixes for alpha based on 2.16 changes
  • Loading branch information
dhlavac authored Jan 3, 2025
2 parents c80bafe + 8d3ddf3 commit ad6edfa
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 48 deletions.
12 changes: 5 additions & 7 deletions testsuite/tests/ui/devel/auth/test_login_recaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from testsuite import settings, rawobj, TESTED_VERSION # noqa # pylint: disable=unused-import
from testsuite.ui.views.admin.audience.developer_portal import BotProtection
from testsuite.ui.views.devel.login import BasicSignUpView, LoginView, SuccessfulAccountCreationView, ForgotPasswordView
from testsuite.ui.views.devel.login import BasicSignUpView, LoginView, ForgotPasswordView
from testsuite.utils import blame, warn_and_skip

# requires special setup, internet access
Expand All @@ -30,7 +30,8 @@ def ui_devel_account(request, testconfig, threescale):

if not testconfig["skip_cleanup"]:
usr = threescale.accounts.read_by_name(user_name)
request.addfinalizer(usr.delete)
if usr:
request.addfinalizer(usr.delete)


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -66,6 +67,8 @@ def test_devel_recaptcha_sing_up(provider_account, ui_devel_account, navigator):
- Navigates and fills up the Sign Up page on developer portal
- Assert that invisible recaptcha badge is present
- Submits the form and checks that the success website appears
note: Since reCAPTCHA v3 does not support developer mode, this test does not attempt to submit the form.
"""
signup_view = navigator.open(
BasicSignUpView, url=settings["threescale"]["devel"]["url"], access_code=provider_account["site_access_code"]
Expand All @@ -78,11 +81,6 @@ def test_devel_recaptcha_sing_up(provider_account, ui_devel_account, navigator):
assert signup_view.signup_button.is_enabled
assert signup_view.recaptcha.is_displayed, "Recaptcha was not found on the developer sign up page"

signup_view.signup_button.click()

login_success = SuccessfulAccountCreationView(navigator.browser)
assert login_success.is_displayed


def test_devel_forgot_password_recaptcha(custom_account, navigator, params):
"""
Expand Down
4 changes: 2 additions & 2 deletions testsuite/ui/views/admin/foundation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class BaseAdminView(View, Navigable):
logo = GenericLocatorWidget(".//a[@href='/p/admin/dashboard']")
support_link = Text(".//a[@href='//access.redhat.com/products/red-hat-3scale#support']")
context_menu = Dropdown(component_id="context-selector")
documentation = Dropdown(component_id="OUIA-Generated-Dropdown-2")
user_session = Dropdown(component_id="OUIA-Generated-Dropdown-3")
documentation = Dropdown(component_id="OUIA-Generated-DropdownToggle-2")
user_session = Dropdown(component_id="OUIA-Generated-DropdownToggle-3")
threescale_version = Text("//*[contains(@class,'powered-by-3scale')]/span")

def __init__(self, parent, logger=None, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions testsuite/ui/views/admin/settings/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from testsuite.ui.navigation import step
from testsuite.ui.views.admin.settings import BaseSettingsView
from testsuite.ui.widgets import CheckBoxGroup, ThreescaleDropdown
from testsuite.ui.widgets import ThreescaleDropdown, PfCheckBoxGroup
from testsuite.ui.widgets.buttons import ThreescaleSubmitButton


Expand Down Expand Up @@ -48,7 +48,7 @@ class TokenNewView(BaseSettingsView):

path_pattern = "/p/admin/user/access_tokens/new"
name = TextInput(id="access_token_name")
scopes = CheckBoxGroup("//*[@id='access_token_scopes_input']")
scopes = PfCheckBoxGroup("//*[@for='access_token_scopes']/ancestor::div[@class='pf-c-form__group']")
permissions = ThreescaleDropdown("//*[@id='access_token_permission']")
create_button = ThreescaleSubmitButton()
token_value = Text(".//div/dt/span[text()='Token']/ancestor::dt/following-sibling::dd")
Expand Down
41 changes: 10 additions & 31 deletions testsuite/ui/views/admin/settings/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from widgetastic.widget import TextInput, GenericLocatorWidget


from testsuite.ui.views.admin.settings import BaseSettingsView
from testsuite.ui.widgets import CheckBoxGroup
from testsuite.ui.widgets import PfCheckBoxGroup
from testsuite.ui.widgets.buttons import ThreescaleUpdateButton


Expand All @@ -17,34 +18,12 @@ class WebhooksView(BaseSettingsView):
path_pattern = "/p/admin/webhooks/edit"
webhook_active = GenericLocatorWidget('//*[@id="web_hook_active"]')
webhook_provider = GenericLocatorWidget('//*[@id="web_hook_provider_actions"]')
accounts = CheckBoxGroup("//fieldset[@class='inputs']/legend/span[text()='Accounts']/../../..")
users = CheckBoxGroup("//fieldset[@class='inputs']/legend/span[text()='Users']/../../..")
applications = CheckBoxGroup("//fieldset[@class='inputs']/legend/span[text()='Applications']/../../..")
keys = CheckBoxGroup("//fieldset[@class='inputs']/legend/span[text()='Keys']/../../..")
checkbox_names = {
"Accounts": [
"web_hook_account_created_on",
"web_hook_account_updated_on",
"web_hook_account_plan_changed_on",
"web_hook_account_deleted_on",
],
"Users": ["web_hook_user_created_on", "web_hook_user_updated_on", "web_hook_user_deleted_on"],
"Applications": [
"web_hook_application_created_on",
"web_hook_application_updated_on",
"web_hook_application_suspended_on",
"web_hook_application_plan_changed_on",
"web_hook_application_user_key_updated_on",
"web_hook_application_deleted_on",
],
"Keys": [
"web_hook_application_key_created_on",
"web_hook_application_key_deleted_on",
"web_hook_application_key_updated_on",
],
}
url = TextInput(id="web_hook_url")
update = ThreescaleUpdateButton()
accounts_cb_group = PfCheckBoxGroup(label_text="Accounts")
users_cb_group = PfCheckBoxGroup(label_text="Users")
applications_cb_group = PfCheckBoxGroup(label_text="Applications")
keys_cb_group = PfCheckBoxGroup(label_text="Keys")

def webhook_check(self, webhook_type: str, requestbin: str):
"""Configure given webhooks"""
Expand All @@ -53,16 +32,16 @@ def webhook_check(self, webhook_type: str, requestbin: str):
self.url.fill(requestbin)

if webhook_type == "Accounts":
self.accounts.check(self.checkbox_names[webhook_type])
self.accounts_cb_group.check_all()

if webhook_type == "Users":
self.users.check(self.checkbox_names[webhook_type])
self.users_cb_group.check_all()

if webhook_type == "Applications":
self.applications.check(self.checkbox_names[webhook_type])
self.applications_cb_group.check_all()

if webhook_type == "Keys":
self.keys.check(self.checkbox_names[webhook_type])
self.keys_cb_group.check_all()

self.update.click()

Expand Down
2 changes: 1 addition & 1 deletion testsuite/ui/views/devel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class LandingView(BaseDevelView):
"""Developer portal landing page"""

sign_in_btn = Text("//a[contains(@href, '/login')]")
close_csm = GenericLocatorWidget('//*[@id="cms-toolbar-menu-right"]/li/a')
close_csm = GenericLocatorWidget('//*[@id="cms-toolbar-menu-right"]/div/a')

@property
def is_displayed(self):
Expand Down
2 changes: 1 addition & 1 deletion testsuite/ui/views/devel/settings/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class BillingAddressForm(View):
"""Billing Address form"""

ROOT = "//form[@action='/admin/account/payment_details']"
ROOT = "//form[@action='/admin/account/stripe']"
name = TextInput(id="account_billing_address_name")
address1 = TextInput(id="account_billing_address_address1")
address2 = TextInput(id="account_billing_address_address2")
Expand Down
2 changes: 1 addition & 1 deletion testsuite/ui/views/master/audience/tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class TenantDetailView(BaseMasterAudienceView):

path_pattern = "/buyers/accounts/{account_id}"
edit_button = ThreescaleEditButton()
applications_button = Text("//*[contains(@title,'applications')]")
applications_button = Text("*//button[normalize-space(text())='Applications']")
public_domain = Text(".//th[contains(text(),'Public domain')]/parent::*/td/a")
admin_domain = Text(".//th[contains(text(),'Admin domain')]/parent::*/td/a")
resume_b = Button("Resume", classes=["button-to", "resume"])
Expand Down
4 changes: 2 additions & 2 deletions testsuite/ui/views/master/foundation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class BaseMasterView(View, Navigable):
support_link = Text("//a[@href='//access.redhat.com/products/red-hat-3scale#support']")
master_header = Text("//*[contains(@class,'Header--master')]")
context_menu = Dropdown(component_id="context-selector")
documentation = Dropdown(component_id="OUIA-Generated-Dropdown-2")
user_session = Dropdown(component_id="OUIA-Generated-Dropdown-3")
documentation = Dropdown(component_id="OUIA-Generated-DropdownToggle-2")
user_session = Dropdown(component_id="OUIA-Generated-DropdownToggle-3")
threescale_version = Text("//*[contains(@class,'powered-by-3scale')]/span")

def __init__(self, parent, logger=None, **kwargs):
Expand Down
91 changes: 91 additions & 0 deletions testsuite/ui/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,97 @@ def clear_all(self):
element.click()


class PfCheckBoxGroup(Widget):
"""
Patternfly CheckBox group
:param locator: Locator of widget which contains patternfly checkboxes
:param label_text: Label of the patternfly checkbox group. This param shadows param locator
"""

def __init__(self, parent=None, locator=None, label_text=None, logger=None):
super().__init__(parent, logger=logger)
self.locator = locator
self.label_text = label_text

if label_text:
self.locator = (
f"//div[@class='pf-c-form__group' and "
f".//span[@class='pf-c-form__label-text' and text()='{label_text}']]"
)
elif locator:
self.locator = locator
else:
self.locator = ""
self.checkboxes = self.locator + "//input[@type='checkbox']"
self.checkbox_by_label = (
self.locator + "//div[@class='pf-c-check' and ./label[text()='{}']]//input[@type='checkbox']"
)
self.checkbox_by_id = self.locator + "//input[@type='checkbox' and @id='{}']"

def is_checked(self, cb_id: str = None, label: str = None):
"""
Detect if checkbox in the checkbox group is already checked
@param cb_id: select checkbox by id (this param have higher priority than param label)
@param label: select checkbox by label
@return true if is checked
"""
locator = self.checkbox_by_id.format(cb_id) if cb_id else self.checkbox_by_label.format(label)
return self.browser.element(locator).is_selected()

def check(self, ids=None, labels=None):
"""
Check specified checkboxes of the checkbox group. Specification can be based on checkbox id, or it's label.
@param ids: specify checkboxes by id
@param labels: specify checkboxes by labels
@return: None
"""
ids = ids if ids else []
labels = labels if labels else []
self.uncheck_all()
for cb_id in ids:
self.browser.element(self.checkbox_by_id.format(cb_id)).click()
for label in labels:
element = self.browser.element(self.checkbox_by_label.format(label))
if not element.is_selected(): # element can be already selected by id
element.click()

def uncheck(self, ids=None, labels=None):
"""
Uncheck specified checkboxes of the checkbox group. Specification can be based on checkbox id, or it's label.
@param ids: specify checkboxes by id
@param labels: specify checkboxes by labels
@return: None
"""
ids = ids if ids else []
labels = labels if labels else []
elms = []
for cb_id in ids:
elms.append(self.browser.element(self.checkbox_by_id.format(cb_id)))
for label in labels:
elms.append(self.browser.element(self.checkbox_by_label.format(label)))
for elem in elms:
if elem.is_selected():
elem.click()

def check_all(self):
"""
Check all checkboxes of the group
@return: None
"""
for element in self.browser.elements(self.checkboxes):
if not element.is_selected():
element.click()

def uncheck_all(self):
"""
Uncheck all checkboxes of the group
@return:
"""
for element in self.browser.elements(self.checkboxes):
if element.is_selected():
element.click()


class ThreescaleDropdown(GenericLocatorWidget):
"""Specific dropdown of 3scale pages"""

Expand Down
2 changes: 1 addition & 1 deletion testsuite/ui/widgets/oas3.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Endpoint(ParametrizedView):

PARAMETERS = ("endpoint_method", "endpoint_path")
ROOT = ParametrizedLocator(
"//span[@data-path={endpoint_path|quote}]/.."
"//span[@data-path={endpoint_path|quote}]/../.."
"/span[text()={endpoint_method|quote}]"
'/ancestor::div[contains(@id, "operations")]'
)
Expand Down

0 comments on commit ad6edfa

Please sign in to comment.