[captureScreenshot description]
@param  {[type]} chromy   [description]
@param  {[type]} filePath [description]
@param  {[type]} selector [description]
@param  {[type]} config   [description]
@return {[type]}          [description]
 TODO: remove filepath_
174494
function captureScreenshot (chromy, filePath_, selector, selectorMap, config, selectors) {
  return new Promise(function (resolve, reject) {
    // VIEWPORT screenshot
    if (selector === VIEWPORT_SELECTOR || selector === BODY_SELECTOR) {
      chromy
        .screenshot()
        .result(buffer => {
          return saveViewport(buffer, selector);
        });
    // DOCUMENT screenshot
    } else if (selector === NOCLIP_SELECTOR || selector === DOCUMENT_SELECTOR) {
      chromy.screenshotMultipleSelectors(['body'], saveSelector);
    // OTHER-SELECTOR screenshot
    } else {
      chromy.screenshotMultipleSelectors(selectors, saveSelector);
    }

    chromy
      .end()
      .then(_ => {
        resolve();
      })
      .catch(e => {
        reject(e);
      });

    // result helpers

    // saveViewport: selectors will be `body` or `viewport` ONLY
    function saveViewport (buffer, selector) {
      const filePath = selectorMap[selector].filePath;

      ensureDirectoryPath(filePath);
      return fs.writeFile(filePath, buffer);
    }

    // saveSelector: selectorArr will contain any valid selector (not body or viewport).
    // If body *is* found in selector arr then it was originally DOCUMENT_SELECTOR -- and it will be reset back to DOCUMENT_SELECTOR -- this is because chromy takes a Document shot when BODY is used.
    function saveSelector (err, buffer, index, selectorArr) {
      let selector = selectorArr[index];
      if (selector === BODY_SELECTOR) {
        selector = DOCUMENT_SELECTOR;
      }
      const selectorProps = selectorMap[selector];
      const filePath = selectorProps.filePath;
      if (!selectorProps.exists) {
        return fs.copy(config.env.backstop + SELECTOR_NOT_FOUND_PATH, filePath);
      } else if (!selectorProps.isVisible) {
        return fs.copy(config.env.backstop + HIDDEN_SELECTOR_PATH, filePath);
      } else {
        if (err) {
          console.log('ChromyJS returned an unexpected error while attempting to capture a selector.', err);
          return new Error(err);
        }
        ensureDirectoryPath(filePath);
        return fs.writeFile(filePath, buffer);
      }
    }
  });
}
204890
async function importCustomSelectorsFromCSSFile(from) {
	const css = await readFile(path.resolve(from));
	const root = postcss.parse(css, { from: path.resolve(from) });

	return importCustomSelectorsFromCSSAST(root);
}
832251
function getCssSelectorFromPath(path, selector){
  return parsePath(path).map(function(role){
    if (!role.role)
      return '';

    var start = escapeQuotes(role.role);
    var end = (role.subrole ? '/' + escapeQuotes(role.subrole) : '') + '"]';

    if (role.roleId)
    {
      if (selector && role.roleId == '*')
        start = '[role-marker^="' + start + '("][role-marker$=")';
      else
        start = '[role-marker="' + start + '(' + escapeQuotes(role.roleId) + ')';
    }
    else
    {
      start = '[role-marker="' + start;
    }

    return start + end;
  }).join(' ');
}
108138
function (filePath) {
    var removeFile = this._removeFile.bind(this)
    var message = 'Should I remove `' + filePath + '`?'

    var promptPromise = this.ui.prompt({
      type: 'confirm',
      name: 'answer',
      message: message,
      choices: [
        { key: 'y', name: 'Yes, remove it', value: 'yes' },
        { key: 'n', name: 'No, leave it there', value: 'no' }
      ]
    })

    return promptPromise.then(function (response) {
      if (response.answer) {
        return removeFile(filePath)
      } else {
        return RSVP.resolve()
      }
    })
  }
1100279
function loadComponentFile (meta, key, filepath, messages) {
  const ext = path.extname(filepath).slice(1)
  const loader = fileLoaders[ext] || fileLoaders.DEFAULT

  return loader(meta, key, filepath, messages)
}
311259
function layoutResource(filePath, config) {

    filePath = filePath || this.page.template;
    var testFilePath = filePath + config.extOut;
    var stat = this.has_file(testFilePath);

    if (stat) {
      return filePath;
    }

  }
1239653
function saveViewport (buffer, selector) {
      const filePath = selectorMap[selector].filePath;

      ensureDirectoryPath(filePath);
      return fs.writeFile(filePath, buffer);
    }
