Beispiel #1
0
class LocalWeb(object):
    """
    Constants that represent URLs and images for local content.
    """

    # Simple blank HTML page
    BLANK_PAGE = 'http://127.0.0.1:%s/blank.htm' % parse_args().port

    # Local Firefox site
    FIREFOX_TEST_SITE = 'http://127.0.0.1:%s/firefox/' % parse_args().port
    FIREFOX_LOGO = 'firefox_logo.png'
    FIREFOX_IMAGE = 'firefox_full.png'
    FIREFOX_BOOKMARK = 'firefox_bookmark.png'
    FIREFOX_BOOKMARK_SMALL = 'firefox_bookmark_small.png'

    # Local Firefox Focus site
    FOCUS_TEST_SITE = 'http://127.0.0.1:%s/focus/' % parse_args().port
    FOCUS_LOGO = 'focus_logo.png'
    FOCUS_IMAGE = 'focus_full.png'
    FOCUS_BOOKMARK = 'focus_bookmark.png'
    FOCUS_BOOKMARK_SMALL = 'focus_bookmark_small.png'

    # Local Mozilla site
    MOZILLA_TEST_SITE = 'http://127.0.0.1:%s/mozilla/' % parse_args().port
    MOZILLA_LOGO = 'mozilla_logo.png'
    MOZILLA_IMAGE = 'mozilla_full.png'
    MOZILLA_BOOKMARK = 'mozilla_bookmark.png'
    MOZILLA_BOOKMARK_SMALL = 'mozilla_bookmark_small.png'

    # Local Pocket site
    POCKET_TEST_SITE = 'http://127.0.0.1:%s/pocket/' % parse_args().port
    POCKET_LOGO = 'pocket_logo.png'
    POCKET_IMAGE = 'pocket_full.png'
    POCKET_BOOKMARK = 'pocket_bookmark.png'
    POCKET_BOOKMARK_SMALL = 'pocket_bookmark_small.png'
Beispiel #2
0
def _click_at(location=None, clicks=None, duration=None, button=None):
    """Click on Location coordinates.

    :param location: Location , image name or Pattern.
    :param clicks: Number of mouse clicks.
    :param duration: Speed of hovering from current location to target.
    :param button: Mouse button clicked (can be left, right, middle, 1, 2, 3).
    :return: None.
    """

    if duration is None:
        duration = Settings.move_mouse_delay

    if location is None:
        location = Location(0, 0)

    pyautogui.moveTo(location.x, location.y, duration)
    if parse_args().highlight:
        hl = ScreenHighlight()
        hl.draw_circle(HighlightCircle(location.x, location.y, 15))
        hl.render()
    if clicks > 1:
        mouse = Controller()
        mouse.position = (location.x, location.y)
        mouse.click(Button.left, 2)
    else:
        pyautogui.click(clicks=clicks,
                        interval=Settings.click_delay,
                        button=button)

    if Settings.click_delay != DEFAULT_CLICK_DELAY:
        Settings.click_delay = DEFAULT_CLICK_DELAY
