Пример #1
0
 def set_power_capacity(self, capacity: int):
     from selenium.common.exceptions import WebDriverException
     try:
         self.get_driver().set_power_capacity(capacity)
     except WebDriverException:
         exception = f'{self.device_name}: powerCapacity method is only available for emulators'
         logger.log_error(error_with_traceback(exception))
         raise Exception(
             'powerCapacity method is only available for emulators')
Пример #2
0
    def __show_error(self, exception) -> None:
        driver = self.args[0].testui_driver
        config: Configuration = driver.configuration

        if config.save_screenshot_on_fail:
            driver.save_screenshot()

        full_exception = exception
        if config.save_full_stacktrace:
            full_exception = error_with_traceback(exception)

        if driver.soft_assert:
            logger.log_error(full_exception)
            driver.set_error(full_exception)
        else:
            logger.log_error(full_exception)
            driver.set_error(full_exception)
            raise CollectionException(exception)
Пример #3
0
    def find_image_match(self,
                         comparison,
                         threshold=0.90,
                         assertion=False,
                         not_found=False,
                         image_match=''):
        now = datetime.now()
        current_time = now.strftime("%Y-%m-%d%H%M%S")
        image_name = f'{self.device_udid}{current_time}.png'
        image_path = self.save_screenshot(image_name)
        found, p = ImageRecognition(image_path, comparison, threshold,
                                    self.device_name).compare(image_match)
        if assertion and not found and not not_found:
            exception = f'{self.device_name}: The images compared did not match. threshold={threshold}, matched = {p}\n'
            logger.log_error(error_with_traceback(exception))
            raise Exception(exception)
        os.remove(image_path)

        return found
Пример #4
0
def testui_error(driver, exception: str) -> None:
    config = driver.configuration

    if config.save_screenshot_on_fail:
        try:
            driver.save_screenshot()
        except Exception as error:
            exception += f'{logger.bcolors.FAIL} \nCould not take screenshot:{logger.bcolors.ENDC}\n {error}'

    full_exception = exception
    if config.save_full_stacktrace:
        full_exception = error_with_traceback(exception)

    if driver.soft_assert:
        logger.log_error(full_exception)
        driver.set_error(full_exception)
    else:
        logger.log_error(full_exception)
        driver.set_error(full_exception)
        raise ElementException(
            'There were errors during the UI testing, check the logs')
Пример #5
0
 def __show_error(self, exception):
     now = datetime.now()
     current_time = now.strftime("%Y-%m-%d%H%M%S")
     root_dir = os.path.dirname(
         os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
     Path(root_dir + "/report_screenshots").mkdir(parents=True,
                                                  exist_ok=True)
     image_name = f'ERROR-{self.args[0].device_name}-{current_time}.png'
     self.args[0].testui_driver.save_screenshot(
         image_name, directory='report_screenshots/')
     exception = exception + f'{logger.bcolors.FAIL} \n Screenshot taken and saved as: ' \
                             f'report_screenshots/testui-{image_name}{logger.bcolors.ENDC}'
     from testui.support.helpers import error_with_traceback
     full_exception = error_with_traceback(exception)
     if self.args[0].testui_driver.soft_assert:
         logger.log_error(full_exception)
         self.args[0].testui_driver.set_error(full_exception)
         return self
     else:
         logger.log_error(full_exception)
         self.args[0].testui_driver.set_error(full_exception)
         raise CollectionException(exception)
Пример #6
0
def testui_error(driver, exception):
    now = datetime.now()
    current_time = now.strftime("%Y-%m-%d%H%M%S")
    root_dir = os.path.dirname(
        os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    Path(root_dir + "/report_screenshots").mkdir(parents=True, exist_ok=True)
    image_name = f'ERROR-{driver.device_name}-{current_time}.png'
    try:
        driver.save_screenshot(image_name, directory='report_screenshots/')
        exception += f'{logger.bcolors.FAIL} \n Screenshot taken and saved as: ' \
                     f'report_screenshots/testui-{image_name}{logger.bcolors.ENDC}\n'
    except Exception as error:
        exception += f'{logger.bcolors.FAIL} \nCould not take screenshot:{logger.bcolors.ENDC}\n {error}'
    full_exception = error_with_traceback(exception)
    if driver.soft_assert:
        logger.log_error(full_exception)
        driver.set_error(full_exception)
    else:
        driver.set_error(full_exception)
        logger.log_error(full_exception)
        raise ElementException(
            'There were errors during the UI testing, check the logs')
Пример #7
0
 def switch_to_context(self, context=0, last=False):
     if last:
         context = len(self.__appium_driver.contexts) - 1
     try:
         if len(self.__appium_driver.contexts) == 1:
             logger.log(
                 f'{self.device_name}: There is only one context: {self.__appium_driver.contexts[context]}'
             )
         elif context >= len(self.__appium_driver.contexts):
             logger.log_warn(
                 f'{self.device_name}: Cannot switch to context {context}: there are just '
                 f'{len(self.__appium_driver.contexts)} contexts')
         self.__appium_driver.execute(
             'switchToContext',
             {'name': self.__appium_driver.contexts[context]})
         logger.log(
             f'{self.device_name}: Switched to context: {self.__appium_driver.contexts[context]}'
         )
     except Exception as err:
         if self.__soft_assert:
             logger.log_error(err)
         else:
             raise err
     return self