class data_view(View): # noqa table = Table('//*[@id="report_list_div"]//table') field = SelectorDropdown("id", "filterFieldTypeMenu") search_text = SearchBox(locator='//input[contains(@placeholder, "search text")]') # TODO: Write a separate paginator for data view def child_widget_accessed(self, widget): if self.parent.view_selector.selected != "Data View": self.parent.view_selector.select("Data View")
class hosts(View): # noqa fill_strategy = WaitFillViewStrategy("15s") hostname = SearchBox(id='host-selection') @property def is_displayed(self): return self.hostname.is_displayed def after_fill(self, was_change): self.parent.next_btn.click()
class OptimizationSavedReportDetailsView(OptimizationView): field = SelectorDropdown("id", "filterFieldTypeMenu") search_text = SearchBox( locator='//input[contains(@placeholder, "search text")]') table = Table('//*[@id="main_div"]//table') @property def is_displayed(self): context_obj = self.context["object"] return (self.logged_in_as_current_user and self.title.text == context_obj.name and self.table.is_displayed and self.navigation.currently_selected == ["Overview", "Optimization"] and self.breadcrumb.locations == [ "Overview", "Optimization", context_obj.parent.parent.menu_name, context_obj.name ])
class MigrationPlanView(MigrationView): dashboard_cards = View.nested(DashboardCards) paginator_view = View.include(V2VPaginatorPane, use_parent=True) title = Text('.//div[contains(@class, "pull-left")]//h3') create_migration_plan = Text(locator='(//a|//button)[text()="Create Migration Plan"]') configure_providers = Text(locator='//a[text()="Configure Providers"]') sort_type_dropdown = SelectorDropdown("id", "sortTypeMenu") sort_direction = Text(locator=".//span[contains(@class,'sort-direction')]") progress_card = MigrationProgressBar() search_box = SearchBox(locator=".//div[contains(@class,'input-group')]/input") clear_filters = Text(".//a[text()='Clear All Filters']") @property def in_migration_plan(self): return ( self.in_explorer and self.create_migration_plan.is_displayed and len(self.browser.elements('.//div[contains(@class,"card-pf")]')) > 0 and len(self.browser.elements(PFIcon.icons.WARNING)) < 1 ) @property def is_displayed(self): return self.in_migration_plan
class vms(View): # noqa import_btn = Button("Import") hidden_field = HiddenFileInput(locator='.//input[contains(@accept,".csv")]') clear_filters = Text(".//a[text()='Clear All Filters']") error_text = Text('.//h3[contains(@class,"blank-slate-pf-main-action") and ' 'contains(text(), "Error:")]') popover_text = Text(locator='.//div[contains(@class, "popover-content")]') table = Table( './/div[contains(@class, "container-fluid")]/table', column_widgets={ "Select": Checkbox(locator=".//input"), 1: Text('.//span/button[contains(@class,"btn btn-link")]'), }, ) search_box = SearchBox( locator='.//div[contains(@class, "modal-content")]' '//div[contains(@class,"input-group")]/input' ) @property def is_displayed(self): return self.table.is_displayed and ( len(self.browser.elements(".//div[contains(@class,'spinner')]")) == 0 ) def csv_import(self, vm_list): """ Vm's can be imported using csv for migration. Opens a temporary csv with Columns Name and Provider and fill it with vm's from vm_list to be used in fill Args: vm_list: list of vm's to be imported through csv """ temp_file = tempfile.NamedTemporaryFile(suffix=".csv") with open(temp_file.name, "w") as file: headers = ["Name", "Provider"] writer = csv.DictWriter(file, fieldnames=headers) writer.writeheader() for vm in vm_list: writer.writerow({"Name": vm.name, "Provider": vm.provider.name}) self.hidden_field.fill(temp_file.name) def fill(self, values): """ If importing Vm's from csv file , use the file created in csv_import method. Search Vm using searchbox. Select checkbox(row[0]) of all the Vm's imported in the table Args: values : List of Vm's """ csv_import = values.get('csv_import') vm_list = values.get('vm_list') if csv_import: self.csv_import(vm_list) for vm in vm_list: self.search_box.fill(vm.name) for row in self.table.rows(): if vm.name in row.vm_name.read(): # select checkbox row[0].fill(True) self.clear_filters.click() was_change = True self.after_fill(was_change) return was_change def after_fill(self, was_change): self.parent.next_btn.click()