def open_and_check_mysky():
    """Open the MySky app and make some checks"""
    menu = open_and_basic_check_mysky()
    menu_items = menu.menu_items

    item = [
        x for x in menu_items if x.text == sky_plus_strings.MANAGE_YOUR_ACCOUNT
    ][0]
    match_result = match(mysky_constants.MENU_MANAGE_YOUR_ACCOUNT,
                         frame=menu._frame,
                         region=item.region)
    debug('match_result: {0}{1}'.format(match_result.match,
                                        match_result.first_pass_result))
    if sky_plus_utils.IMAGE_DEBUG_MODE:
        cv2.imwrite('matching_menu_{0}.jpg'.format(time.time()),
                    sky_plus_utils.crop_image(menu._frame, item.region))
    assert match_result.match, '[MySky] Could not find {0} menu'.format(
        mysky_constants.MENU_MANAGE_YOUR_ACCOUNT)
    item = [x for x in menu_items
            if x.text == sky_plus_strings.FIX_A_PROBLEM][0]
    match_result = match(mysky_constants.MENU_FIX_A_PROBLEM,
                         frame=menu._frame,
                         region=item.region)
    debug('match_result: {0}{1}'.format(match_result.match,
                                        match_result.first_pass_result))
    assert match_result.match, '[MySky] Could not find {0} menu'.format(
        sky_plus_strings.FIX_A_PROBLEM)

    message = menu.message
    debug('Item message: {0}'.format(message))
    assert message == sky_plus_strings.EXPLORE_MORE, \
        '[MySky] Selected item should be [{0}], but is [{1}]'.format(sky_plus_strings.EXPLORE_MORE, message)

    return menu
Ejemplo n.º 2
0
def test_tuning_channels_20plus_times():
    for _ in " " * 3: stbt.press('KEY_EXIT')
    if not stbt.wait_until(lambda: stbt.match("images/env/do_you_want_to_upgrade.png")) and not stbt.wait_until(
            lambda: stbt.match("images/env/channel_unavailable.png")):
        assert stbt.wait_until(lambda: stbt.wait_for_motion()), \
            "Live TV not reached at test start"
    channels = [21, 24, 27, 29]
    t = 0
    for _ in range(5):
        for ch in channels:
            t += 1
            for x in list(str(ch)):
                stbt.press("KEY_" + x)
                sleep(0.6)
            sleep(4)
            if stbt.match('images/dvr/continue_to_miniguide.png') and t == 1:
                for _ in " " * 2: stbt.press('KEY_RIGHT')
                for _ in " " * 2: stbt.press('KEY_ENTER')
                stbt.press('KEY_RIGHT')
                stbt.press('KEY_ENTER')
            print (t)
            if not stbt.wait_until(lambda: stbt.match("images/env/do_you_want_to_upgrade.png")) and not stbt.wait_until(
                    lambda: stbt.match("images/env/channel_unavailable.png")):
                assert stbt.wait_until(lambda: stbt.wait_for_motion()), \
                    "New channel " + str(ch) + " not reached on channel change number " + t
Ejemplo n.º 3
0
def test_DVR_on_reboot():
    count = 0
    while True:
        if stbt.is_screen_black(): break
        count += 1
        sleep(3)
        assert count < 10, \
        "STB did not reboot within 30 seconds with osdiag RebootNow"
    count = 0
    while True:
        stbt.press('KEY_POWER')
        sleep(5)
        if stbt.match('images/menu/stick_around.png') or stbt.match(
                'images/menu/reboot_logo.png'):
            break
        sleep(5)
        count += 1
        assert count < 18, \
        "Stick Around screen is not shown after reboot within 3 minutes"
    stbt.wait_for_motion(timeout_secs=300)
    stbt.press('KEY_RECORD')
    assert stbt.wait_until(lambda: stbt.match("images/dvr/edit_ep_rec.png") or stbt.match("images/dvr/ch_bar_rec.png")), \
    "RECORD press on live TV did not set recording, or prompt for edit recording"
    mydvr_launch()
    count = 0
    while True:
        stbt.press('KEY_ENTER')
        if stbt.match('images/cta/watch.png'): break
        count += 1
        assert count < 16, \
        "Could not find recording to play in DVR page"
    stbt.press('KEY_ENTER')
    assert stbt.wait_for_motion(timeout_secs=20)