672203
function(editor, filepath) {
			var data = String(editor.getSelection());
			var caretPos = editor.getCaretPos();
			var info = editorUtils.outputInfo(editor);

			if (!data) {
				// no selection, try to find image bounds from current caret position
				var text = info.content, m;
				while (caretPos-- >= 0) {
					if (startsWith('src=', text, caretPos)) { // found <img src="">
						if ((m = text.substr(caretPos).match(/^(src=(["'])?)([^'"<>\s]+)\1?/))) {
							data = m[3];
							caretPos += m[1].length;
						}
						break;
					} else if (startsWith('url(', text, caretPos)) { // found CSS url() pattern
						if ((m = text.substr(caretPos).match(/^(url\((['"])?)([^'"\)\s]+)\1?/))) {
							data = m[3];
							caretPos += m[1].length;
						}
						break;
					}
				}
			}

			if (data) {
				if (startsWith('data:', data)) {
					return decodeFromBase64(editor, filepath, data, caretPos);
				} else {
					return encodeToBase64(editor, data, caretPos);
				}
			}

			return false;
		}
1272632
function (filePath) {

    // console.warn(filePath);


    var contents = String(fs.readFileSync(filePath));
    var fileExt = path.extname(filePath).substr(1);
    var fileType = fileTypes[fileExt] || fileTypes['default'];
    var returnType = /\r\n/.test(contents) ? '\r\n' : '\n';


    // console.log(fileType);

    var newContents = contents.replace(
        fileType.block,
        replaceIncludes(filePath, fileType, returnType)
    );

    // console.log(newContents);
    //  
    // return;

    if (contents !== newContents) {
        fs.writeFileSync(filePath, newContents);

        if (process.env.NODE_ENV !== 'test') {
            console.log(filePath + ' modified.');
        }
    }
}
823585
function FileMap(config) {
  this.config = config || {};
  this.config.exclude = config && config.exclude ? config.exclude : [];
  this.config.exclude.push('/_site');
  this.ignoreDotFiles = true;
  this.root = config.root;
  this.files = [];
  this.events = new EventEmitter();
  this.filesLeft = 0;
  this.dirsLeft = 1;
}
1334487
function takeScreenshot (name) {
  if(_disabled) {
    return q.resolve();
  }

  return browser.driver.controlFlow().execute(function () {

    return q.all([_getProperties(browser), _getMetaData(browser), browser.takeScreenshot(), _readRunIdFile()]).then(function (results) {
      var properties = results[0],
        metaData = results[1],
        compareSettings = _compareSettingsFn,
        png = results[2],
        run = results[3];

      if (!run || !run.run_id) {
        _throwError('VisualReview-protractor: Could not send screenshot to VisualReview server, could not find any run ID. Was initRun called before starting this test? See VisualReview-protractor\'s documentation for more details on how to set this up.');
      }

      return _client.sendScreenshot(name, run.run_id, metaData, properties, compareSettings, png)
        .catch(function (err) {
          _throwError('Something went wrong while sending a screenshot to the VisualReview server. ' + err);
        });
    });
  }.bind(this));
}
225930
function asyncScreenshot(name, path) {
      var rect, offset, clientRect;
      var assert = QUnit.config.current.assert,
          done   = assert.async();

      // pause test for 300ms for rendering purposes
      window.setTimeout(function() {
        // Hide dom element specified by each item in exclude array
        excludeElements(exclude);

        // bubbling to phantomjs to trigger screenshot event
        window.PhantomScreenshot(name, {
          path: path,
          rect: getOffset(selector)
        });

        // Let QUnit know it's done
        done();
      }, 300);
    }
879123
function renderTemplateFile(engine, filePath, context) {
    var loader = engine.getLoader();

    // Resolve the filePath
    var resolvedFilePath = loader.resolve(null, filePath);

    return Promise()
    .then(function() {
        if (!loader.async) {
            return loader.getSource(resolvedFilePath);
        }

        var deferred = Promise.defer();
        loader.getSource(resolvedFilePath, deferred.makeNodeResolver());
        return deferred.promise;
    })
    .then(function(result) {
        if (!result) {
            throw error.TemplateError(new Error('Not found'), {
                filename: filePath
            });
        }

        return render(engine, result.path, result.src, context);
    });

}
696190
function getConvetedDom(filePath) {
        var dom = jsdom.jsdom(fs.readFileSync(filePath).toString());
        lowerScriptsInfo(dom);
        lowerCSSInfo(dom);
        return dom;
    }
467150
def save_element_as_image_file(self, selector, file_name, folder=None):
        
        element = self.find_element(selector)
        element_png = element.screenshot_as_png
        if len(file_name.split('.')[0]) < 1:
            raise Exception("Error: file_name length must be > 0.")
        if not file_name.endswith(".png"):
            file_name = file_name + ".png"
        image_file_path = None
        if folder:
            if folder.endswith("/"):
                folder = folder[:-1]
            if len(folder) > 0:
                self.create_folder(folder)
                image_file_path = "%s/%s" % (folder, file_name)
        if not image_file_path:
            image_file_path = file_name
        with open(image_file_path, "wb") as file:
            file.write(element_png)
333757
function isPathMatchSelector(path, selector){
  function isMatch(path, selector){
    path = typeof path == 'string' ? parseRole(path) : path || '';
    selector = typeof selector == 'string' ? parseRole(selector) : selector || '';

    return selector.role == path.role &&
           (selector.roleId == '*' || selector.roleId == path.roleId) &&
           selector.subrole == path.subrole;
  }

  var pathIndex = path.length;
  var selectorIndex = selector.length;

  if (!selectorIndex)
    return true;

  if (!isMatch(path[--pathIndex], selector[--selectorIndex]))
    return false;

  while (pathIndex > 0 && selectorIndex > 0)
    if (!isMatch(path[--pathIndex], selector[--selectorIndex]))
      selectorIndex++;

  return selectorIndex === 0;
}
325957
function findConfig_p(appDir){
  var filePath = path.join(appDir, ".shiny_app.conf");
  return fsutil.safeStat_p(filePath)
  .then(function(stat){
    if (stat && stat.isFile()){
      return (filePath);
    }
    throw new Error('Invalid app configuration file.');
  });
}