def _click_animated(context, click_x, click_y, button="b1c", delay=1, timing=None): start_x = context._root.get('last_mouse_x', 0) start_y = context._root.get('last_mouse_y', 0) try: if timing is None: timing = 1 / math.sqrt( math.pow(math.fabs(start_x - click_x), 2) + math.pow(math.fabs(start_y - click_y), 2)) except: timing = 0.01 l.simulatemousemove(start_x, start_y, click_x, click_y, timing) time.sleep(delay) l.generatemouseevent(click_x, click_y, button) context._root['last_mouse_x'] = click_x context._root['last_mouse_y'] = click_y time.sleep( delay ) #clicking usually needs a task switch to some UI thread to process it
def generate_mouse_event(self, x, y, eventType='b1c'): """ Generate mouse event on x, y co-ordinates. Used SPI_generateMouseEvent to generate the mouse events. @param x: X co-ordinate @type x: int @param y: Y co-ordinate @type y: int @param eventType: Mouse click type @type eventType: string @return: 1 on success. @rtype: integer """ try: self._info("generate mouse event (%s) at point (%d, %d)" % (eventType, x, y)) return ldtp.generatemouseevent(int(x), int(y), eventType) except LdtpError: raise LdtpError( 'generate mouse event failed, please check the parameters.')
ldtp.waittillguiexist(fenetre) ldtp.click(fenetre, u"btnPi\xe8ces") fenetre = "*une nouvelle*" ldtp.waittillguiexist(fenetre) ldtp.mouseleftclick(fenetre, 'txt1') ldtp.enterstring(fenetre, 'txt1', "disque dur") #ldtp.mouseleftclick(fenetre, 'txt0') #ldtp.enterstring(fenetre, 'txt0', "") ldtp.mouseleftclick(fenetre, 'sldr0') ldtp.enterstring(fenetre, 'txt0', "<del><del><del><del><del>999,99") ldtp.click(fenetre, 'btnSaveEnter') fenetre = "*Traitement d'une fiche de maintenance*" coordinate = ldtp.getobjectsize(fenetre, 'tbl1') ldtp.generatemouseevent(coordinate[0]+120, coordinate[1]+35, 'b1d') ldtp.keypress('<ctrl>') ldtp.keypress('a') ldtp.keyrelease('<ctrl>') ldtp.keypress('<bksp>') ldtp.keyrelease('<bksp>') ajouterPressePapier("Lorem ipsum dolor sit amet, consectetur adipiscing elit. In rhoncus felis sed condimentum pretium. Etiam vulputate sapien eu massa consectetur imperdiet. Nunc non pulvinar magna. Donec fermentum sagittis condimentum. Vivamus et quam nec ante turpis ") ldtp.keypress('<ctrl>') ldtp.keypress('v') ldtp.keyrelease('<ctrl>') ldtp.click(fenetre, 'btnSaveEnter') ldtp.click('*Gestion de dossiers*', 'btnTraiter') ldtp.waittillguiexist(fenetre)
l.launchapp(app) l.waittillguiexist(app_name) l.imagecapture(app_name, os.path.join(basePath, app + ".png")) l.generatekeyevent("<alt><f4>") full_screen = l.imagecapture() os.rename(full_screen, os.path.join(basePath, "xfce-desktop.png")) # I/O error workaround l.launchapp("xfce4-terminal") time.sleep(1) l.generatekeyevent("<alt><f4>") # move the mouse away to avoid tool tips l.generatemouseevent(800, 600, "abs") # appfinder crashes on imagecapture() - (has to window?) l.launchapp("xfce4-appfinder") l.waittillguiexist("ApplicationFinder") full_screen = l.imagecapture() os.rename(full_screen, os.path.join(basePath, "xfce4-appfinder-main.png")) l.generatekeyevent("<alt><f4>") do_screenshot("xfce4-terminal", "Terminal") do_screenshot("xfce4-clipman-settings", "Clipman") do_screenshot("xfce4-display-settings", "Display") do_screenshot("xfce4-keyboard-settings", "Keyboard") do_screenshot("xfce4-mime-settings", "MIME Type Editor") do_screenshot("xfce4-mouse-settings", "Mouse and Touchpad") do_screenshot("xfce4-settings-manager", "Settings")
def step_impl(context): l.simulatemousemove(0,0,100,100) l.generatemouseevent(200,200) # There shouldn't be anything
l.waittillguiexist(app_name) l.imagecapture(app_name, os.path.join(basePath, app + ".png")) l.generatekeyevent("<alt><f4>") full_screen=l.imagecapture() os.rename(full_screen, os.path.join(basePath, "xfce-desktop.png")) # I/O error workaround l.launchapp("xfce4-terminal") time.sleep(1) l.generatekeyevent("<alt><f4>") # move the mouse away to avoid tool tips l.generatemouseevent(800,600, "abs") # appfinder crashes on imagecapture() - (has to window?) l.launchapp("xfce4-appfinder") l.waittillguiexist("ApplicationFinder") full_screen=l.imagecapture() os.rename(full_screen, os.path.join(basePath, "xfce4-appfinder-main.png")) l.generatekeyevent("<alt><f4>") do_screenshot("xfce4-terminal", "Terminal") do_screenshot("xfce4-clipman-settings", "Clipman") do_screenshot("xfce4-display-settings", "Display") do_screenshot("xfce4-keyboard-settings", "Keyboard") do_screenshot("xfce4-mime-settings", "MIME Type Editor") do_screenshot("xfce4-mouse-settings", "Mouse and Touchpad") do_screenshot("xfce4-settings-manager", "Settings")
def take_screenshot(self, option, effects, delay): """ Complete the "Take Screenshot" dialog box by choosing one option from whole desktop, current window and select area to grab, then clicking Take Screenshot. You must have started the application already. @type option: char @param option: the different name of the radio button @type effects: int @param effects: 1 to set effects on, 0 to set effects off @type delay: int @param delay: The number of seconds to delay before taking the screenshot. """ screenshot = ooldtp.context(self.WINDOW) """ To choose the radio button according to test case """ if option.__contains__("desktop"): radio_button = self.GRAB_THE_WHOLE_DESKTOP_RADIO elif option.__contains__("window"): radio_button = self.GRAB_THE_CURRENT_WINDOW_RADIO elif option.__contains__("area"): radio_button = self.GRAB_A_SELECTED_AREA # To click the radio button while screenshot.getchild(radio_button).verifyuncheck(): screenshot.getchild(radio_button).click() # To set the effects on/off according to test case if option.__contains__("desktop"): if effects == 1: while screenshot.getchild(self.CHK_INCLUDE_POINTER).verifyuncheck(): screenshot.getchild(self.CHK_INCLUDE_POINTER).check() elif effects == 0: while screenshot.getchild(self.CHK_INCLUDE_POINTER).verifycheck(): screenshot.getchild(self.CHK_INCLUDE_POINTER).uncheck() elif option.__contains__("window"): if effects == 1: while screenshot.getchild(self.CHK_INCLUDE_POINTER).verifyuncheck(): screenshot.getchild(self.CHK_INCLUDE_POINTER).check() while screenshot.getchild(self.CHK_INCLUDE_THE_WINDOW_BORDER).verifyuncheck(): screenshot.getchild(self.CHK_INCLUDE_THE_WINDOW_BORDER).check() screenshot.getchild(self.CBO_APPLY_EFFECT).selectindex(random.randint(1, 2)) elif effects == 0: while screenshot.getchild(self.CHK_INCLUDE_POINTER).verifycheck(): screenshot.getchild(self.CHK_INCLUDE_POINTER).uncheck() while screenshot.getchild(self.CHK_INCLUDE_THE_WINDOW_BORDER).verifycheck(): screenshot.getchild(self.CHK_INCLUDE_THE_WINDOW_BORDER).uncheck() screenshot.getchild(self.CBO_APPLY_EFFECT).selectindex(0) # To set the delay seconds if screenshot.getchild(self.GRAB_AFTER_DELAY_FIELD).hasstate("enabled"): while int(screenshot.getchild(self.GRAB_AFTER_DELAY_FIELD).getvalue()) != delay: screenshot.getchild(self.GRAB_AFTER_DELAY_FIELD).setvalue(delay) screenshot.getchild(self.TAKE_SCREENSHOT_BUTTON).click() ldtp.waittillguinotexist(self.WINDOW) # Select the area of the screen for the screenshot. As long as your screen is # larger than 200x200px this should work fine. if option.__contains__("area"): try: ldtp.generatemouseevent(100, 100, "b1p") # button 1 press ldtp.generatemouseevent(200, 200, "abs") # move mouse to 200,200 ldtp.generatemouseevent(200, 200, "b1r") # button 1 release except ldtp.LdtpExecutionError: raise ldtp.LdtpExecutionError, "Error selecting screen area"