Ejemplo n.º 4
0
 def check_image(self,
                 image_to_find,
                 region=None,
                 timeout_secs=configuration.image_check_time_out_secs):
     image_name = image_to_find.split("/")[-1:][0]
     if region is not None:
         img_region = stbt.Region(region["x"],
                                  region["y"],
                                  width=region["width"],
                                  height=region["height"])
         if stbt.wait_until(
                 lambda: stbt.match(image_to_find, region=img_region),
                 timeout_secs=timeout_secs):
             self.LogResults.info(
                 "Image check passed using: {}".format(image_name))
             return True
         else:
             self.LogResults.warning(
                 "Image check failed using: {}".format(image_name))
             return False
     else:
         if stbt.wait_until(lambda: stbt.match(image_to_find),
                            timeout_secs=timeout_secs):
             self.LogResults.info(
                 "Image check passed using: {}".format(image_name))
             return True
         else:
             self.LogResults.warning(
                 "Image check failed using: {}".format(image_name))
             return False
Ejemplo n.º 5
0
def test_DVR_playback_50plus_times_no_TTS():
    # Turn off TTS
    for _ in " " * 3: stbt.press('KEY_EXIT')
    count = 0
    # GNarration_setting("Off")
    for _ in range(51):
        count = 0
        for _ in " " * 3: stbt.press('KEY_EXIT')
        sleep(3)
        stbt.press('KEY_MYDVR')
        sleep(3)
        if stbt.match('images/dvr/cancel_a_recording.png'):
            for _ in " " * 2: stbt.press('KEY_RIGHT')
            for _ in " " * 2: stbt.press('KEY_ENTER')
            stbt.press('KEY_RIGHT')
            stbt.press('KEY_ENTER')
        assert stbt.wait_until(lambda: stbt.match("images/dvr/my_dvr.png")), \
            "MyDVR not launched"
        while True:
            stbt.press('KEY_ENTER')
            sleep(1)
            if stbt.match('images/cta/watch.png') or stbt.match('images/cta/resume.png'): break
            count += 1
            assert count < 20, \
                "Could not find recording to play in DVR page"
        sleep(2)
        stbt.press('KEY_ENTER')
        sleep(3)
        assert stbt.wait_for_motion(timeout_secs=20)
Ejemplo n.º 6
0
def test_match_region2(x, y, offset_x, offset_y, width, height,
                       frame_width, frame_height):
    if x >= 0:
        x = x + offset_x
    else:
        x = frame_width - width - offset_x
    if y >= 0:
        y = y + offset_y
    else:
        y = frame_height - height - offset_y
    region = stbt.Region(x, y, width=width, height=height)
    image = numpy.ones((region.height, region.width, 3), numpy.uint8) * 255
    image[5:-5, 5:-5] = (255, 0, 0)
    frame = black(frame_width, frame_height)
    frame[region.to_slice()] = image[
        0 if region.y >= 0 else -region.y :
            region.height if region.bottom <= frame_height
            else frame_height - region.y,
        0 if region.x >= 0 else -region.x :
            region.width if region.right <= frame_width
            else frame_width - region.x] * .85
    # N.B. .85 is the lowest at which all the tests still passed when I
    # disabled the pyramid optimisation.

    should_match = _image_region(frame).contains(region)

    m = stbt.match(image, frame)
    if should_match != m.match or os.environ.get("STBT_DEBUG"):
        with scoped_debug_level(2):
            stbt.match(image, frame)
    assert should_match == m.match
    if should_match:
        assert m.region == region
Ejemplo n.º 7
0
def match_image(image,element):
    try:
        if lambda: match(image,match_parameters=stbt.MatchParameters(match_method="ccoeff-normed", confirm_method="none")):           
           return  match(image,match_parameters=stbt.MatchParameters(match_method="ccoeff-normed", confirm_method="none"))
        else:
          assert False, elementName+" is not visible on the Screen"  
    except Exception,e:
        failMessage(e.args)
        raise e 
Ejemplo n.º 8
0
 def is_visible(self):
     if (stbt.match("images/mainhub/home_breadcrumb_NL.png",
                    frame=self._frame).match
             & stbt.match(
                 "images/mainhub/televisie_focusinshowcaseline_NL.png",
                 frame=self._frame).match):
         return True
     else:
         return False
Ejemplo n.º 9
0
 def check(self, picture, picture_two=None):
     i = 0
     while i < 5:
         if picture_two is None:
             if stbt.match(picture, None, stbt.MatchParameters(None, None, None, 0.7)):
                 return True
         else:
             if (stbt.match(picture, None, stbt.MatchParameters(None, None, None, 0.7)) and stbt.match(picture_two, None, stbt.MatchParameters(None, None, None, 0.7))):
                 return True
         i += 1
     return False
Ejemplo n.º 10
0
def test_pyramid_roi_too_small(frame, image, match_method, match_threshold):
    # This is a regression test for an error that was seen with a particular
    # frame from a single test-run, with SQDIFF_NORMED:
    # cv2.error: (-215) _img.size().height <= _templ.size().height &&
    # _img.size().width <= _templ.size().width in function matchTemplate
    with scoped_debug_level(2):
        stbt.match(image,
                   frame=stbt.load_image(frame),
                   match_parameters=stbt.MatchParameters(
                       match_method=match_method,
                       match_threshold=match_threshold))
