Is a screenshot desired, based on the command and the test result.
1425
public boolean requireScreenshot(final ExtendedSeleniumCommand command,
			boolean result) {
		return
			(!command.isAssertCommand()
				&& !command.isVerifyCommand()
				&& !command.isWaitForCommand()
				&& screenshotPolicy == ScreenshotPolicy.STEP)
			|| (!result
				&& (screenshotPolicy == ScreenshotPolicy.FAILURE
					|| (command.isAssertCommand() && screenshotPolicy == ScreenshotPolicy.ASSERTION)));
	}
935462
def info(self, text, screenshot=None):
        
        step = {
            'time': '%.1f' % (time.time()-self.start_time,),
            'action': 'info',
            'description': text,
            'success': True,
        }   
        if screenshot:
            step['screenshot'] = self._take_screenshot(screenshot, name_prefix='info')
        self.steps.append(step)
1355508
def _check_command_result(self):
        """"""
        if self.commandResult.startswith('/bin/bash'):
            raise UtilError('%s' % self.commandResult.split(' ', 1)[1])
        if self.commandResult.startswith('/bin/mv'):
            raise UtilError('%s' % self.commandResult.split(' ', 1)[1])
        if self.commandResult.startswith('/bin/ls'):
            raise UtilError('%s' % self.commandResult.split(' ', 1)[1])
        if self.commandResult.startswith('/bin/rm'):
            raise UtilError('%s' % self.commandResult.split(' ', 1)[1])
        if 'invalid option' in self.commandResult:
            raise UtilError('%s' % self.commandResult)
        if 'Invalid option' in self.commandResult:
            raise UtilError('%s' % self.commandResult)
        if 'usage: /usr/bin/get_dossier' in self.commandResult:
            raise UtilError('%s' % self.commandResult)
1105652
function screenshot(name, options) {
      var options  = options || {};
      var newPath = path;

      // options to override
      if(options.selector) { selector = options.selector; }
      if(options.path) { newPath = path + '/' + options.path; }
      if(Array.isArray(options.exclude)) { exclude = exclude.concat(options.exclude); }

      // Check if in phantomjs browser and PhantomScreenshot exists
      if(window.callPhantom && window.PhantomScreenshot) {
        asyncScreenshot(name, newPath);
      }
    }
1053112
def screenshot(self, filename=None):
        '''
        
        '''
        image = self.d.screenshot()
        if self.rotation:
            method = getattr(Image, 'ROTATE_{}'.format(self.rotation*90))
            image = image.transpose(method)
        if filename:
            image.save(filename)
        return image
426107
def work(path)
      out = "#{path}/#{@name}.png"
      @fetcher.fetch(output: out, width: @size[0], height: @size[1], dpi: @dpi)
    rescue Screencap::Error
      puts "Fail to capture screenshot #{@url}"
    end
576907
def step_command_output_should_contain_text(context, text):
    '''
    
    '''
    expected_text = text
    if "{__WORKDIR__}" in expected_text or "{__CWD__}" in expected_text:
        expected_text = textutil.template_substitute(text,
             __WORKDIR__ = posixpath_normpath(context.workdir),
             __CWD__     = posixpath_normpath(os.getcwd())
        )
    actual_output = context.command_result.output
    with on_assert_failed_print_details(actual_output, expected_text):
        textutil.assert_normtext_should_contain(actual_output, expected_text)
1147081
public boolean compareOneScreenshot(File baseImg, File targetImg, int rows, int columns) {

        boolean match = true;
        BufferedImage[][] baseBfImg = splitImage(baseImg, rows, columns);
        BufferedImage[][] targetBfImg = splitImage(targetImg, rows, columns);

        BufferedImage[][] diffImg = new BufferedImage[rows][columns];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < columns; j++) {

                byte[] baseImgBytes = toByteArray(baseBfImg[i][j]);
                byte[] targetImgBytes = toByteArray(targetBfImg[i][j]);

                if (Arrays.equals(baseImgBytes, targetImgBytes)) {
                    diffImg[i][j] = darken(targetBfImg[i][j]);
                } else {
                    match = false;
                    diffImg[i][j] = targetBfImg[i][j];
                }
            }
        }

        if (match) {
            LOG.info("screenshot.match", targetImg.getName());
        } else {
            LOG.error("screenshot.unmatch", targetImg.getName());
            writeDiffImg(targetImg, diffImg);
        }

        return match;
    }
1230911
def snapshot(self, filename="tmp.png"):
        
        if not filename:
            filename = "tmp.png"
        if self.handle:
            try:
                screenshot(filename, self.handle)
            except win32gui.error:
                self.handle = None
                screenshot(filename)
        else:
            screenshot(filename)

        img = aircv.imread(filename)
        os.remove(filename)

        return img
192087
function saveScreenshotIfExists(testResults) {
        var deferred = Q.defer();

        if (testResults.screenshotBuffer) {

            var screenshotFilePath = path.join(resultsDir, testResults.runId, resultScreenshotName);
            fs.writeFile(screenshotFilePath, testResults.screenshotBuffer);

            delete testResults.screenshotBuffer;

        } else {
            deferred.resolve();
        }

        return deferred;
    }