Beispiel #3
0
class LocalWeb(object):
    """Constants that represent URLs and images for local content. """

    _ip_host = '127.0.0.1'
    _domain_host = 'localhost.allizom.org'
    _port = parse_args().port
    """Simple blank HTML page."""
    BLANK_PAGE = 'http://%s:%s/blank.htm' % (_ip_host, _port)
    BLANK_PAGE_2 = 'http://%s:%s/blank.htm' % (_domain_host, _port)
    """Local Firefox site."""
    FIREFOX_TEST_SITE = 'http://%s:%s/firefox/' % (_ip_host, _port)
    FIREFOX_TEST_SITE_2 = 'http://%s:%s/firefox/' % (_domain_host, _port)
    FIREFOX_LOGO = Pattern('firefox_logo.png')
    FIREFOX_IMAGE = Pattern('firefox_full.png')
    FIREFOX_BOOKMARK = Pattern('firefox_bookmark.png')
    FIREFOX_BOOKMARK_SMALL = Pattern('firefox_bookmark_small.png')
    """Local Firefox Focus site."""
    FOCUS_TEST_SITE = 'http://%s:%s/focus/' % (_ip_host, _port)
    FOCUS_TEST_SITE_2 = 'http://%s:%s/focus/' % (_domain_host, _port)
    FOCUS_LOGO = Pattern('focus_logo.png')
    FOCUS_IMAGE = Pattern('focus_full.png')
    FOCUS_BOOKMARK = Pattern('focus_bookmark.png')
    FOCUS_BOOKMARK_SMALL = Pattern('focus_bookmark_small.png')
    """Local Mozilla site."""
    MOZILLA_TEST_SITE = 'http://%s:%s/mozilla/' % (_ip_host, _port)
    MOZILLA_TEST_SITE_2 = 'http://%s:%s/mozilla/' % (_domain_host, _port)
    MOZILLA_LOGO = Pattern('mozilla_logo.png')
    MOZILLA_IMAGE = Pattern('mozilla_full.png')
    MOZILLA_BOOKMARK = Pattern('mozilla_bookmark.png')
    MOZILLA_BOOKMARK_SMALL = Pattern('mozilla_bookmark_small.png')
    """Local Pocket site."""
    POCKET_TEST_SITE = 'http://%s:%s/pocket/' % (_ip_host, _port)
    POCKET_TEST_SITE_2 = 'http://%s:%s/pocket/' % (_domain_host, _port)
    POCKET_LOGO = Pattern('pocket_logo.png')
    POCKET_IMAGE = Pattern('pocket_full.png')
    POCKET_BOOKMARK = Pattern('pocket_bookmark.png')
    POCKET_BOOKMARK_SMALL = Pattern('pocket_bookmark_small.png')
    """Soap Wiki Test Site"""
    SOAP_WIKI_TEST_SITE = 'http://%s:%s/soap_wiki_test_site/' % (_ip_host,
                                                                 _port)
    SOAP_WIKI_1_OF_2_MATCHES = Pattern('1_of_2_matches.png')
    SOAP_WIKI_2_OF_2_MATCHES = Pattern('2_of_2_matches.png')
    SOAP_WIKI_CLEANING_SEE_SELECTED_LABEL = Pattern(
        'cleaning_see_selected_label.png')
    SOAP_WIKI_OPERATING_ALL = Pattern('operating_all.png')
    SOAP_WIKI_OPERATING_ALL_HIGHLIGHTED = Pattern(
        'operating_all_highlighted.png')
    SOAP_WIKI_OPERATING_DISPARATE = Pattern('operating_disparate.png')
    SOAP_WIKI_OPERATING_DISPARATE_HIGHLIGHTED = Pattern(
        'operating_disparate_highlighted.png')
    SOAP_WIKI_SEE_LABEL = Pattern('see_label.png')
    SOAP_WIKI_SEE_LABEL_UNHIGHLITED = Pattern('see_label_unhighlited.png')
    SOAP_WIKI_SOAP_ENVELOPE_LABEL_SELECTED = Pattern(
        'soap_envelope_label_selected.png')
    SOAP_WIKI_SOAP_LABEL = Pattern('soap_label.png')
    SOAP_WIKI_SOAP_LINK_HIGHLIGHTED = Pattern('soap_link_highlighted.png')
    SOAP_WIKI_SOAP_XML_LABEL = Pattern('soap_xml_label.png')
    SOAP_WIKI_TEST_LABEL_PATTERN = Pattern('test_label_pattern.png')
Beispiel #4
0
def check_keyboard_state():
    """Check Keyboard state.

    Iris cannot run in case Key.CAPS_LOCK, Key.NUM_LOCK or Key.SCROLL_LOCK are pressed.
    """
    if parse_args().no_check:
        return True

    key_on = False
    keyboard_keys = [Key.CAPS_LOCK, Key.NUM_LOCK, Key.SCROLL_LOCK]
    for key in keyboard_keys:
        if Key.is_lock_on(key):
            logger.error(
                'Cannot run Iris because %s is on. Please turn it off to continue.'
                % str(key).upper())
            key_on = True
    return not key_on
Beispiel #5
0
def _load_all_patterns():
    if parse_args().resize:
        _convert_hi_res_images()
    result_list = []
    for root, dirs, files in os.walk(IrisCore.get_module_dir()):
        for file_name in files:
            if file_name.endswith('.png'):
                if IrisCore.get_images_path(
                ) in root or 'common' in root or 'local_web' in root:
                    pattern_name, pattern_scale = _parse_name(file_name)
                    pattern_path = os.path.join(root, file_name)
                    pattern = {
                        'name': pattern_name,
                        'path': pattern_path,
                        'scale': pattern_scale
                    }
                    result_list.append(pattern)
    return result_list