Ejemplo n.º 11
0
def tune_to_agerating_event(scope={}):
    coordinatesTen = getCoordinatesOfIcon("ageRating_icon_Ten")
    coordinatesTwelve = getCoordinatesOfIcon("ageRating_icon_Twelve")
    coordinatesSixteen = getCoordinatesOfIcon("ageRating_icon_Sixten")
    coordinatesEighteen = getCoordinatesOfIcon("ageRating_icon_Eighteen")
    try:
        for num in range(200):
            stbt.press("KEY_DOWN")
            sleep(2)
            tenAR = bool(
                stbt.match(coordinatesTen['image'],
                           region=stbt.Region(
                               x=coordinatesTen['x'],
                               y=coordinatesTen['y'],
                               right=coordinatesTen['right'],
                               bottom=coordinatesTen['bottom'])))
            twelveAR = bool(
                stbt.match(coordinatesTwelve['image'],
                           region=stbt.Region(
                               x=coordinatesTwelve['x'],
                               y=coordinatesTwelve['y'],
                               right=coordinatesTwelve['right'],
                               bottom=coordinatesTwelve['bottom'])))
            sixteenAR = bool(
                stbt.match(coordinatesSixteen['image'],
                           region=stbt.Region(
                               x=coordinatesSixteen['x'],
                               y=coordinatesSixteen['y'],
                               right=coordinatesSixteen['right'],
                               bottom=coordinatesSixteen['bottom'])))
            eighteenAR = bool(
                stbt.match(coordinatesEighteen['image'],
                           region=stbt.Region(
                               x=coordinatesEighteen['x'],
                               y=coordinatesEighteen['y'],
                               right=coordinatesEighteen['right'],
                               bottom=coordinatesEighteen['bottom'])))
            if (tenAR or twelveAR or sixteenAR or eighteenAR):
                stbt.press("KEY_OK")
                sleep(2)
                break
            else:
                print "Continue  through zap list"
        return {
            "status": True,
            "tenAR": tenAR,
            "twelveAR": twelveAR,
            "sixteenAR": sixteenAR,
            "eighteenAR": eighteenAR
        }
    except Exception, e:
        print "Couldnt find Channel with Age Rating"
        return {"status": False}
Ejemplo n.º 12
0
def test_that_cache_is_disabled_when_debug_match():
    # debug logging is a side effect that the cache cannot reproduce
    import stbt
    import _stbt.logging
    with scoped_curdir() as srcdir, cache('cache.lmdb'):
        stbt.match(srcdir + '/tests/red-black.png',
                   frame=numpy.zeros((720, 1280, 3), dtype=numpy.uint8))
        assert not os.path.exists('stbt-debug')

        with _stbt.logging.scoped_debug_level(2):
            stbt.match(srcdir + '/tests/red-black.png',
                       frame=numpy.zeros((720, 1280, 3), dtype=numpy.uint8))
        assert os.path.exists('stbt-debug')
Ejemplo n.º 13
0
def test_that_cache_is_disabled_when_debug_match():
    # debug logging is a side effect that the cache cannot reproduce
    import stbt
    import _stbt.logging
    with scoped_curdir() as srcdir, cache('cache.lmdb'):
        stbt.match(srcdir + '/tests/red-black.png',
                   frame=numpy.zeros((720, 1280, 3), dtype=numpy.uint8))
        assert not os.path.exists('stbt-debug')

        with _stbt.logging.scoped_debug_level(2):
            stbt.match(srcdir + '/tests/red-black.png',
                       frame=numpy.zeros((720, 1280, 3), dtype=numpy.uint8))
        assert os.path.exists('stbt-debug')
Ejemplo n.º 14
0
    def is_visible(self):
        # pylint: disable=stbt-frame-object-missing-frame
        logo_visible = stbt.match(
            interactive_constants.INTERACTIVE_SKY_LOGO_SD)
        debug('[MY ACCOUNT] Logo visible: {0}'.format(logo_visible))
        if logo_visible:
            title = find_text(self._frame, MA_TITLE_REGION)
            debug('[MY ACCOUNT] Title found: {0}'.format(title))
            title_visible = (title == sky_plus_strings.MY_ACCOUNT)

            background_visible = stbt.match(MA_BACKGROUND,
                                            region=MA_BACKGROUND_REGION)

            return title_visible and background_visible
        return False
Ejemplo n.º 15
0
def test_png_with_16_bits_per_channel():
    assert cv2.imread(_find_file("uint16.png"), cv2.IMREAD_UNCHANGED).dtype == \
        numpy.uint16  # Sanity check (that this test is valid)

    assert stbt.match(
        "tests/uint16.png",
        frame=cv2.imread(_find_file("uint8.png")))
