Exemple #1
0
 def testAddImagePath(self):
     old_path = []
     new_path = None
     for p in getImagePath():
         old_path.append(p)
     if Env.isWindows():
         new_path = r"C:\Users"
         path_utils.add_image_path(new_path)
     else:
         new_path = os.path.join("/usr", "bin")
         path_utils.add_image_path(new_path)
     self.assertNotEqual(old_path, getImagePath())
     self.assertNotEqual(len(old_path), len(getImagePath()))
     self.assertTrue(len(old_path) < len(getImagePath()))
     self.assertIn(new_path, getImagePath())
Exemple #2
0
# adding a path to exec path do not add it to image path
print("\nDoesn t change image path:")
print(getImagePath())

# now path has changed so we can import modules from new_path and use their functions
print("\nImporting a new sikuli module")
import path_utils
path_utils.print_execution_path()
# importing a sikuli module will also add it to image path
path_utils.print_image_path()

# if [ROOT]/.../allos is in sys.path, we can now add path(s) with ...
# use path_utils.get_parent_dirname(path, level) to get level x parent dirname
root_path = path_utils.get_parent_dirname(getBundlePath(), 2)
new_path1 = os.path.join(root_path, "src", "objects")
path_utils.add_execution_path(new_path1)
path_utils.print_execution_path()
# path already exists mistake is handled
path_utils.add_execution_path(new_path1)
# incorrect path will raise Error
try:
    path_utils.add_execution_path((123, 'ZE'))
except Exception as e:
    print(e)

# we can add path to image path
path_utils.add_image_path(os.path.join(root_path, "imgs"))
path_utils.print_image_path()
# this doesn t change execution path
path_utils.print_execution_path()
def spe_imgpathutil(s):
    """

    """
    path_utils.add_image_path(
        os.path.join(context.rootpath, "imgs", "leboncoin", s))
Exemple #4
0
def launch_app(app_name=None, app_path=None, wait_img=False, timeout=10):
    """
    Open an application.

    Give:
    - app_name and ensure APPS[app_name] is defined
    - if APPS[app_name] is undefined, then give app_path
    - choose either to wait or not for images in imgs/app_name/start
    -> wait: set wait_img as True
    - default timeout is 10
    This will define a Sikuli App() instance and run it.

    :param app_name: application_name as in APPS
    :type path: str
    :param app_path: path to application executable or script
    :type app_path: str
    :param wait_img: wait for imgs in imgs/app_name/start or not
    :type wait_img: boolean
    :param timeout: timeout for wait for imgs in imgs/app_name/start or not
    :type timeout: int
    :return: Nothing
    :rtype: None

    """
    if DEBUG:
        print("Trying to launch application with parameters:")
        print("app_name: {}, app_path: {}, wait_img: {}, timeout: {}".format(
            app_name, app_path, wait_img, timeout))
        print("Actual OS is {}".format(Env.getOS()))
    # guess image library
    img_lib = os.path.join(path_utils.get_parent_dirname(getBundlePath(), 2),
                           "imgs", app_name.replace(' ', '_'))
    if DEBUG:
        print("img_lib: {}".format(img_lib))
    maximize_shortcut = SHORTCUTS[str(Env.getOS())]["maximize"]
    if DEBUG:
        print("maximize_shortcut: {}".format(maximize_shortcut))
    app = App(APPS[str(Env.getOS())][app_name]["path"])
    if not App(app_name).isRunning():
        if DEBUG:
            print("App {} currently not running.".format(app_name))
        app.open()
        if DEBUG:
            print("App {} should now be openned.".format(app_name))
    else:
        if DEBUG:
            print("App {} currently running, trying to focus ont it...".format(
                app_name))
        app.focus()
    if wait_img:
        print("Waiting for app images to ensure it is openned...")
        start = os.path.join(img_lib, "start")
        imgs = glob.glob(os.path.join(start, "*"))
        if DEBUG:
            print("All images to wait:")
            for im in imgs:
                print("\t{},".format(im))
        img2 = []
        for im in imgs:
            im = im.split(os.sep)[-1]
            img2.append(im)
        path_utils.add_image_path(start)
        path_utils.print_image_path()
        image_utils.wait_all(img2)
        if DEBUG:
            print("App is openned !")
    if Env.isWindows():
        type(*maximize_shortcut)
    # ToDo: fix shortcuts for MAC
    if DEBUG:
        print('App should now be maximized.')