Beispiel #1
0
    def run(cls, className):
        """ Launch an application through reflection """

        cls.logger.info("is attempting to run [%s] wd=%s" %
                        (className, osLib.getcwd()))

        for appCls in Application.__subclasses__():
            if className == appCls.__name__:

                os = Env.getOS()
                osVersion = Env.getOSVersion(fullName=True)
                arch = java.lang.System.getProperty('os.arch')

                app = appCls()  # get an instance of this class
                binary = app.getBinary(
                    os, osVersion,
                    arch)  # get the binary to run from the instance
                cls.logger.info('created [%s] from [%s] [%s %s %s]' %
                                (className, binary, os, osVersion, arch))

                result = subprocess.Popen(binary,
                                          shell=True,
                                          cwd=app.getWorkingDir(
                                              os, osVersion, arch))

                return app

        raise Exception(
            "Unable to find Application sub-class [%s], ensure that it is included"
            % className)
 def load_module(self, module_name):
     #print "SikuliLoader.load_module", module_name
     module_name = _stripPackagePrefix(module_name)
     sys.path.append(self.path)
     img_path = java.lang.System.getProperty("SIKULI_IMAGE_PATH")
     if not img_path:
         img_path = ""
     elif img_path[-1] != Env.getSeparator():
         img_path += Env.getSeparator()
     img_path += self.path
     java.lang.System.setProperty("SIKULI_IMAGE_PATH", img_path)
     return self._load_module(module_name)
Beispiel #3
0
 def load_module(self, module_name):
     # print "SikuliLoader.load_module", module_name
     module_name = _stripPackagePrefix(module_name)
     sys.path.append(self.path)
     img_path = java.lang.System.getProperty("SIKULI_IMAGE_PATH")
     if not img_path:
         img_path = ""
     elif img_path[-1] != Env.getSeparator():
         img_path += Env.getSeparator()
     img_path += self.path
     java.lang.System.setProperty("SIKULI_IMAGE_PATH", img_path)
     return self._load_module(module_name)
Beispiel #4
0
def move_to(session_id=''):
    request_data = request.body.read()
    if request_data == None or request_data == '' or request_data == "{}":
        element_id = None
        xoffset = None
        yoffset = None
    else:
        element_id = json.loads(request_data).get('element')
        xoffset = json.loads(request_data).get('xoffset')
        yoffset = json.loads(request_data).get('yoffset')
    try:
        if element_id == None and (xoffset != None or yoffset != None):
            mouse_pos = Env.getMouseLocation()
            app.SS.mouseMove(Location(mouse_pos.getX()+xoffset,mouse_pos.getY()+yoffset))
        else:
            if xoffset != None or yoffset != None:
                #img = decode_value_from_wire(element_id)
                #app.SS.exists(img)
                #elem_pos = Region.getLastMatch().getTopLeft()
                elem_pos = app.element_list[element_id].getTopLeft()
                app.SS.mouseMove(Location(elem_pos.getX()+xoffset,elem_pos.getY()+yoffset))
            else: # just go to center of element
                #img = decode_value_from_wire(element_id)
                #app.SS.exists(img)
                #elem_pos = Region.getLastMatch().getCenter()
                elem_pos = app.element_list[element_id].getCenter()
                app.SS.mouseMove(Location(elem_pos.getX(),elem_pos.getY()))
    except:
        response.status = 400
        return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}

    app_response = {'sessionId': session_id,
        'status': 0,
        'value': {}}
    return app_response
Beispiel #5
0
    def run(cls, className):
        """ Launch an application through reflection """

        cls.logger.info("is attempting to run [%s] wd=%s" % (className, osLib.getcwd()))

        for appCls in Application.__subclasses__():
            if className == appCls.__name__:

                os = Env.getOS()
                osVersion = Env.getOSVersion(fullName=True)
                arch = java.lang.System.getProperty("os.arch")

                app = appCls()  # get an instance of this class
                binary = app.getBinary(os, osVersion, arch)  # get the binary to run from the instance
                cls.logger.info("created [%s] from [%s] [%s %s %s]" % (className, binary, os, osVersion, arch))

                result = subprocess.Popen(binary, shell=True, cwd=app.getWorkingDir(os, osVersion, arch))

                return app

        raise Exception("Unable to find Application sub-class [%s], ensure that it is included" % className)
Beispiel #6
0
def double_click(session_id=''):
    try:
        current_location = Env.getMouseLocation()
        app.SS.doubleClick(current_location)
    except:
        response.status = 400
        return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}

    app_response = {'sessionId': session_id,
        'status': 0,
        'value': {}}
    return app_response
Beispiel #7
0
 def assertThat(self, text):        
     self.validate()
     self.logger.info("Asserting [%s]" % text)
     
     baselinePath = self.config.imageBaseline + "/assert/" +  str(Env.getOS()).lower() + "/" + text + ".png"
     baseline = Pattern(baselinePath)
     
     # TODO: Refactor to allow for using RegionFinder class so PNG attributes can be used
     try:
         ImageLocator().locate( baselinePath )            
         result = self.region.find(baseline)                    
         self.logger.info('%%s matched %%s', self.logger.getFormatter()(result), self.logger.getFormatter()(baseline))
     except FindFailed, e:            
         self.logger.error('%%s does not match %%s', self.logger.getFormatter()(self.region), self.logger.getFormatter()(baseline))
         raise Exception("Assertion failure")        
Beispiel #8
0
def mouse_click(session_id=''):
    request_data = request.body.read()
    if request_data == None or request_data == '' or request_data == "{}":
        button = 0
    else:
        button = json.loads(request_data).get('button')
    try:
        current_location = Env.getMouseLocation()
        if button == 1:
            app.SS.mouseMove(current_location)
            app.SS.mouseDown(app.Buttons.MIDDLE)
            app.SS.mouseUp(app.Buttons.MIDDLE)
        elif button == 2:
            app.SS.rightClick(current_location)
        else: #button 1
            app.SS.click(current_location)
    except:
        response.status = 400
        return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}

    app_response = {'sessionId': session_id,
        'status': 0,
        'value': {}}
    return app_response
	def getResultFromClipboard(self):
		type('c', KEY_CTRL)
		return str(Env.getClipboard())
Beispiel #10
0
 def addHotkey(cls, key, modifiers, handler):
    class AnonyListener(HotkeyListener):
       def hotkeyPressed(self, event):
          handler(event)
    return JEnv.addHotkey(key, modifiers, AnonyListener())
    def addHotkey(cls, key, modifiers, handler):
        class AnonyListener(HotkeyListener):
            def hotkeyPressed(self, event):
                handler(event)

        return JEnv.addHotkey(key, modifiers, AnonyListener())