Ejemplo n.º 16
0
def test_png_with_16_bits_per_channel():
    assert cv2.imread(_find_file("uint16.png"), cv2.IMREAD_UNCHANGED).dtype == \
        numpy.uint16  # Sanity check (that this test is valid)

    assert stbt.match(
        "tests/uint16.png",
        frame=cv2.imread(_find_file("uint8.png")))
Ejemplo n.º 17
0
def main():
    os.chdir(os.path.dirname(__file__))

    # Disable cpu frequency scaling
    subprocess.check_call(r"""
        for cpu in /sys/devices/system/cpu/cpufreq/policy*; do
            echo $cpu
            cat $cpu/scaling_available_governors
            echo performance | sudo tee $cpu/scaling_governor
            freq=$(cat $cpu/cpuinfo_max_freq)
            echo $freq | sudo tee $cpu/scaling_min_freq
        done >&2
        """,
                          shell=True)

    print "screenshot,reference,min,avg,max"

    for fname in glob.glob("images/performance/*-frame.png"):
        tname = fname.replace("-frame.png", "-reference.png")
        f = stbt.load_image(fname)
        t = stbt.load_image(tname)
        # pylint:disable=cell-var-from-loop
        times = timeit.repeat(lambda: stbt.match(t, f), number=1, repeat=100)
        print "%s,%s,%f,%f,%f" % (os.path.basename(fname),
                                  os.path.basename(tname), min(times),
                                  max(times), sum(times) / len(times))
Ejemplo n.º 18
0
def test_matching_greyscale_array_with_greyscale_frame(match_method):
    assert stbt.match(
        cv2.cvtColor(stbt.load_image("videotestsrc-redblue.png"),
                     cv2.COLOR_BGR2GRAY),
        frame=cv2.cvtColor(stbt.load_image("videotestsrc-full-frame.png"),
                           cv2.COLOR_BGR2GRAY),
        match_parameters=mp(match_method=match_method))
Ejemplo n.º 19
0
def test_matching_greyscale_array_with_greyscale_frame(match_method):
    assert stbt.match(
        cv2.cvtColor(stbt.load_image("videotestsrc-redblue.png"),
                     cv2.COLOR_BGR2GRAY),
        frame=cv2.cvtColor(stbt.load_image("videotestsrc-full-frame.png"),
                           cv2.COLOR_BGR2GRAY),
        match_parameters=mp(match_method=match_method))
Ejemplo n.º 20
0
def test_stbt():
    func_name = sys._getframe().f_code.co_name
    test = 'tests/' + os.path.basename(__file__) + '::' + func_name
    sleep(2)
    """Navigating to Roku Home Screen"""
    to_roku_home()
    sleep(2)
    if match("images/Mtv_app/MTV_Icon.png"):
        passMessageWith_Screenshots("Settings Screenshot Verified")
        sleep(2)
    press("KEY_RIGHT")
    sleep(2)
    press_until_match("KEY_DOWN", "images/Mtv_app/MTV_Icon.png")
    sleep(2)
    navigate_to_tile("images/Mtv_app/MTV_Icon.png")
    sleep(2)
    press("KEY_OK")
    sleep(2)
    press("KEY_OK")
    sleep(2)
    press_until_match("KEY_RIGHT", "images/Mtv_app/WinterBreak_Icon.png")
    sleep(2)
    text_1 = getText(270, 485, 730, 522)
    print text_1
    text_2 = getText(272, 526, 726, 526)
    print text_2
    text_3 = getText(290, 553, 331, 555)
    print text_3
    show_name = text_1 + text_2 + text_3
    sleep(2)
    print("Show_Name") + show_name
    sleep(2)
    press("KEY_OK")
Ejemplo n.º 21
0
def main():
    os.chdir(os.path.dirname(__file__))

    # Disable cpu frequency scaling
    subprocess.check_call(r"""
        for cpu in /sys/devices/system/cpu/cpufreq/policy*; do
            echo $cpu
            cat $cpu/scaling_available_governors
            echo performance | sudo tee $cpu/scaling_governor
            freq=$(cat $cpu/cpuinfo_max_freq)
            echo $freq | sudo tee $cpu/scaling_min_freq
        done >&2
        """, shell=True)

    print "screenshot,reference,min,avg,max"

    for fname in glob.glob("images/performance/*-frame.png"):
        tname = fname.replace("-frame.png", "-reference.png")
        f = stbt.load_image(fname)
        t = stbt.load_image(tname)
        # pylint:disable=cell-var-from-loop
        times = timeit.repeat(lambda: stbt.match(t, f), number=1, repeat=100)
        print "%s,%s,%f,%f,%f" % (os.path.basename(fname),
                                  os.path.basename(tname),
                                  min(times),
                                  max(times),
                                  sum(times) / len(times))
