コード例 #1
0
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
import bootstrap
from config import Config
from log import EntityLoggerProxy
from log.level import TRACE
from maps.calculator import Calculator
from launcher import Launcher

"""
Simple example that validates that the calculator is present on the screen.
Results can be found in the /results directory. 
"""
    
# Change logging level verbosity
EntityLoggerProxy.getLogger().setLevel(TRACE)
Config.setScreenshotLoggingLevel(TRACE)

# Launch the Calculator binary
calculator = Launcher.run('Calculator')

# Validate that the calculator exists on the screen
calculator.validate()
コード例 #2
0
 def __init__(self):
     self.argStore = {}
     self.logger = EntityLoggerProxy(self)
コード例 #3
0
class SikuliFwRfAbstractLib(object):
    """
    Base class for SikuliFramework Application entities, helps bridge SikuliFW with RobotFramework. 
    """

    logger = None
    argStore = None
    entity = None

    def __init__(self):
        self.argStore = {}
        self.logger = EntityLoggerProxy(self)

    def displayConfig(self):
        self.logger.info("%s" % Config.toString())

    def validate(self, *args):
        """
        Validates an entity, finding it on the screen
        """

        # Set the context, take it if it's the first in the list
        try:
            context = self.retrieve(args[0])
            args = args[1:]  # Remove the first, ie. pop
            context.validate()  # Validate this first

        except KeyNotInArgStorageException:
            context = self.entity

        # Perform lots of clicks and stuff
        for target in args:
            self.logger.info("[%s] selecting [%s]" % (context, target))
            context = context[target]
            context.validate()  # Ensure each is validated

        # Let the entity do the selectin
        return self.store(context)

    def select(self, *args):

        # Set the context, take it if it's the first in the list
        try:
            context = self.retrieve(args[0])
            args = args[1:]  # Remove the first, ie. pop
        except KeyNotInArgStorageException:
            context = self.entity

        # Perform lots of clicks and stuff
        for target in args:
            self.logger.info("[%s] selecting [%s]" % (context, target))
            context = context[target]

        # Let the entity do the selectin
        return self.store(context)

    def click(self, *args):

        # Set the context, take it if it's the first in the list
        try:
            context = self.retrieve(args[0])
            args = args[1:]  # Remove the first, ie. pop
        except KeyNotInArgStorageException:
            context = self.entity

        # Perform lots of clicks and stuff
        for target in args:

            target = str(target)

            self.logger.info("[%s] executing [%s]" % (context, target))
            context = context[target]

            # Perform the click
            if isinstance(context, ClickableEntity):
                context = context.click()

        return self.store(context)

    def type(self, *args):

        try:
            # try format (context, target, text)
            context = self.retrieve(args[0])
            targetArgs = [
                args[1],
            ]
            text = args[2]
        except KeyNotInArgStorageException:

            # Except Try format (value, targetArg0..N)
            try:
                context = self.retrieve(args[1])
                targetArgs = args[2:]
            except KeyNotInArgStorageException:
                context = self.entity
                targetArgs = args[1:]

            text = args[0]

        # Try and find target
        for target in targetArgs:
            context = context[target]

        return self.store(context.type(text))

    def waitUntilVanish(self, target=None, timeout=None):

        if target:
            # Set the context, take it if it's the first in the list
            try:
                context = self.retrieve(target)
            except KeyNotInArgStorageException:
                context = self.entity[target]
        elif self.entity:
            context = self.entity
        else:
            raise Exception("Unable to determine context")

        kargs = {}

        # Add a timeout if it's specified
        if timeout:
            kargs['timeout'] = timeout

        return self.store(context.waitUntilVanish(**kargs))

    def waitUntilAppears(self, target=None, timeout=None):

        if target:
            # Set the context, take it if it's the first in the list
            try:
                context = self.retrieve(target)
            except KeyNotInArgStorageException:
                context = self.entity[target]
        elif self.entity:
            context = self.entity
        else:
            raise Exception("Unable to determine context")

        kargs = {}

        # Add a timeout if it's specified
        if timeout:
            kargs['timeout'] = timeout

        return self.store(context.waitUntilAppears(**kargs))

    def showConfig(self):
        self.logger.info(Config.toString())

    def setLogLevel(self, level):
        """ Change the level of detail that is logged """

        level = str(level)

        if str.lower(level) == 'info':
            Logger.setLevel(INFO)
        elif str.lower(level) == 'debug':
            Logger.setLevel(DEBUG)
        elif str.lower(level) == 'trace':
            Logger.setLevel(TRACE)
        else:
            raise Exception("Logging level [%s] is not supported" % level)

    def setScreenshotLogLevel(self, level):
        """ Change the level of detail that is logged """

        level = str(level)

        if str.lower(level) == 'INFO':
            Config.setScreenshotLoggingLevel(INFO)
        elif str.lower(level) == 'debug':
            Config.setScreenshotLoggingLevel(DEBUG)
        elif str.lower(level) == 'trace':
            Config.setScreenshotLoggingLevel(TRACE)
        else:
            raise Exception("Screenshot logging level [%s] is not supported" %
                            level)

    def retrieve(self, key):
        """ Retrieve an argument from storage using a key """

        # assert the key is a string
        assert isinstance(key, str) or isinstance(key, unicode)

        try:
            self.logger.info("Resolved Entity=%%s",
                             self.logger.getFormatter()(self.argStore[key]))
            return self.argStore[key]
        except KeyError:

            # We cannot find the key in storage
            raise KeyNotInArgStorageException()

    def store(self, var):
        """ Store an argument and return the key """

        # The key becomes the type of variable
        key = str(type(var))

        self.argStore[key] = var
        return key

    def sleep(self, duration):
        """
        Pauses the script for N seconds
        """

        sleep(int(duration))

    def captureScreen(self):
        self.logger.info("Screen=%%s",
                         self.logger.getFormatter()(Config.screen))

    def assertBaseline(self, *args):

        # Set the context, take it if it's the first in the list
        try:
            context = self.retrieve(args[0])
            args = args[1:]  # Remove the first, ie. pop
        except KeyNotInArgStorageException:
            context = self.entity

        context.assertBaseline(args[0])

    def assertEquals(self, *args):

        # Set the context, take it if it's the first in the list
        try:
            context = self.retrieve(args[0])
            args = args[1:]  # Remove the first, ie. pop
        except KeyNotInArgStorageException:
            context = self.entity

        context.assertEquals(args[0])

    def convertUnicodeToAscii(self, *args):

        fixedArgs = []

        for arg in args:
            arg = str(arg) if isinstance(arg, unicode) else arg
            fixedArgs.append(arg)

        return fixedArgs
