def _update_scaling_params(self): # type: () -> Optional[ScaleProvider] if (self.device_pixel_ratio != self._UNKNOWN_DEVICE_PIXEL_RATIO or not isinstance(self._scale_provider, NullScaleProvider)): logger.debug("Device pixel ratio was already changed") return self._scale_provider logger.debug("Trying to extract device pixel ratio...") try: device_pixel_ratio = eyes_selenium_utils.get_device_pixel_ratio( self._driver) except Exception as e: logger.info( "Failed to extract device pixel ratio! Using default. Error %s " % e) device_pixel_ratio = self._DEFAULT_DEVICE_PIXEL_RATIO logger.info("Device pixel ratio: {}".format(device_pixel_ratio)) self._device_pixel_ratio = device_pixel_ratio logger.debug("Setting scale provider...") try: self._scale_provider = ContextBasedScaleProvider( top_level_context_entire_size=self._driver. get_entire_page_size(), viewport_size=self.configure.viewport_size, device_pixel_ratio=device_pixel_ratio, is_mobile_device=False, # TODO: fix scaling for mobile ) # type: ScaleProvider except Exception: # This can happen in Appium for example. logger.info("Failed to set ContextBasedScaleProvider.") logger.info("Using FixedScaleProvider instead...") self._scale_provider = FixedScaleProvider(1 / device_pixel_ratio) logger.info("Done!") return self._scale_provider
def update_scaling_params(self): # type: () -> Optional[ScaleProvider] if ( self.device_pixel_ratio != self._UNKNOWN_DEVICE_PIXEL_RATIO or not isinstance(self._scale_provider, NullScaleProvider) ): logger.debug("Device pixel ratio was already changed") return self._scale_provider logger.debug("Trying to extract device pixel ratio...") try: if ( self.driver.is_mobile_app and Feature.SCALE_MOBILE_APP in self.configure.features ): device_pixel_ratio = self.driver.session["pixelRatio"] else: device_pixel_ratio = self._driver.execute_script( "return window.devicePixelRatio;" ) except Exception as e: logger.info( "Failed to extract device pixel ratio! Using default. Error %s " % e ) device_pixel_ratio = self._DEFAULT_DEVICE_PIXEL_RATIO logger.info("Device pixel ratio: {}".format(device_pixel_ratio)) self._device_pixel_ratio = device_pixel_ratio logger.debug("Setting scale provider...") try: self._scale_provider = ContextBasedScaleProvider( top_level_context_entire_size=self._driver.get_entire_page_size(), viewport_size=self.configure.viewport_size, device_pixel_ratio=device_pixel_ratio, is_mobile_device=False, # TODO: fix scaling for mobile ) # type: ScaleProvider except Exception: # This can happen in Appium for example. logger.info("Failed to set ContextBasedScaleProvider.") logger.info("Using FixedScaleProvider instead...") self._scale_provider = FixedScaleProvider(1 / device_pixel_ratio) logger.debug("Scaling provider has been set") return self._scale_provider