Ejemplo n.º 22
0
def miniguide_launch():
    stbt.press('KEY_EXIT')
    stbt.press('KEY_ENTER')
    time.sleep(1.2)
    stbt.press('KEY_ENTER')
    assert stbt.wait_until(lambda: stbt.match("images/miniguide/miniguide.png")), \
    "Miniguide not launched"
Ejemplo n.º 23
0
def video_store_launch():
    menu_launch()
    stbt.press('KEY_CHANNELUP')
    for _ in " " * 5:
        stbt.press('KEY_DOWN')
    stbt.press('KEY_ENTER')
    assert stbt.wait_until(lambda: stbt.match("images/vod/video_store_logo.png")), \
    "Video Store not launched"
Ejemplo n.º 24
0
def movies_launch():
    menu_launch()
    stbt.press('KEY_CHANNELUP')
    for _ in " " * 4:
        stbt.press('KEY_DOWN')
    stbt.press('KEY_ENTER')
    assert stbt.wait_until(lambda: stbt.match("images/vod/movies_logo.png")), \
    "Movies not launched"
Ejemplo n.º 25
0
def tv_shows_launch():
    menu_launch()
    stbt.press('KEY_CHANNELUP')
    for _ in " " * 3:
        stbt.press('KEY_DOWN')
    stbt.press('KEY_ENTER')
    assert stbt.wait_until(lambda: stbt.match("images/vod/tv_shows_logo.png")), \
    "TV Shows not launched"
Ejemplo n.º 26
0
def my_library_launch():
    menu_launch()
    stbt.press('KEY_CHANNELUP')
    for _ in " " * 2:
        stbt.press('KEY_DOWN')
    stbt.press('KEY_ENTER')
    assert stbt.wait_until(lambda: stbt.match("images/vod/my_library_header.png")), \
    "My Library not launched"
Ejemplo n.º 27
0
def test_20_trickplay_buttons_on_TSB():
    for _ in " " * 3: stbt.press('KEY_EXIT')
    if stbt.wait_until(lambda: stbt.match("images/dvr/pause.png")):
        stbt.press('KEY_PLAYPAUSE')
    count = 0
    while True:
        if not stbt.wait_until(lambda: stbt.wait_for_motion(timeout_secs=10)):
            stbt.press('KEY_CHANNELUP')
        else:
            break
        count += 1
        assert count < 4, \
            "No motion found on Live after 4 channel changes"
    sleep(2)
    stbt.press('KEY_PLAYPAUSE')
    assert stbt.wait_until(lambda: stbt.match("images/dvr/pause.png")), \
        "Unable to pause Live"
    sleep(50)
    for _ in range(5):
        stbt.press('KEY_PLAYPAUSE')
        assert stbt.wait_until(lambda: stbt.match("images/dvr/play.png")), \
            "Unable to play Live after pause"
        stbt.press('KEY_LEFT')
        assert stbt.wait_until(lambda: stbt.match("images/dvr/rewind.png")), \
            "Unable to rewind Live"
        for _ in " " * 2: stbt.press('KEY_RIGHT')
        assert stbt.wait_until(lambda: stbt.match("images/dvr/fastforward.png")), \
            "Unable to fastforward Live"
        stbt.press('KEY_PLAYPAUSE')
        assert stbt.wait_until(lambda: stbt.match("images/dvr/play.png")), \
            "Unable to play Live"
        stbt.press('KEY_PLAYPAUSE')
        assert stbt.wait_until(lambda: stbt.match("images/dvr/pause.png")), \
            "Unable to pause Live"
Ejemplo n.º 28
0
def test_20_trickplay_buttons_on_TSB_iguide():
    if stbt.wait_until(lambda: stbt.match("images/dvr/i_pause.png")):
        stbt.press('KEY_PLAY')
    count = 0
    while True:
        if not stbt.wait_until(lambda: stbt.wait_for_motion(timeout_secs=10)):
            stbt.press('KEY_CHANNELUP')
        else:
            break
        count += 1
        assert count < 4, \
            "No motion found on Live after 4 channel changes"
    sleep(2)
    stbt.press('KEY_PAUSE')
    assert stbt.wait_until(lambda: stbt.match("images/dvr/i_pause.png")), \
        "Unable to pause Live"
    sleep(80)
    for _ in range(10):
        stbt.press('KEY_PLAY')
        assert stbt.wait_until(lambda: stbt.match("images/dvr/i_play.png")), \
            "Unable to play Live after pause"
        stbt.press('KEY_REWIND')
        assert stbt.wait_until(lambda: stbt.match("images/dvr/i_rewind.png")), \
            "Unable to rewind Live"
        for _ in " " * 2: stbt.press('KEY_FASTFORWARD')
        assert stbt.wait_until(lambda: stbt.match("images/dvr/i_fastforward.png")), \
            "Unable to fastforward Live"
        stbt.press('KEY_PLAY')
        assert stbt.wait_until(lambda: stbt.match("images/dvr/i_play.png")), \
            "Unable to play Live"
        stbt.press('KEY_PAUSE')
        assert stbt.wait_until(lambda: stbt.match("images/dvr/i_pause.png")), \
            "Unable to pause Live"
