code: def screenshot(self, filename=None):
          
          if self.__keep_screen:
              return self.__last_screen
          try:
              screen = self._take_screenshot()
          except IOError:
              # try taks screenshot again
              log.warn("warning, screenshot failed [2/1], retry again")
              screen = self._take_screenshot()
          self.__last_screen = screen
          if filename:
              save_dir = os.path.dirname(filename) or '.'
              if not os.path.exists(save_dir):
                  os.makedirs(save_dir)
              screen.save(filename)
          return screen
docs: Take screen snapshot
  
          Args:
              - filename: filename where save to, optional
  
          Returns:
              PIL.Image object
  
          Raises:
              TypeError, IOError