Beispiel #6
0
class LocalWeb(object):
    """
    Constants that represent URLs and images for local content.
    """

    _ip_host = '127.0.0.1'
    _domain_host = 'localhost.allizom.org'
    _port = parse_args().port

    # Simple blank HTML page.
    BLANK_PAGE = 'http://%s:%s/blank.htm' % (_ip_host, _port)
    BLANK_PAGE_2 = 'http://%s:%s/blank.htm' % (_domain_host, _port)

    # Local Firefox site.
    FIREFOX_TEST_SITE = 'http://%s:%s/firefox/' % (_ip_host, _port)
    FIREFOX_TEST_SITE_2 = 'http://%s:%s/firefox/' % (_domain_host, _port)
    FIREFOX_LOGO = Pattern('firefox_logo.png')
    FIREFOX_IMAGE = Pattern('firefox_full.png')
    FIREFOX_BOOKMARK = Pattern('firefox_bookmark.png')
    FIREFOX_BOOKMARK_SMALL = Pattern('firefox_bookmark_small.png')

    # Local Firefox Focus site.
    FOCUS_TEST_SITE = 'http://%s:%s/focus/' % (_ip_host, _port)
    FOCUS_TEST_SITE_2 = 'http://%s:%s/focus/' % (_domain_host, _port)
    FOCUS_LOGO = Pattern('focus_logo.png')
    FOCUS_IMAGE = Pattern('focus_full.png')
    FOCUS_BOOKMARK = Pattern('focus_bookmark.png')
    FOCUS_BOOKMARK_SMALL = Pattern('focus_bookmark_small.png')

    # Local Mozilla site.
    MOZILLA_TEST_SITE = 'http://%s:%s/mozilla/' % (_ip_host, _port)
    MOZILLA_TEST_SITE_2 = 'http://%s:%s/mozilla/' % (_domain_host, _port)
    MOZILLA_LOGO = Pattern('mozilla_logo.png')
    MOZILLA_IMAGE = Pattern('mozilla_full.png')
    MOZILLA_BOOKMARK = Pattern('mozilla_bookmark.png')
    MOZILLA_BOOKMARK_SMALL = Pattern('mozilla_bookmark_small.png')

    # Local Pocket site.
    POCKET_TEST_SITE = 'http://%s:%s/pocket/' % (_ip_host, _port)
    POCKET_TEST_SITE_2 = 'http://%s:%s/pocket/' % (_domain_host, _port)
    POCKET_LOGO = Pattern('pocket_logo.png')
    POCKET_IMAGE = Pattern('pocket_full.png')
    POCKET_BOOKMARK = Pattern('pocket_bookmark.png')
    POCKET_BOOKMARK_SMALL = Pattern('pocket_bookmark_small.png')
Beispiel #7
0
class Platform(object):
    """Class that holds all the supported operating systems (HIGH_DEF = High definition displays)."""
    WINDOWS = 'win'
    LINUX = 'linux'
    MAC = 'osx'
    OS_NAME = mozinfo.os
    OS_VERSION = mozinfo.os_version
    OS_BITS = mozinfo.bits
    PROCESSOR = mozinfo.processor

    ALL = [LINUX, MAC, WINDOWS]

    primary_monitor = {
        "top": 0,
        "left": 0,
        "width": 1920,
        "height": 1080
    } if parse_args().headless_run else mss.mss().monitors[1]
    _screenshot = mss.mss().grab(primary_monitor)
    SCREENSHOT_SIZE = (_screenshot.width, _screenshot.height)
    HIGH_DEF = SCREENSHOT_SIZE != pyautogui.size()
    SCREEN_WIDTH, SCREEN_HEIGHT = pyautogui.size()
    LOW_RES = (SCREEN_WIDTH < 1280 or SCREEN_HEIGHT < 800)