Ejemplo n.º 29
0
    def is_visible(self):
        # pylint: disable=stbt-frame-object-missing-frame
        logo_visible = stbt.match(
            interactive_constants.INTERACTIVE_SKY_LOGO_SD)
        debug('[MY MESSAGES] Logo visible: {0}'.format(logo_visible))
        if logo_visible:
            title = find_text(self._frame, MM_TITLE_REGION)
            debug('[MY MESSAGES] Title found: {0}'.format(title))
            title_visible = (title == sky_plus_strings.MY_MESSAGES)

            subtitle = find_text(self._frame, MM_SUBTITLE_REGION)
            debug('[MY MESSAGES] Subtitle found: {0}'.format(subtitle))
            subtitle_visible = (subtitle == sky_plus_strings.MM_SUBTITLE)

            pin_visible = stbt.match(MM_PIN_ENTRY)

            return title_visible and subtitle_visible and pin_visible
        return False
 def is_visible(self):
     # pylint: disable=stbt-frame-object-missing-frame
     logo_visible = stbt.match(mysky_constants.SKY_TOP_LOGO,
                               region=MY_SKY_REGION)
     if logo_visible:
         light_is_green = ui_ready(self._frame)
         text = sky_plus_utils.find_text(self._frame, MYA_TITLE_REGION)
         return light_is_green and text == sky_plus_strings.MANAGE_YOUR_ACCOUNT
     return False
Ejemplo n.º 31
0
def init():
    if stbt.match('images/env/user_settings.png'):
        for _ in " " * 2:
            stbt.press('KEY_POWER')
    else:
        stbt.press('KEY_EXIT')
        stbt.press('KEY_EXIT')
        guide_launch()
        stbt.press('KEY_EXIT')
Ejemplo n.º 32
0
def test_mydvr_launch():
    f = open("testFile.txt", "w+")
    stbt.press('KEY_EXIT')
    f.write("Step 1: press exit: Passed\n")
    stbt.press('KEY_MYDVR')
    f.write("Step 2: press MyDVR: Passed\n")
    f.close()
    assert stbt.wait_until(lambda: stbt.match("images/dvr/my_dvr.png")), \
    "MyDVR not launched"
Ejemplo n.º 33
0
def check_video_is_paused(scope={}):
    sleep(10)
    assert stbt.wait_until(
        lambda: stbt.match("images/recordingsPage/pauseImageDisplayed.png"))
    try:
        stbt.wait_for_motion()
        print "The video has not been paused"
        assert False
    except stbt.MotionTimeout:
        print "The video has been paused"
Ejemplo n.º 34
0
    def is_visible(self):
        # pylint: disable=stbt-frame-object-missing-frame
        logo_visible = stbt.match(INTERACTIVE_SKY_LOGO)
        debug('[INTERACTIVE] Logo visible: {0}'.format(logo_visible))
        if logo_visible:
            title = find_text(self._frame, TITLE_REGION)
            debug('[INTERACTIVE] Text found: {0}'.format(title))
            title_visible = (title == sky_plus_strings.INTERACTIVE)

            return title_visible
        return False
Ejemplo n.º 35
0
def test_that_get_frame_resizes_to_match_coordinate_system(
        orientation, coordinate_system):

    source = cv2.imread(_find_file(
        "images/android/resize/source-1080p-%s.png" % orientation))
    out = _resize(source, coordinate_system)
    expected_filename = \
        "images/android/resize/expected-{system}-{orientation}.png".format(
            system=coordinate_system.name.lower().replace("_", "-"),
            orientation=orientation)
    expected = cv2.imread(_find_file(expected_filename))
    assert match(expected, out)
Ejemplo n.º 36
0
    def _info(self):
        """
        This is a private property because its name starts with ``_``. It will
        not appear in ``__repr__`` nor count toward equality comparisons, but
        the result from it will still be cached. This is useful for sharing
        intermediate values between your public properties, particularly if
        they are expensive to calculate. In this example we use ``_info`` from
        ``is_visible`` and ``message``.

        You wouldn't want this to be a public property because it returns a
        `MatchResult` which includes the entire frame passed into `match`.
        """
        return stbt.match('tests/info.png', frame=self._frame)
