def add_library_item_to_dataflow(self, item_name, instance_name, check=True, offset=None, prefix=None, args=None): """ Add component `item_name`, with name `instance_name`. """ offset = offset or (90, 90) xpath = "//*[@id='-dataflow']" library_item = self.get_library_item(item_name) target = WebDriverWait(self.browser, TMO).until( lambda browser: browser.find_element_by_xpath(xpath)) for retry in range(3): try: chain = ActionChains(self.browser) if False: chain.drag_and_drop(library_item, target) else: chain.click_and_hold(library_item) chain.move_to_element_with_offset(target, offset[0], offset[1]) chain.release(None) chain.perform() except StaleElementReferenceException: if retry < 2: logging.warning('add_library_item_to_dataflow:' ' StaleElementReferenceException') library_item = self.get_library_item(item_name) target = WebDriverWait(self.browser, TMO).until( lambda browser: browser.find_element_by_xpath(xpath)) else: raise else: break page = ArgsPrompt(self.browser, self.port) page.set_name(instance_name) if args is not None: for i, arg in enumerate(args): page.set_argument(i, arg) page.click_ok() # Check that the prompt is gone so we can distinguish a prompt problem # from a dataflow update problem. time.sleep(0.25) self.browser.implicitly_wait(1) # We don't expect to find anything. try: eq(len(self.browser.find_elements(*page('prompt')._locator)), 0) finally: self.browser.implicitly_wait(TMO) retval = None if check: # Check that it's been added. retval = WebDriverWait(self.browser, TMO).until( lambda browser: self.get_dataflow_figure(instance_name, prefix)) return retval
def fill_slot_from_library(self, slot, classname, args=None): """ Fill slot with `classname` instance from library. """ for retry in range(3): try: button = self.find_library_button(classname) chain = ActionChains(self.browser) chain.move_to_element(button) chain.click_and_hold(button) chain.move_to_element(slot.root) chain.release(None) chain.perform() except StaleElementReferenceException: if retry < 2: logging.warning('fill_slot_from_library:' 'StaleElementReferenceException') else: raise else: break # Handle arguments for the slotted class page = ArgsPrompt(self.browser, self.port) argc = page.argument_count() if argc > 0: if args is not None: for i, arg in enumerate(args): page.set_argument(i, arg) page.click_ok() # Check that the prompt is gone so we can distinguish a prompt problem # from a dataflow update problem. time.sleep(0.5) self.browser.implicitly_wait(1) # We don't expect to find anything. try: eq(len(self.browser.find_elements(*page('prompt')._locator)), 0) finally: self.browser.implicitly_wait(TMO)