Skip to content

Commit

Permalink
TakeScreenshotOF with pageContext
Browse files Browse the repository at this point in the history
  • Loading branch information
welbert committed Jan 11, 2017
1 parent 110151c commit 37a019e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,13 @@ Params: `<Required>` `[Optional]`
### takeScreenshotOf
- Description: Take Screenshot of specific element
- Params: `<cssSelector>`, `[crop]`, `[outline]`, `[imageWidth]`
- Params: `Array(<cssSelector>,[cssSelector],...)`, `[crop]`, `[outline]`, `[imageWidth]`
- Params: `Array(Array(<cssSelector>,<Iframe-CssSelector>),[cssSelector],...)`, `[crop]`, `[outline]`, `[imageWidth]`
- Example:
- takeScreenshotOf('#user-content-guideautomator');
- takeScreenshotOf('#user-content-guideautomator',false,true);
- takeScreenshotOf(['#user-content-guideautomator','.avatar'],false,true); //Multiple cssSelector only for outline
- takeScreenshotOf(['#user-content-guideautomator','.avatar'],false,true); //Multiple cssSelector(only for outline)
- takeScreenshotOf([['#user-content-guideautomator','#frameID'],'.avatar'],false,true) //Multiple cssSelector (only for outline) on different contexts(Iframe)

### fillIn
- Description: Fill in field element
Expand Down
19 changes: 16 additions & 3 deletions bin/guide-automator-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var __Driver = new __webdriver.Builder()
var __DEFAULT_IMG_WIDTH = '60%';
var __imgCount = 0;
var __returnGuideAutomator = "";

var __DefaultContext = true;
var GLOBAL = {};

var options = {
Expand Down Expand Up @@ -138,6 +138,7 @@ function takeScreenshot(width) {
*/
function takeScreenshotOf(cssSelector, crop, outline, width) {
var cssSelectors;
//Multiplos elementos
if(cssSelector.constructor === Array) {
cssSelectors = cssSelector;
cssSelector = cssSelectors[0];
Expand All @@ -154,6 +155,15 @@ function takeScreenshotOf(cssSelector, crop, outline, width) {
GD.driver.executeScript("arguments[0].style.outline = '" + options.outlineStyle + "'", el);
if(cssSelectors) {
cssSelectors.forEach(element => {

//Contexto Diferentes
if(element.constructor === Array) {
pageContext(element[1].toString());
element = element[0];
} else if(!__DefaultContext)
pageContext();
//Se não foi definido um contexto e ele está em outro contexto, volte para o default

GD.driver.findElement(GD.by.css(element)).then(function(el1) {
GD.driver.executeScript("arguments[0].style.outline = '" + options.outlineStyle + "'", el1);
});
Expand Down Expand Up @@ -274,10 +284,13 @@ function wait(cssSelector, timeOut) {
}

function pageContext(cssSelector) {
if(!cssSelector || cssSelector.toString().toLowerCase() === 'default')
if(!cssSelector || cssSelector.toString().toLowerCase() === 'default') {
GD.driver.switchTo().defaultContent();
else
__DefaultContext = true;
} else {
GD.driver.switchTo().frame(GD.driver.findElement(GD.by.css(cssSelector)));
__DefaultContext = false;
}
}

function quit() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "guide-automator",
"version": "2.2.0",
"version": "2.2.1",
"description": "User guide automator",
"preferGlobal": true,
"bin": {
Expand Down

0 comments on commit 37a019e

Please sign in to comment.