Ejemplo n.º 37
0
def test_that_match_fast_path_is_equivalent():
    from _stbt.match import _load_image
    black_reference = black(10, 10)
    almost_black_reference = black(10, 10, value=1)
    black_frame = black(1280, 720)
    almost_black_frame = black(1280, 720, value=2)

    images = [
        ("videotestsrc-redblue.png", "videotestsrc-full-frame.png"),
        ("action-panel.png", "action-panel.png"),
        ("videotestsrc-full-frame.png", "videotestsrc-full-frame.png"),
        ("videotestsrc-redblue-flipped.png", "videotestsrc-full-frame.png"),
        ("button.png", "black-full-frame.png"),
        ("completely-transparent.png", "buttons-on-blue-background.png"),
        ("action-panel-template.png", "action-panel.png"),
        ("button.png", "buttons.png"),
        (black_reference, black_frame),
        (almost_black_reference, black_frame),
        (almost_black_reference, almost_black_frame),
        ("repeating-pattern.png", "repeating-pattern-full-frame.png"),
        ("button-transparent.png", "buttons.png"),
    ]
    for reference, frame in images:
        if isinstance(frame, (str, unicode)):
            frame = stbt.load_image(frame, cv2.IMREAD_COLOR)
        reference = _load_image(reference)
        orig_m = stbt.match(reference, frame=frame)
        fast_m = stbt.match(reference, frame=frame, region=orig_m.region)
        assert orig_m.time == fast_m.time
        assert orig_m.match == fast_m.match
        assert orig_m.region == fast_m.region
        assert bool(orig_m) == bool(fast_m)
        assert orig_m.first_pass_result == pytest.approx(
            fast_m.first_pass_result, abs=0.0001 if orig_m else 0.05)
        assert (orig_m.frame == fast_m.frame).all()
        if isinstance(orig_m.image, numpy.ndarray):
            assert (orig_m.image == fast_m.image).all()
        else:
            assert orig_m.image == fast_m.image
Ejemplo n.º 38
0
def test_to_native_coordinates(
        orientation, device_resolution, expected_coordinates,
        coordinate_system):

    description = "{source}-{orientation}".format(
        source=coordinate_system.name.lower().replace("_", "-"),
        orientation=orientation)
    screenshot = cv2.imread(_find_file(
        "images/android/coordinates/%s-screenshot.png" % description))
    icon = "images/android/coordinates/%s-reference.png" % description

    m = match(icon, screenshot)
    screenshot_x, screenshot_y = _centre_point(m.region)
    native_x, native_y = _to_native_coordinates(
        screenshot_x, screenshot_y, coordinate_system,
        _Dimensions(*device_resolution))
    print(native_x, native_y)
    assert isclose(native_x, expected_coordinates[0], atol=1)
    assert isclose(native_y, expected_coordinates[1], atol=1)
Ejemplo n.º 39
0
def test_that_sqdiff_matches_black_images():
    black_reference = black(10, 10)
    almost_black_reference = black(10, 10, value=1)
    black_frame = black(1280, 720)
    almost_black_frame = black(1280, 720, value=2)

    sqdiff = mp(match_method=stbt.MatchMethod.SQDIFF)
    sqdiff_normed = mp(match_method=stbt.MatchMethod.SQDIFF_NORMED)

    assert not stbt.match(black_reference, black_frame, sqdiff_normed)
    assert not stbt.match(almost_black_reference, black_frame, sqdiff_normed)
    assert not stbt.match(almost_black_reference, almost_black_frame,
                          sqdiff_normed)
    assert stbt.match(black_reference, black_frame, sqdiff)
    assert stbt.match(almost_black_reference, black_frame, sqdiff)
    assert stbt.match(almost_black_reference, almost_black_frame, sqdiff)
Ejemplo n.º 40
0
 def match():
     return stbt.match('tests/red-black.png', frame=black)
Ejemplo n.º 41
0
 def match_any(basename):
     f = adb.get_frame()
     return (match("images/android/galaxy-ace-2/" + basename, f) or
             match("images/android/moto-x2/" + basename, f))
