Skip to content

Commit

Permalink
Create option debug
Browse files Browse the repository at this point in the history
  • Loading branch information
welbert committed Nov 19, 2016
1 parent eeb9c87 commit cdba9de
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 25 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Specifies files to intentionally ignore when using Git
# http://git-scm.com/docs/gitignore

.jshintrc
node_modules\
node_modules/
output\
Expand Down
7 changes: 5 additions & 2 deletions bin/guide-automator-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var options = {
output: "",
html: false,
pdf: false,
style: 'default'
style: 'default',
debug: false
};

function updateHtmlStart() {
Expand Down Expand Up @@ -90,6 +91,8 @@ function exportFiles(text, cb) {
if (options.pdf)
exportPDF(html + html_end);
}
if (options.debug)
console.timeEnd("Guide-Automator");
}

function exportPDF(html) {
Expand All @@ -107,4 +110,4 @@ function exportPDF(html) {
module.exports = {
defineOptions: defineOptions,
exportFiles: exportFiles
};
};;
27 changes: 20 additions & 7 deletions bin/guide-automator-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var GLOBAL = {};
var options = {
output: "",
outlineStyle: "solid red 3px",
legacy: false
legacy: false,
debug: false
};

module.exports = {
Expand Down Expand Up @@ -80,15 +81,20 @@ function takeScreenshot(width) {
width = width || DEFAULT_IMG_WIDTH;
var localImageName = imgCount; //Tratamento devido procedimentos async

if (options.debug)
console.time("Screenshot " + localImageName);

driver.takeScreenshot().then(
function(image, err) {
if (err) {
throw err;
} else {
fs.writeFile(options.output + '/' + localImageName + '.png', image, 'base64', function(err) {
if (err) {
if (err)
throw err;
}

if (options.debug)
console.timeEnd("Screenshot " + localImageName);
});
}
}
Expand Down Expand Up @@ -117,6 +123,9 @@ function takeScreenshotOf(cssSelector, crop, outline, width) {
width = width || DEFAULT_IMG_WIDTH;
var localImageName = imgCount; //Tratamento devido procedimentos async

if (options.debug)
console.time("ScreenshotOF " + localImageName);

driver.findElement(By.css(cssSelector)).then(function(el) {
if (outline) {
driver.executeScript("arguments[0].style.outline = '" + options.outlineStyle + "'", el);
Expand All @@ -131,15 +140,19 @@ function takeScreenshotOf(cssSelector, crop, outline, width) {
gm(img)
.crop(rect.width, rect.height, rect.left, rect.top)
.write(options.output + '/' + localImageName + '.png', function(err) {
if (err) {
if (err)
throw err;
}

if (options.debug)
console.timeEnd("ScreenshotOF " + localImageName);
});
} else {
fs.writeFile(options.output + '/' + localImageName + '.png', image, 'base64', function(err) {
if (err) {
if (err)
throw err;
}

if (options.debug)
console.timeEnd("ScreenshotOF " + localImageName);
});
}
}
Expand Down
16 changes: 14 additions & 2 deletions bin/guide-automator-parser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var options = {
output: "",
outlineStyle: "solid red 3px",
legacy: false
legacy: false,
debug: false
};

module.exports = {
Expand Down Expand Up @@ -182,6 +183,11 @@ function guideAutomatorParser(mdText, cb) {
throw err;

guideAutomator.quit().then(function() {
if (options.debug) {
console.log("");
console.timeEnd('Selenium');
}

return replaceRemainingBlocks(cb);
});

Expand All @@ -190,7 +196,7 @@ function guideAutomatorParser(mdText, cb) {
}
}
//-- Fim Tratamento dos tokens ou execução de funcionalidades 'automator' ------

//--------------------------------------------------------------------
//-- Tratamento via javascript
function replaceBlockWithJsStdout(blockIndex, jsStdout) {
var index = 0;
Expand All @@ -213,6 +219,12 @@ function extractJavascript(markdownAndCode, cb) {
}

function executeJavascriptSelenium(markdownText, cb) {
if (options.debug) {
console.log(`File's JSBlocks: ` + seleniumBlocks.length);
console.log("");
console.time('Selenium');
}

for (var n_block = 0; n_block < seleniumBlocks.length; n_block++) {
guideAutomator.executeExternFunction(seleniumBlocks[n_block]);
var jsStdout = guideAutomator.getReturn();
Expand Down
12 changes: 12 additions & 0 deletions examples/exampleSimple.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Github - Access

Access [https://github.com](https://github.com).

```javascript

//Access url
get('https://github.com/');

//Take Screenshot of actual state
takeScreenshot();
```
24 changes: 21 additions & 3 deletions guide-automator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var themeList = ['lightBlue', 'lightOrange'];
var fs = require("fs");
var options = {
debug: false,
input: "",
output: ".",
outlineStyle: "solid red 3px",
Expand Down Expand Up @@ -50,7 +51,8 @@ program.version(pjson.version)
.option('-H, --html', 'Export manual to HTML, default is export for all types', false)
.option('-I, --image', `Export ONLY manual's image and ignore others types, default is export for all types`, false)
.option('-s, --style <style.css>', 'Css style to be used in the manual or theme [' + themeList.toString() + ']')
.option('-L, --legacy', 'Use Legacy mode "<automator>" [DEPRECATED]');
.option('-L, --legacy', 'Use Legacy mode "<automator>" [DEPRECATED]')
.option('-d, --debug', 'Show progress of code');

program.on('--help', function() {
console.log(' Examples:');
Expand All @@ -63,11 +65,24 @@ program.on('--help', function() {

program.parse(process.argv);

if (program.debug) {
console.log("Version: " + pjson.version);
console.log("Options Used.:");
}

Object.keys(options)
.forEach(function(key) {
options[key] = program[key] || options[key];
if (options.debug)
console.log(" " + key + ": " + options[key].toString());
});

if (options.debug) {
console.log("--------");
console.time("Guide-Automator");
}


//if image, others exports type are ignored
if (options.image)
options.pdf = options.html = false;
Expand Down Expand Up @@ -109,9 +124,12 @@ processInput(options.input, function(err) {

function processInput(input, cb) {
fs.readFile(input, 'utf8', (err, data) => { //Leitura do arquivo
if (err) {
if (err)
return cb(err);
}

if (options.debug)
console.log(`File's line: ` + data.split(/\r\n|\r|\n/).length);

return guideAutomator.guideAutomatorParser(data, function(value, err) {
if (err)
throw err;
Expand Down
17 changes: 9 additions & 8 deletions install_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
is_executable () {
command -v "$1" >/dev/null 2>&1
}

errcho () {
>&2 echo "$@"
}
Expand All @@ -23,15 +23,15 @@ if ! (is_executable npm && is_executable node); then
else
errcho "Couldn't install NodeJS. Please install NodeJS manually, then run this script again."
errcho "Visit https://nodejs.org/en/download/package-manager/ for instructions on how to install NodeJS on your OS."
exit 1
exit 1
fi
rm setup_6.x
fi

if ! (is_executable wkhtmltopdf); then
echo " # Installing Dependencie WKHTMLTOPDF"
case $( uname -m ) in
x86_64)
x86_64)
wget http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz -O wkhtmltox.tar.xz;;
*)
wget http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_linux-generic-i386.tar.xz -O wkhtmltox.tar.xz;;
Expand All @@ -43,24 +43,25 @@ if ! (is_executable wkhtmltopdf); then
sudo ln -s ../lib/wkhtmltox/bin/wkhtmltopdf wkhtmltopdf
cd ~
fi

if ! (is_executable convert); then
echo " # Installing Dependencie IMAGEMAGICK"
sudo apt-get install imagemagick -y
fi
fi

if ! (is_executable chromedriver) ; then
echo " # Installing Dependencie CHROMEDRIVER"
case $( uname -m ) in
x86_64)
x86_64)
wget https://chromedriver.storage.googleapis.com/2.25/chromedriver_linux64.zip -O chromedriver.zip;;
*)
wget https://chromedriver.storage.googleapis.com/2.25/chromedriver_linux32.zip -O chromedriver.zip;;
esac

unzip chromedriver.zip
sudo mv chromedriver /usr/bin/
rm chromedriver.zip
rm chromedriver.zip
fi

sudo npm install -g guide-automator
echo "$ guide-automator -h , or check https://www.npmjs.com/package/guide-automator"

0 comments on commit cdba9de

Please sign in to comment.