def get_text(self, *regions):
     # type: (*OCRRegion) -> List[Text]
     result = []
     for ocr_region in regions:
         self._process_app_output(ocr_region)
         image = ocr_region.app_output_with_screenshot.screenshot.image
         screenshot_url = self._server_connector.try_upload_image(
             image_utils.get_bytes(image))
         data = TextSettingsData(
             app_output=AppOutput(
                 screenshot_url=screenshot_url,
                 location=Point.ZERO(),
                 dom_url=ocr_region.app_output_with_screenshot.app_output.
                 dom_url,
             ),
             language=ocr_region._language,
             min_match=ocr_region._min_match,
             regions=[
                 ExpectedTextRegion(
                     0,
                     0,
                     width=image.width,
                     height=image.height,
                     expected=ocr_region._hint,
                 )
             ],
         )
         result.extend(
             self._server_connector.get_text_in_running_session_image(data))
     return result
Esempio n. 2
0
    def get_locators(self, visual_locator_settings):
        # type: (VisualLocatorSettings) -> LOCATORS_TYPE
        argument_guard.not_none(visual_locator_settings)

        logger.info(
            "Get locators with given names: {}".format(visual_locator_settings.names)
        )
        logger.info("Requested viewport screenshot for visual locators..")
        viewport_screenshot = self._get_viewport_screenshot()
        self._debug_screenshot_provider.save(
            viewport_screenshot,
            "Visual locators: {}".format(visual_locator_settings.names),
        )
        image = image_utils.get_bytes(viewport_screenshot)
        logger.info("Post visual locators screenshot...")
        viewport_screenshot_url = self._server_connector.try_upload_image(image)

        logger.info("Screenshot URL: {}".format(viewport_screenshot_url))
        data = VisualLocatorsData(
            app_name=self._eyes.configure.app_name,
            image_url=viewport_screenshot_url,
            first_only=visual_locator_settings.values.is_first_only,
            locator_names=visual_locator_settings.values.names,
        )
        logger.info("Post visual locators: {}".format(data))
        return self._server_connector.post_locators(data)
        def get_app_output():
            scale_provider = self._eyes.update_scaling_params()
            viewport_screenshot = self._eyes.get_scaled_cropped_viewport_image(
                scale_provider)
            image = image_utils.get_bytes(viewport_screenshot)
            screenshot_url = self._server_connector.try_upload_image(image)

            dom_json = self._eyes._try_capture_dom()
            dom_url = self._eyes._try_post_dom_capture(dom_json)
            return AppOutput(dom_url=dom_url,
                             screenshot_url=screenshot_url,
                             location=Point.ZERO())
def prepare_match_data(match_data):
    # type: (MatchWindowData) -> bytes
    screenshot64 = match_data.app_output.screenshot64
    if screenshot64:
        match_data.app_output.screenshot64 = None
        image = image_utils.image_from_base64(screenshot64)
        screenshot_bytes = image_utils.get_bytes(image)  # type: bytes
    else:
        screenshot_bytes = b""
    match_data_json = json_utils.to_json(match_data)
    logger.debug("MatchWindowData {}".format(match_data_json))
    match_data_json_bytes = match_data_json.encode("utf-8")  # type: bytes
    match_data_size_bytes = pack(">L", len(match_data_json_bytes))  # type: bytes
    body = match_data_size_bytes + match_data_json_bytes + screenshot_bytes
    return body
Esempio n. 5
0
    def _perform_match(
            self,
            user_inputs,  # type: UserInputs
            app_output_width_screenshot,  # type: AppOutputWithScreenshot
            check_settings,  # type: CheckSettings
            replace_last,  # type: bool
            image_match_settings,  # type: ImageMatchSettings
            agent_setup,  # type: Text
            render_id,  # type: Text
            source,  # type: Text
    ):
        # type: (...) -> MatchResult
        name = check_settings.values.name
        variant_id = check_settings.values.variation_group_id
        screenshot = app_output_width_screenshot.screenshot
        app_output = app_output_width_screenshot.app_output
        if screenshot:
            app_output.screenshot_bytes = image_utils.get_bytes(
                screenshot.image)

        match_window_data = MatchWindowData(
            ignore_mismatch=False,
            user_inputs=user_inputs,
            options=Options(
                name=name,
                user_inputs=user_inputs,
                replace_last=replace_last,
                ignore_mismatch=False,
                ignore_match=False,
                force_mismatch=False,
                force_match=False,
                image_match_settings=image_match_settings,
                source=source,
                render_id=render_id,
                variant_id=variant_id,
            ),
            app_output=app_output,
            tag=name,
            agent_setup=agent_setup,
            render_id=render_id,
        )
        return self._server_connector.match_window(self._running_session,
                                                   match_window_data)
def test_match_window_with_image_uploading(started_connector, server_status):
    #  type: (ServerConnector, int) -> None
    data = copy(MATCH_WINDOW_DATA_OBJ)
    data.app_output.screenshot_url = None
    data.app_output.screenshot_bytes = image_utils.get_bytes(
        image_utils.image_from_base64(IMAGE_BASE_64))
    rendering_info = RenderingInfo(
        access_token="some access",
        service_url="https://render-wus.applitools.com",
        results_url=
        "https://eyespublicwustemp.blob.core.windows.net/temp/__random__?sv=2017-04-17&sr=c&sig=aAArw3au%",
        stitching_service_url="https://some.stitchingserviceuri.com",
    )
    with patch(
            "applitools.core.server_connector.ServerConnector.render_info",
            return_value=rendering_info,
    ):
        with patch(
                "applitools.core.server_connector.ClientSession.put",
                return_value=MockResponse(None, None, server_status),
        ):
            with patch(
                    "applitools.core.server_connector.ClientSession.post",
                    side_effect=mocked_requests_post,
            ):
                if server_status in [200, 201]:
                    started_connector.match_window(RUNNING_SESSION_OBJ, data)
                else:
                    with pytest.raises(EyesError):
                        started_connector.match_window(RUNNING_SESSION_OBJ,
                                                       data)

    if server_status in [200, 201]:
        target_url = data.app_output.screenshot_url
        assert target_url.startswith(
            "https://eyespublicwustemp.blob.core.windows.net/temp/")
        assert target_url.endswith("?sv=2017-04-17&sr=c&sig=aAArw3au%")
        assert "__random__" not in target_url
Esempio n. 7
0
    def _perform_match(
            self,
            user_inputs,  # type: UserInputs
            app_output_width_screenshot,  # type: AppOutputWithScreenshot
            name,  # type: Text
            ignore_mismatch,  # type: bool
            image_match_settings,  # type: ImageMatchSettings
            agent_setup,  # type: Text
            render_id,  # type: Text
    ):
        # type: (...) -> MatchResult

        screenshot = app_output_width_screenshot.screenshot
        app_output = app_output_width_screenshot.app_output
        if screenshot:
            app_output.screenshot_bytes = image_utils.get_bytes(
                screenshot.image)

        match_window_data = MatchWindowData(
            ignore_mismatch=ignore_mismatch,
            user_inputs=user_inputs,
            options=Options(
                name=name,
                user_inputs=user_inputs,
                ignore_mismatch=ignore_mismatch,
                ignore_match=False,
                force_mismatch=False,
                force_match=False,
                image_match_settings=image_match_settings,
                render_id=render_id,
            ),
            app_output=app_output,
            tag=name,
            agent_setup=agent_setup,
            render_id=render_id,
        )
        return self._server_connector.match_window(self._running_session,
                                                   match_window_data)