Ejemplo n.º 42
0
def test_match_error_message_for_too_small_frame_and_region():
    stbt.match("videotestsrc-redblue.png", frame=black(width=92, height=160))
    stbt.match("videotestsrc-redblue.png", frame=black(),
               region=stbt.Region(x=1188, y=560, width=92, height=160))

    with pytest.raises(ValueError) as excinfo:
        stbt.match("videotestsrc-redblue.png",
                   frame=black(width=91, height=160))
    assert (
        "Frame (160, 91, 3) must be larger than reference image (160, 92, 3)"
        in str(excinfo.value))

    with pytest.raises(ValueError) as excinfo:
        stbt.match("videotestsrc-redblue.png",
                   frame=black(width=92, height=159))
    assert (
        "Frame (159, 92, 3) must be larger than reference image (160, 92, 3)"
        in str(excinfo.value))

    with pytest.raises(ValueError) as excinfo:
        # Region seems large enough but actually it extends beyond the frame
        stbt.match("videotestsrc-redblue.png", frame=black(),
                   region=stbt.Region(x=1189, y=560, width=92, height=160))
    assert (
        "Region(x=1189, y=560, right=1280, bottom=720) must be larger than "
        "reference image (160, 92, 3)"
        in str(excinfo.value))

    with pytest.raises(ValueError) as excinfo:
        # Region seems large enough but actually it extends beyond the frame
        stbt.match("videotestsrc-redblue.png", frame=black(),
                   region=stbt.Region(x=1188, y=561, width=92, height=160))
    assert (
        "Region(x=1188, y=561, right=1280, bottom=720) must be larger than "
        "reference image (160, 92, 3)"
        in str(excinfo.value))
Ejemplo n.º 43
0
def test_that_match_rejects_greyscale_array(match_method):
    grey = cv2.cvtColor(stbt.load_image("black.png"), cv2.COLOR_BGR2GRAY)
    with pytest.raises(ValueError):
        stbt.match(grey, frame=black(),
                   match_parameters=mp(match_method=match_method))
Ejemplo n.º 44
0
def test_that_match_rejects_greyscale_template():
    grey = cv2.cvtColor(_load_template("black.png").image, cv2.cv.CV_BGR2GRAY)
    stbt.match(grey, frame=black())
Ejemplo n.º 45
0
def test_that_screensaver_appears_if_i_do_nothing():
    to_roku_home()
    assert wait_until(lambda: match("images/roku-screensaver.png"),
                      timeout_secs=2 * 60)
Ejemplo n.º 46
0
def test_ocr_on_text_next_to_image_match():
    frame = cv2.imread("tests/action-panel.png")
    m = stbt.match("tests/action-panel-blue-button.png", frame)
    assert "YOUVIEW MENU" == stbt.ocr(frame,
                                      region=m.region.right_of(width=150))
Ejemplo n.º 47
0
def test_match_fast_path():
    # This is just an example of typical use
    assert stbt.match("action-panel-prototype.png",
                      frame=stbt.load_image("action-panel.png"))
Ejemplo n.º 48
0
def test_matchresult_region_when_first_pyramid_level_fails_to_match():
    f = _imread("videotestsrc-full-frame.png")
    assert stbt.Region(184, 0, width=92, height=160) == stbt.match(
        "videotestsrc-redblue-flipped.png", frame=f).region
Ejemplo n.º 49
0
def test_that_matchresult_str_image_matches_template_passed_to_match():
    assert "image=\'black.png\'" in str(stbt.match("black.png", frame=black()))
Ejemplo n.º 50
0
def test_transparent_reference_image_with_sqdiff_normed_raises_valueerror():
    f = stbt.load_image("buttons-on-blue-background.png")
    with pytest.raises(ValueError):
        stbt.match("button-transparent.png", f,
                   match_parameters=mp(stbt.MatchMethod.SQDIFF_NORMED))
Ejemplo n.º 51
0
def test_that_matchresult_image_matches_template_passed_to_match():
    assert stbt.match("black.png", frame=black()).image == "black.png"
Ejemplo n.º 52
0
def test_that_match_converts_greyscale_reference_image(filename):
    stbt.match(filename, frame=black())  # Doesn't raise
    stbt.match(stbt.load_image(filename), frame=black())
Ejemplo n.º 53
0
 def is_visible(self):
     ignore_text = stbt.MatchParameters(confirm_method="none")
     return stbt.match("images/roku/menu-selection-background.png",
                       frame=self._frame, region=self.selection_region,
                       match_parameters=ignore_text)
Ejemplo n.º 54
0
def test_that_matchresult_str_image_matches_template_passed_to_match_custom():
    assert "image=<Custom Image>" in str(
        stbt.match(black(30, 30), frame=black()))
Ejemplo n.º 55
0
def test_match():
    assert stbt.match("videotestsrc-redblue.png")
Ejemplo n.º 56
0
def test_matchresult_region_when_first_pyramid_level_fails_to_match():
    f = stbt.load_image("videotestsrc-full-frame.png")
    r = stbt.match("videotestsrc-redblue-flipped.png", frame=f).region
    assert r.width == 92
    assert r.height == 160
Ejemplo n.º 57
0
def test_that_roku_home_shows_netflix_player():
    to_roku_home()
    assert wait_until(lambda: match("images/netflix-tile.png"))
Ejemplo n.º 58
0
 def is_visible(self):
     return bool(stbt.match('info.png', frame=self._frame))