def __init__(self, parent, id, number="", move_into=None, move_from=None, available_items="choices_chosen", chosen_items="members_chosen", logger=None): Widget.__init__(self, parent, logger=logger) self.available_options = Select(self, id=available_items) self.chosen_options = Select(self, id=chosen_items) self.id = id if number: self.number = "[{}]".format(number) else: self.number = number if isinstance(move_into, WidgetDescriptor): self._move_into = move_into.klass(self, **move_into.kwargs) else: self._move_into = move_into if isinstance(move_from, WidgetDescriptor): self._move_from = move_from.klass(self, **move_from.kwargs) else: self._move_from = move_from
class HostsChangeEnvironment(BaseLoggedInView): title = Text("//h4[text()='Change Environment - The" " following hosts are about to be changed']") table = SatTable("//div[@class='modal-body']//table") keep_selected = Checkbox(id='keep_selected') environment = Select(id='environment_id') submit = Text('//button[@onclick="submit_modal_form()"]') @property def is_displayed(self): return self.browser.wait_for_element(self.title, exception=False) is not None
class ProductCreateView(BaseLoggedInView): breadcrumb = BreadCrumb() name = TextInput(id='name') label = TextInput(id='label') gpg_key = Select(id='gpg_key_id') ssl_ca_cert = Select(id='ssl_ca_cert_id') ssl_client_cert = Select(id='ssl_client_cert_id') ssl_client_key = Select(id='ssl_client_key_id') sync_plan = Select(id='sync_plan_id') create_sync_plan = Text("//a[contains(@ng-click, 'openSyncPlanModal')]") description = TextInput(id='description') submit = Text("//button[contains(@ng-click, 'handleSave')]") @property def is_displayed(self): breadcrumb_loaded = self.browser.wait_for_element(self.breadcrumb, exception=False) return ( breadcrumb_loaded and self.breadcrumb.locations[0] == 'Products' and self.breadcrumb.read() == 'New Product' )
class FlavorAddForm(View): """ Represents Add Flavor page """ provider = Select(name='ems_id') flavor_name = TextInput(name='name') ram_size = TextInput(name='ram') vcpus = TextInput(name='vcpus') disk_size = TextInput(name='disk') swap_size = TextInput(name='swap') rxtx_factor = TextInput(name='rxtx_factor') public = BootstrapSwitch(name='is_public') add = Button('Add') cancel = Button('Cancel')
class Navbar(View): """ Navigation bar on top of every page except the login page. usermanagement is only available to admins """ ROOT = ".//nav[contains(@class,'navbar-pf-contextselector tendrl-header-container')]" title = Text(".//a[@class='navbar-brand']") clusters = Select(".//select[contains(@ng-change, 'goToClusterPage')]") modal = NavDropdown(".//button[@id='aboutModalDropdown']/parent::li") usermanagement = NavDropdown(".//a[@id='usermanagement']/parent::li") alerts = NavDropdown(".//a[@id='notifications']/parent::li") usermenu = NavDropdown(".//a[@id='usermenu']/parent::li")
class VMwareProviderForm(View): vcenter = TextInput(id='compute_resource_server') user = TextInput(id='compute_resource_user') password = TextInput(id='compute_resource_password') display_type = Select(id='compute_resource_display_type') vnc_console_passwords = Checkbox( id='compute_resource_set_console_password') enable_caching = Checkbox(id='compute_resource_caching_enabled') load_datacenters = Text("//*[contains(@id,'test_connection_button')]") def after_fill(self, was_change): self.load_datacenters.click()
class options(Tab): # noqa default_text_box = Input(name='default_value') field_required = DialogBootstrapSwitch(label='Required') default_value = DialogBootstrapSwitch(label='Default value') field_required = DialogBootstrapSwitch(label='Required') field_past_dates = DialogBootstrapSwitch(label='Show Past Dates') field_category = Select( locator= './/select[../../../../label[normalize-space(text())="Category"]]') validation = Input(name='validator_rule') visible = DialogBootstrapSwitch(label='Visible')
class ActivationKeyCreateView(BaseLoggedInView): name = TextInput(id='name') hosts_limit = LimitInput() description = TextInput(id='description') lce = LCESelector() content_view = Select(id='content_view_id') submit = Text("//button[contains(@ng-click, 'handleSave')]") @property def is_displayed(self): return self.browser.wait_for_element(self.name, exception=False) is not None
class PuppetRepository(View): upstream_url = TextInput(id='url') verify_ssl = Checkbox(id='verify_ssl_on_sync') upstream_username = TextInput(id='upstream_username') upstream_password = TextInput(id='upstream_password') mirror_on_sync = Checkbox(id='mirror_on_sync') publish_via_http = Checkbox(id='unprotected') http_proxy_policy = Select(id="http_proxy_policy") proxy_policy = ConditionalSwitchableView(reference='http_proxy_policy') @proxy_policy.register('Use specific HTTP Proxy') class SpecificHttpProxy(View): http_proxy = Select(id="http_proxy")
class MyView(View): the_reference = Select(id='switchabletesting-select') the_switchable_view = ConditionalSwitchableView( reference='the_reference') @the_switchable_view.register('foo') class FooView(View): widget = Text('//h3[@id="switchabletesting-1"]') @the_switchable_view.register('bar') class BarView(View): widget = Text('//h3[@id="switchabletesting-2"]')
class MyView(View): the_reference = Select(id='ewaopaopsdkgnjdsopjf') the_switchable_view = ConditionalSwitchableView( reference='the_reference') @the_switchable_view.register('foo') class FooView(View): widget = Text('//h3[@id="switchabletesting-1"]') @the_switchable_view.register('bar', default=True) class BarView(View): widget = Text('//h3[@id="switchabletesting-2"]')
class MyView(View): the_reference = Select(id="ewaopaopsdkgnjdsopjf") the_switchable_view = ConditionalSwitchableView( reference="the_reference") @the_switchable_view.register("foo") class FooView(View): widget = Text('//h3[@id="switchabletesting-1"]') @the_switchable_view.register("bar", default=True) class BarView(View): widget = Text('//h3[@id="switchabletesting-2"]')
class MyView(View): the_reference = Select(id="switchabletesting-select") the_switchable_view = ConditionalSwitchableView( reference="the_reference") @the_switchable_view.register("foo") class FooView(View): widget = Text('//h3[@id="switchabletesting-1"]') @the_switchable_view.register("bar") class BarView(View): widget = Text('//h3[@id="switchabletesting-2"]')
class options(PotentiallyInvisibleTab): # noqa form = ConditionalSwitchableView(reference="type") type = BootstrapSelect("button_type") @form.register("Default") class ButtonFormDefaultView(View): # noqa dialog = BootstrapSelect("dialog_id") @form.register("Ansible Playbook") class ButtonFormAnsibleView(View): # noqa playbook_cat_item = BootstrapSelect("service_template_id") inventory = AutomateRadioGroup(locator=".//input[@name='inventory']/..") hosts = Input(name="hosts") text = Input(name="name") display = Checkbox(name="display") hover = Input(name="description") image = FonticonPicker("button_icon") icon_color = ColourInput(id="button_color") open_url = Checkbox("open_url") display_for = Select(id="display_for") submit = Select(id="submit_how")
class instance_properties(View): # noqa table = Table('.//div[contains(@class, "container-fluid")]/table') edit_instance_properties = Text(locator='.//button/span[contains(@class, "pficon-edit")]') select_security_group = Select(locator='.//td[5]/select') select_flavor = Select(locator='.//td[6]/select') save_properties = Text(locator='.//div[contains(@class, "inline-edit-buttons")]' '/button[contains(@aria-label, "Save")]') @property def is_displayed(self): return self.table.is_displayed and ( not self.browser.elements(".//h3[contains(text(),'Discovering VMs')]") ) def fill(self, values): """ This is required only for OSP and only if we want to edit osp_security_group or osp_flavor otherwise not needed. If none them is to be edited only next needs to be clicked. Args: values: """ was_change = True osp_security_group = values.get('osp_security_group') osp_flavor = values.get('osp_flavor') if osp_security_group or osp_flavor: self.edit_instance_properties.click() self.select_security_group.wait_displayed() if osp_security_group: self.select_security_group.fill(osp_security_group) if osp_flavor: self.select_flavor.fill(osp_flavor) self.save_properties.click() self.after_fill(was_change) return was_change def after_fill(self, was_change): self.parent.next_btn.click()
class ActivationKeyDetailsView(BaseLoggedInView): name = TextInput(id='name') description = TextInput(id='description') unlimited_hosts = Checkbox(name='limit') max_hosts = TextInput(id='max_hosts') submit = Text("//button[contains(@ng-click, 'handleSave')]") lce = LCESelector() content_view = Select(id='content_view_id') @property def is_displayed(self): return self.browser.wait_for_element(self.name, exception=False) is not None
class optional_input_validators(View): expander = Text( ".//h2[contains(@data-target, '#optional_input_validators_')]") validator_type = Select( locator=".//select[contains(@name, '[validator_type]')]") validator_rule = TextInput( locator=".//input[contains(@name, '[validator_rule]')]") def __init__(self, parent, logger=None): View.__init__(self, parent, logger=logger) if 'collapsed' in self.browser.classes(self.expander): self.expander.click() self.browser.wait_for_element(self.validator_type, visible=True)
class foreign_input(View): ROOT = "//div[contains(@class, 'foreign_input')]" \ "/following-sibling::div[1]" target_template = Select( locator=".//select[contains(@name, '[target_template_id]')]") include_all = Checkbox( locator=".//input[contains(@id, 'include_all')]") include = TextInput( locator=".//input[contains(@name, '[include]')]") exclude = TextInput( locator=".//input[contains(@name, '[exclude]')]") def before_fill(self, values=None): self.parent.add_foreign_input_set.click()
class ContentCredentialCreateView(BaseLoggedInView): breadcrumb = BreadCrumb() name = TextInput(id='name') content_type = Select(id='content_type') content = TextInput(name='content') upload_file = FileInput(name='file_path') submit = Text("//button[contains(@ng-click, 'handleSave')]") @property def is_displayed(self): breadcrumb_loaded = self.browser.wait_for_element(self.breadcrumb, exception=False) return (breadcrumb_loaded and self.breadcrumb.locations[0] == 'Content Credential' and self.breadcrumb.read() == 'New Content Credential')
class ProductManageHttpProxy(BaseLoggedInView): """Represents Http Proxy Management page for Products.""" title = Text("//h4[text()='Http Proxy Management']") http_proxy_policy = Select(id="http_proxy_policy") proxy_policy = ConditionalSwitchableView(reference='http_proxy_policy') update = Text('//button[@ng-click="update()"]') @proxy_policy.register('Use specific HTTP Proxy') class ExistingProductForm(View): http_proxy = Select(id="http_proxy") @property def is_displayed(self): return self.browser.wait_for_element(self.title, exception=False) is not None
class options(WaitTab): # noqa default_text_box = Input(name='default_value') entry_point = EntryPoint(locator="//input[@class='form-control']", tree_id="treeview-tree-selector") field_required = DialogBootstrapSwitch(label='Required') default_value = DialogBootstrapSwitch(label='Default value') field_required = DialogBootstrapSwitch(label='Required') field_past_dates = DialogBootstrapSwitch(label='Show Past Dates') field_category = Select( locator= './/select[../../../../label[normalize-space(text())="Category"]]') validation_switch = DialogBootstrapSwitch(label='Validation') validation = Input(name='validator_rule') visible = DialogBootstrapSwitch(label='Visible')
class ControlImportExportView(BaseLoggedInPage): upload_button = InputButton("commit") export_button = Button("Export") commit_button = Button("Commit") upload_file = Input("upload[file]") export = BootstrapSelect("dbtype") policy_profiles = Select(id="choices_chosen_") @property def is_displayed(self): return (self.logged_in_as_current_user and self.navigation.currently_selected == ["Control", "Import / Export"])
class ActivationKeyCreateView(BaseLoggedInView): breadcrumb = BreadCrumb() name = TextInput(id='name') hosts_limit = LimitInput() description = TextInput(id='description') lce = ParametrizedView.nested(LCESelectorGroup) content_view = Select(id='content_view_id') submit = Text("//button[contains(@ng-click, 'handleSave')]") @property def is_displayed(self): breadcrumb_loaded = self.browser.wait_for_element(self.breadcrumb, exception=False) return (breadcrumb_loaded and self.breadcrumb.locations[0] == 'Activation Keys' and self.breadcrumb.read() == 'New Activation Key')
class ImportExportWidgetsView(CloudIntelReportsView): title = Text("#explorer_title_text") subtitle = Text(locator=".//div[@id='main_div']/h2") upload_file = FileInput(id="upload_file") upload_button = InputButton("commit") items_for_export = Select(id="widgets_") export_button = Button(value="Export") @property def is_displayed(self): return (self.in_intel_reports and self.title.text == "Import / Export" and self.subtitle.text == "Widgets" and self.import_export.tree.currently_selected == ["Import / Export", "Widgets"])
class VMwareProviderForm(View): vcenter = TextInput(id='compute_resource_server') user = TextInput(id='compute_resource_user') password = TextInput(id='compute_resource_password') display_type = Select(id='compute_resource_display_type') vnc_console_passwords = Checkbox( id='compute_resource_set_console_password') enable_caching = Checkbox(id='compute_resource_caching_enabled') @View.nested class datacenter(View): load_datacenters = Text("//a[contains(@id,'test_connection_button')]") value = FilteredDropdown(id='s2id_compute_resource_datacenter') def before_fill(self, values=None): self.load_datacenters.click()
class SyncPlanCreateView(BaseLoggedInView): breadcrumb = BreadCrumb() name = TextInput(id='name') description = TextInput(id='description') interval = Select(id='interval') cron_expression = TextInput(id='cron_expression') date_time = DateTime() submit = Text("//button[contains(@ng-click, 'handleSave')]") @property def is_displayed(self): breadcrumb_loaded = self.browser.wait_for_element(self.breadcrumb, exception=False) return (breadcrumb_loaded and self.breadcrumb.locations[0] == 'Sync Plans' and self.breadcrumb.read() == 'New Sync Plan')
class fields(ParametrizedView): # noqa PARAMETERS = ("key", ) input = Input(id=Parameter("key")) select = Select(id=Parameter("key")) param_input = Input(id=ParametrizedString("param_{key}")) dropdown = VersionPick({ Version.lowest(): BootstrapSelect(Parameter("key")), "5.9": BootstrapSelect(locator=ParametrizedLocator( './/div[contains(@class, "bootstrap-select")]/select[@id={key|quote}]/..' )) }) param_dropdown = VersionPick({ Version.lowest(): BootstrapSelect(ParametrizedString("param_{key}")), "5.9": BootstrapSelect(locator=ParametrizedLocator( ".//div[contains(@class, 'bootstrap-select')]/select[@id='param_{key}']/.." )) }) @property def visible_widget(self): if self.browser.wait_for_element(self.input.locator, exception=False): return self.input elif self.browser.wait_for_element(self.dropdown.locator, exception=False): return self.dropdown elif self.browser.wait_for_element(self.param_input.locator, exception=False): return self.param_input elif self.browser.wait_for_element(self.param_dropdown.locator, exception=False): return self.param_dropdown elif self.browser.wait_for_element(self.select.locator, exception=False): return self.select else: raise ItemNotFound("Visible widget is not found") def read(self): return self.visible_widget.read() def fill(self, value): return self.visible_widget.fill(value)
class YumRepository(View): arch_restrict = Select(id='architecture_restricted') upstream_url = TextInput(id='url') verify_ssl = Checkbox(id='verify_ssl_on_sync') upstream_username = TextInput(id='upstream_username') upstream_password = TextInput(id='upstream_password') download_policy = Select(id='download_policy') mirror_on_sync = Checkbox(id='mirror_on_sync') ignore_global_proxy = TextInput(id='ignore_global_proxy') checksum_type = Select(id='checksum_type') publish_via_http = Checkbox(id='unprotected') gpg_key = Select(id='gpg_key_id') ssl_ca_cert = Select(id='ssl_ca_cert_id') ssl_client_cert = Select(id='ssl_client_cert_id') ssl_client_key = Select(id='ssl_client_key_id')
class YumRepository(View): arch_restrict = Select(id='architecture_restricted') upstream_url = TextInput(id='url') verify_ssl = Checkbox(id='verify_ssl_on_sync') upstream_username = TextInput(id='upstream_username') upstream_password = TextInput(id='upstream_password') download_policy = Select(id='download_policy') mirror_on_sync = Checkbox(id='mirror_on_sync') checksum_type = Select(id='checksum_type') publish_via_http = Checkbox(id='unprotected') gpg_key = Select(id='gpg_key_id') ssl_ca_cert = Select(id='ssl_ca_cert_id') ssl_client_cert = Select(id='ssl_client_cert_id') ssl_client_key = Select(id='ssl_client_key_id') http_proxy_policy = Select(id="http_proxy_policy") proxy_policy = ConditionalSwitchableView(reference='http_proxy_policy') @proxy_policy.register('Use specific HTTP Proxy') class SpecificHttpProxy(View): http_proxy = Select(id="http_proxy")
class HostCollectionChangeAssignedContentView(BaseLoggedInView): title = Text("//h4[contains(., 'Content Host Bulk Content')]") lce = ParametrizedView.nested(LCESelectorGroup) content_view = Select(locator=".//select[@ng-model='selected.contentView']") assign = Text(locator=".//form/button[contains(@ng-click, 'showConfirm')]") @View.nested class dialog(ConfirmationDialog): ROOT = ".//div[@ng-show='showConfirm']" confirm_dialog = Text(".//button[contains(@ng-click, 'performAction')]") cancel_dialog = Text( ".//button[contains(@ng-click, 'showConfirm')" " and not(contains(@ng-click, 'performAction'))]" ) @property def is_displayed(self): """The view is displayed when it's title exists""" return self.browser.wait_for_element(self.title, exception=False) is not None
class ImportExportCustomReportsView(CloudIntelReportsView): title = Text("#explorer_title_text") subtitle = Text(locator=".//div[@id='main_div']/h2") upload_file = FileInput(id="upload_file") upload_button = InputButton("commit") overwrite = Checkbox("overwrite") preserve_owner = Checkbox("preserve_owner") items_for_export = Select(id="choices_chosen") export_button = Button(id="export_button") @property def is_displayed(self): return (self.in_intel_reports and self.title.text == "Import / Export" and self.subtitle.text == "Custom Reports" and self.import_export.tree.currently_selected == ["Import / Export", "Custom Reports"])
class MultiBoxSelect(Widget): TABLE = "//table[@id={}]{}" def __init__(self, parent, id, number="", move_into=None, move_from=None, available_items="choices_chosen", chosen_items="members_chosen", logger=None): Widget.__init__(self, parent, logger=logger) self.available_options = Select(self, id=available_items) self.chosen_options = Select(self, id=chosen_items) self.id = id if number: self.number = "[{}]".format(number) else: self.number = number if isinstance(move_into, WidgetDescriptor): self._move_into = move_into.klass(self, **move_into.kwargs) else: self._move_into = move_into if isinstance(move_from, WidgetDescriptor): self._move_from = move_from.klass(self, **move_from.kwargs) else: self._move_from = move_from def __locator__(self): return self.TABLE.format(quote(self.id), self.number) def _values_to_remove(self, values): return list((set(values) ^ self.read()) - set(values)) def _values_to_add(self, values): return list((set(values) ^ self.read()) - self.read()) @property def move_into_button(self): """This method is required to avoid 'Element is no longer attached to the DOM' Selenium exception. """ if isinstance(self._move_into, Button): button = self._move_into elif isinstance(self._move_into, basestring): button = self.browser.element(self._move_into, self) return button @property def move_from_button(self): if isinstance(self._move_from, Button): button = self._move_from elif isinstance(self._move_from, basestring): button = self.browser.element(self._move_from, self) return button def fill(self, values): if set(values) == self.read(): return False else: values_to_remove = self._values_to_remove(values) values_to_add = self._values_to_add(values) if values_to_remove: self.chosen_options.fill(values_to_remove) self.move_from_button.click() self.browser.plugin.ensure_page_safe() if values_to_add: self.available_options.fill(values_to_add) self.move_into_button.click() self.browser.plugin.ensure_page_safe() return True def read(self): return {option.text for option in self.chosen_options.all_options}