Skip to content

Commit

Permalink
fix(basic.gblib): SCREENSHOT keyword.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Sep 12, 2022
1 parent c3eb1dd commit 0f1ee22
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 34 deletions.
181 changes: 180 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"prism-media": "1.3.1",
"public-ip": "4.0.4",
"puppeteer": "13.7.0",
"puppeteer-extra-plugin-stealth": "2.4.5",
"qrcode": "^1.5.0",
"qrcode-terminal": "0.12.0",
"readline": "1.3.0",
Expand Down Expand Up @@ -257,4 +258,4 @@
"post-merge": []
}
}
}
}
8 changes: 3 additions & 5 deletions packages/basic.gblib/services/ChartServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@

'use strict';

const urlJoin = require('url-join');
const DateDiff = require('date-diff');
const puppeteer = require('puppeteer');
const Path = require('path');
import bb from "billboard.js";
const pluginStealth = require('puppeteer-extra-plugin-stealth');


export class ChartServices {

Expand All @@ -48,7 +46,7 @@ export class ChartServices {
public static async screenshot(args, path) {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();

// load billboard.js assets from CDN.
await page.addStyleTag({ url: "https://cdn.jsdelivr.net/npm/billboard.js/dist/theme/datalab.min.css" });
await page.addScriptTag({ url: "https://cdn.jsdelivr.net/npm/billboard.js/dist/billboard.pkgd.min.js" });
Expand Down
47 changes: 40 additions & 7 deletions packages/basic.gblib/services/DialogKeywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ import { GBMinService } from '../../core.gbapp/services/GBMinService';
import { HubSpotServices } from '../../hubspot.gblib/services/HubSpotServices';
import { WhatsappDirectLine } from '../../whatsapp.gblib/services/WhatsappDirectLine';
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
import { GBVMService } from './GBVMService';
const DateDiff = require('date-diff');
const puppeteer = require('puppeteer');
const pluginStealth = require('puppeteer-extra-plugin-stealth');


const Path = require('path');
const sgMail = require('@sendgrid/mail');
const PizZip = require("pizzip");
const Docxtemplater = require("docxtemplater");
var mammoth = require("mammoth");
const qrcode = require('qrcode');

Expand Down Expand Up @@ -318,6 +318,26 @@ export class DialogKeywords {
}
}

/**
* Press ENTER in a web page, useful for logins.
*
* @example PRESS ENTER ON page
*/
public async pressKey(step, page, char, frame) {
GBLog.info(`BASIC: Web Automation PRESS ${char} ON element: ${frame}.`);
if (char.toLowerCase() === "enter") {
char = '\n';
}
if (frame) {
await page.waitForSelector(frame)
let frameHandle = await page.$(frame);
const f = await frameHandle.contentFrame();
await f.keyboard.press(char);
}
else {
await page.keyboard.press(char);
}
}

public async linkByText(step, page, text, index) {
GBLog.info(`BASIC: Web Automation CLICK LINK TEXT: ${text} ${index}.`);
Expand All @@ -335,10 +355,23 @@ export class DialogKeywords {
*
* @example file = SCREENSHOT page
*/
public async screenshot(step, page, idOrName, localName) {
public async screenshot(step, page, idOrName) {
GBLog.info(`BASIC: Web Automation SCREENSHOT ${idOrName}.`);
const e = await this.getBySelector(page, idOrName);
await e.screenshot({ path: localName });

const gbaiName = `${this.min.botId}.gbai`;
const localName = Path.join('work', gbaiName, 'cache', `screen-${GBAdminService.getRndReadableIdentifier()}.jpg`);

await page.screenshot({ path: localName });

const url = urlJoin(
GBServer.globals.publicAddress,
this.min.botId,
'cache',
Path.basename(localName)
);
GBLog.info(`BASIC: WebAutomation: Screenshot captured at ${url}.`);

return url;
}


Expand Down Expand Up @@ -936,7 +969,7 @@ export class DialogKeywords {
if (page) {
const gbaiName = `${this.min.botId}.gbai`;
const localName = Path.join('work', gbaiName, 'cache', `img${GBAdminService.getRndReadableIdentifier()}.jpg`);
await filename.screenshot({ path: localName });
await filename.screenshot({ path: localName, fullPage: true });

const url = urlJoin(
GBServer.globals.publicAddress,
Expand Down

0 comments on commit 0f1ee22

Please sign in to comment.