コード例 #4
0
 def __init__(self):
     self.argStore = {}
     self.logger = EntityLoggerProxy(self)
コード例 #5
0
class SikuliFwRfAbstractLib(object):
    """
    Base class for SikuliFramework Application entities, helps bridge SikuliFW with RobotFramework. 
    """
    
    logger = None
    argStore = None
    entity = None
    
    def __init__(self):
        self.argStore = {}
        self.logger = EntityLoggerProxy(self)
    
    def displayConfig(self):
        self.logger.info("%s" % Config.toString())
        
    def validate(self, *args):
        """
        Validates an entity, finding it on the screen
        """        
        
        # Set the context, take it if it's the first in the list        
        try:
            context = self.retrieve(args[0])
            args = args[1:] # Remove the first, ie. pop            
            context.validate() # Validate this first
            
        except KeyNotInArgStorageException:
            context = self.entity        
            
        # Perform lots of clicks and stuff
        for target in args:    
            self.logger.info("[%s] selecting [%s]" % (context, target))
            context = context[target]
            context.validate() # Ensure each is validated
                    
        # Let the entity do the selectin
        return self.store(context)
        

    def select(self, *args):
        
        # Set the context, take it if it's the first in the list        
        try:
            context = self.retrieve(args[0])
            args = args[1:] # Remove the first, ie. pop
        except KeyNotInArgStorageException:
            context = self.entity        
            
        # Perform lots of clicks and stuff
        for target in args:    
            self.logger.info("[%s] selecting [%s]" % (context, target))
            context = context[target]
                    
        # Let the entity do the selectin
        return self.store(context)
    
    def click(self, *args):
        
        # Set the context, take it if it's the first in the list        
        try:
            context = self.retrieve(args[0])
            args = args[1:] # Remove the first, ie. pop
        except KeyNotInArgStorageException:
            context = self.entity
        
        # Perform lots of clicks and stuff
        for target in args:            

            target = str(target)
            
            self.logger.info("[%s] executing [%s]" % (context, target))
            context = context[target]

            # Perform the click 
            if isinstance(context, ClickableEntity):
                context = context.click() 
 
        return self.store(context)
    
    
    def type(self, *args):

        try:
            # try format (context, target, text)
            context = self.retrieve(args[0])
            targetArgs = [args[1],]
            text = args[2]
        except KeyNotInArgStorageException:
                    
            # Except Try format (value, targetArg0..N)
            try:
                context = self.retrieve(args[1])
                targetArgs = args[2:]
            except KeyNotInArgStorageException:
                context = self.entity
                targetArgs = args[1:]
            
            text = args[0]    
            
            
        # Try and find target
        for target in targetArgs:            
            context = context[target]            
                    
        return self.store(context.type(text))

    def waitUntilVanish(self, target=None, timeout=None):
        
        if target:
            # Set the context, take it if it's the first in the list        
            try:
                context = self.retrieve(target)
            except KeyNotInArgStorageException:
                context = self.entity[target]
        elif self.entity:
            context = self.entity
        else:
            raise Exception("Unable to determine context")     
        
        kargs = {}
        
        # Add a timeout if it's specified
        if timeout:
            kargs['timeout'] = timeout
        
        return self.store(context.waitUntilVanish(**kargs))
    
    def waitUntilAppears(self, target=None, timeout=None):
        
        if target:
            # Set the context, take it if it's the first in the list        
            try:
                context = self.retrieve(target)
            except KeyNotInArgStorageException:
                context = self.entity[target]
        elif self.entity:
            context = self.entity
        else:
            raise Exception("Unable to determine context")     
        
        kargs = {}
        
        # Add a timeout if it's specified
        if timeout:
            kargs['timeout'] = timeout
        
        return self.store(context.waitUntilAppears(**kargs))
            
    def showConfig(self):        
        self.logger.info(Config.toString())
    
    def setLogLevel(self, level):
        """ Change the level of detail that is logged """
        
        level = str(level)
        
        if str.lower(level) == 'info':
            Logger.setLevel(INFO)
        elif str.lower(level) == 'debug':
            Logger.setLevel(DEBUG)
        elif str.lower(level) == 'trace':
            Logger.setLevel(TRACE)
        else:
            raise Exception("Logging level [%s] is not supported" % level)

    def setScreenshotLogLevel(self, level):
        """ Change the level of detail that is logged """
        
        level = str(level)
        
        if str.lower(level) == 'INFO':
            Config.setScreenshotLoggingLevel(INFO)
        elif str.lower(level) == 'debug':
            Config.setScreenshotLoggingLevel(DEBUG)
        elif str.lower(level) == 'trace':
            Config.setScreenshotLoggingLevel(TRACE)
        else:
            raise Exception("Screenshot logging level [%s] is not supported" % level)
            
            
    def retrieve(self, key):
        """ Retrieve an argument from storage using a key """
        
        # assert the key is a string
        assert isinstance(key, str) or isinstance(key, unicode)
        
        try:
            self.logger.info("Resolved Entity=%%s", self.logger.getFormatter()(self.argStore[key]))
            return self.argStore[key]
        except KeyError:
            
            # We cannot find the key in storage
            raise KeyNotInArgStorageException()
    
    def store(self, var):
        """ Store an argument and return the key """
        
        # The key becomes the type of variable
        key = str(type(var))
        
        self.argStore[key] = var
        return key
    
    def sleep(self, duration):
        """
        Pauses the script for N seconds
        """
                
        sleep(int(duration))
    
    def captureScreen(self):
        self.logger.info("Screen=%%s", self.logger.getFormatter()(Config.screen))
        
    def assertBaseline(self, *args):
        
        # Set the context, take it if it's the first in the list        
        try:
            context = self.retrieve(args[0])
            args = args[1:] # Remove the first, ie. pop
        except KeyNotInArgStorageException:
            context = self.entity            
            
        context.assertBaseline(args[0])

    def assertEquals(self, *args):
        
        # Set the context, take it if it's the first in the list        
        try:
            context = self.retrieve(args[0])
            args = args[1:] # Remove the first, ie. pop
        except KeyNotInArgStorageException:
            context = self.entity            
            
        context.assertEquals(args[0])
            
    
    def convertUnicodeToAscii(self, *args):
        
        fixedArgs = []
        
        for arg in args:
            arg = str(arg) if isinstance(arg, unicode) else arg
            fixedArgs.append(arg)
        
        return fixedArgs
コード例 #6
0
ファイル: resize.py プロジェクト: way030724/sikuli-framework
from launcher import Launcher

"""
Simple example that validates that the calculator is present on the screen.
This example does not use the Launcher() class so it assumes that the application
is already running.  Results can be found in the /results directory. 
"""

# Change logging level verbosity
#EntityLoggerProxy.getLogger().setLevel(TRACE)
Config.setScreenshotLoggingLevel(TRACE)


# Launch the Calculator binary
textedit = Launcher.run('TextEdit')
logger = EntityLoggerProxy(textedit)

# Type some text in the text area
textedit[TextEdit.TEXT_AREA].type("This is a demo of SikuliFramework")

# Resize the application size 4 times
for i in range(0,4):
    
    # Get the current application region
    region = textedit.validate().region
    
    # Alternate between growing / shrinking application width
    offset = 100 * (1 - ((i % 2)*2))
    
    # Modify the size of current application region
    morph = RegionMorph(0, 0, offset, 0)