858486
function (commandName, args, result, error) {
    if (error) {
      if ( error.type ) {
        errorType = error.type
      } else if ( error.toString().indexOf("Error: An element could not be located on the page using the given search parameters") > -1 ) {
        errorType = true
      }

      try {
        const screenshot = browser.saveScreenshot() // returns base64 string buffer

        const screenshotFolder = path.join(process.env.WDIO_WORKFLO_RUN_PATH, 'allure-results')
        const screenshotFilename = `${screenshotFolder}/${global.screenshotId}.png`

        global.errorScreenshotFilename = screenshotFilename

        fs.writeFileSync(screenshotFilename, screenshot)
      } catch (err) {
        console.log(`Failed to take screenshot: ${err.message}`)
        console.log(err.stack)
      }
    }

    if (typeof workfloConf.afterCommand === 'function') {
      return workfloConf.afterCommand(commandName, args, result, error)
    }
  }
192457
def cmp_output(test)
      # test out and err
      if test.expected_out_exists? && test.expected_err_exists?
        cmp_out(test)
        cmp_err(test)
        return :success if (test.out_result && test.err_result)

      # test only out
      elsif test.expected_out_exists?
        cmp_out(test)
        return :success if test.out_result

      # test only err
      else
        cmp_err(test)
        return :success if test.err_result
      end

      return :failed
    end
1078221
protected function tryOutputImage()
    {
        if (is_file($this->data_cached_file)) {

            $this->response->addHeader('Last-Modified', gmdate('D, d M Y H:i:s T', filemtime($this->data_cached_file)))
                ->addHeader('Content-Length', filesize($this->data_cached_file))
                ->addHeader('Content-type', mime_content_type($this->data_cached_file))
                ->sendHeaders();

            readfile($this->data_cached_file);
            exit;
        }
    }
251031
def screenshots_done(self, jobid):
        
        resp = self.session.get(os.path.join(self.api_url, '{0}.json'.format(jobid)))
        resp = self._process_response(resp)
        return True if resp.json()['state'] == 'done' else False
736161
def generate_screenshots():
    """"""
    this_script = os.path.abspath(__file__)
    this_directory = os.path.dirname(this_script)
    repository = os.path.join(this_directory, os.pardir)
    examples_directory = os.path.join(repository, 'docs', 'examples')
    images_directory = os.path.join(repository, 'docs', 'images')
    for shell_script in sorted(glob.glob(os.path.join(examples_directory, '*.sh'))):
        basename, extension = os.path.splitext(os.path.basename(shell_script))
        image_file = os.path.join(images_directory, '%s.png' % basename)
        logger.info("Generating %s by running %s ..",
                    format_path(image_file),
                    format_path(shell_script))
        command_line = [sys.executable, __file__, shell_script]
        random_title = random_string(25)
        # Generate the urxvt command line.
        urxvt_command = [
            'urxvt',
            # Enforce a default geometry.
            '-geometry', '98x30',
            # Set the text and background color.
            '-fg', TEXT_COLOR,
            '-bg', BACKGROUND_COLOR,
            # Set the font name and pixel size.
            '-fn', 'xft:%s:pixelsize=%i' % (FONT_NAME, FONT_SIZE),
            # Set the window title.
            '-title', random_title,
            # Hide scrollbars.
            '+sb',
        ]
        if which('qtile-run'):
            # I've been using tiling window managers for years now, at the
            # moment 'qtile' is my window manager of choice. It requires the
            # following special handling to enable the 'urxvt' window to float,
            # which in turn enables it to respect the '--geometry' option.
            urxvt_command.insert(0, 'qtile-run')
            urxvt_command.insert(1, '-f')
        # Apply the Ubuntu color scheme to urxvt.
        for index, css_color in enumerate(EIGHT_COLOR_PALETTE):
            urxvt_command.extend(('--color%i' % index, css_color))
        # Add the command that should run inside the terminal.
        urxvt_command.extend(('-e', 'sh', '-c', 'setterm -cursor off; %s' % quote(command_line)))
        # Launch urxvt.
        execute(*urxvt_command, async=True)
        # Make sure we close the urxvt window.
        try:
            # Wait for urxvt to start up. If I were to improve this I could
            # instead wait for the creation of a file by interpret_script().
            time.sleep(10)
            # Take a screen shot of the window using ImageMagick.
            execute('import', '-window', random_title, image_file)
            # Auto-trim the screen shot, then give it a 5px border.
            execute('convert', image_file, '-trim',
                    '-bordercolor', BACKGROUND_COLOR,
                    '-border', '5', image_file)
        finally:
            execute('wmctrl', '-c', random_title)
1248710
def screenshot_themes(self, *args):
        """"""
        from time import sleep
        for theme in THEMES:
            example.set_theme(theme)
            example.update()
            sleep(0.05)
            self.screenshot()
1075308
def save_screenshot(self, name, folder=None):
        
        return page_actions.save_screenshot(self.driver, name, folder)