Beispiel #8
0
def _get_image_path(caller, image):
    """Enforce proper location for all Pattern creation.

    :param caller: Path of calling Python module.
    :param image: String filename of image.
    :return: Full path to image on disk.
    """

    module = os.path.split(caller)[1]
    module_directory = os.path.split(caller)[0]
    parent_directory = os.path.basename(module_directory)
    file_name = image.split('.')[0]
    names = [
        image,
        '*****@*****.**' % file_name,
        '*****@*****.**' % file_name,
        '*****@*****.**' % file_name
    ]

    # We will look at all possible paths relative to the calling file, with this priority:
    #
    # - current platform locale folder
    # - common locale folder
    # - current platform root
    # - common root
    #
    # Each directory is scanned for four possible file names, depending on resolution.
    # If the above fails, we will look up the file name in the list of project-wide images,
    # and return whatever we find, with a warning message.
    # If we find nothing, we will raise an exception.
    if Settings.get_os_version() == 'win7':
        os_version = 'win7'
    else:
        os_version = Settings.get_os()
    paths = []
    current_locale = parse_args().locale

    platform_directory = os.path.join(module_directory, 'images', os_version)
    platform_locale_directory = os.path.join(platform_directory,
                                             current_locale)
    for name in names:
        paths.append(os.path.join(platform_locale_directory, name))

    common_directory = os.path.join(module_directory, 'images', 'common')
    common_locale_directory = os.path.join(common_directory, current_locale)
    for name in names:
        paths.append(os.path.join(common_locale_directory, name))

    for name in names:
        paths.append(os.path.join(platform_directory, name))

    for name in names:
        paths.append(os.path.join(common_directory, name))

    found = False
    image_path = None
    for path in paths:
        if os.path.exists(path):
            found = True
            image_path = path
            break

    if found:
        logger.debug('Module %s requests image %s' % (module, image))
        logger.debug('Found %s' % image_path)
        return image_path
    else:
        # If not found in correct location, fall back to global image search for now.
        result_list = filter(lambda x: x['name'] == image,
                             _load_all_patterns())
        if len(result_list) > 0:
            res = result_list[0]
            logger.warning(
                'Failed to find image %s in default locations for module %s.' %
                (image, module))
            logger.warning('Using this one instead: %s' % res['path'])
            logger.warning(
                'Please move image to correct location relative to caller.')
            location_1 = os.path.join(parent_directory, 'images', 'common')
            location_2 = os.path.join(parent_directory,
                                      IrisCore.get_images_path())
            logger.warning('Suggested locations: %s, %s' %
                           (location_1, location_2))
            return res['path']
        else:
            logger.error('Pattern creation for %s failed for caller %s.' %
                         (image, caller))
            logger.error(
                'Image not found. Either it is in the wrong platform folder, or it does not exist.'
            )
            logger.debug('Paths searched:')
            logger.debug('\n'.join(paths))
            raise FindError('Pattern not found.')
Beispiel #9
0
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

from platform import Platform
from util.color import Color
from util.core_helper import get_os, get_os_version
from util.parse_args import parse_args

DEFAULT_MIN_SIMILARITY = 0.8
DEFAULT_SLOW_MOTION_DELAY = 2
DEFAULT_MOVE_MOUSE_DELAY = parse_args().mouse
DEFAULT_OBSERVE_MIN_CHANGED_PIXELS = 50
DEFAULT_TYPE_DELAY = 0
DEFAULT_CLICK_DELAY = 0
DEFAULT_WAIT_SCAN_RATE = 3
DEFAULT_OBSERVE_SCAN_RATE = 3
DEFAULT_AUTO_WAIT_TIMEOUT = 3
DEFAULT_DELAY_BEFORE_MOUSE_DOWN = 0.3
DEFAULT_DELAY_BEFORE_DRAG = 0.3
DEFAULT_DELAY_BEFORE_DROP = 0.3
DEFAULT_HIGHLIGHT_DURATION = 2
DEFAULT_HIGHLIGHT_COLOR = Color.RED
DEFAULT_HIGHLIGHT_THICKNESS = 2
DEFAULT_FX_DELAY = 0.5
DEFAULT_UI_DELAY = 1
DEFAULT_UI_DELAY_LONG = 2.5
DEFAULT_SYSTEM_DELAY = 5
DEFAULT_FIREFOX_TIMEOUT = 10

BETA = 'beta'