Skip to content

Commit

Permalink
new(basic.gblib): Command TEXT OF
Browse files Browse the repository at this point in the history
  • Loading branch information
phpussente committed May 9, 2023
1 parent b87a0c3 commit a03a7c7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
11 changes: 10 additions & 1 deletion packages/basic.gblib/services/KeywordsExpressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,11 +802,20 @@ export class KeywordsExpressions {
keywords[i++] = [
/^\s*(click link text)(\s*)(.*)/gim,
($0, $1, $2, $3) => {
const params = this.getParams('page,' + $3, ['text', 'index']);
const params = this.getParams($3, ['text', 'index']);
return `await wa.linkByText ({pid: pid, handle: page, ${params}})`;
}
];

keywords[i++] = [
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*(text of)(\s*)(.*)/gim,
($0, $1, $2, $3, $4) => {
const params = this.getParams($4, ['frameOrSelector', 'selector']);
return `
${$1} = await wa.getTextOf ({pid: pid, handle: page, ${params}})`;
}
];

keywords[i++] = [
/^\s*(click button)(\s*)(.*)/gim,
($0, $1, $2, $3) => {
Expand Down
37 changes: 29 additions & 8 deletions packages/basic.gblib/services/WebAutomationServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class WebAutomationServices {

return 4294967296 * (2097151 & h2) + (h1 >>> 0);
};

public async closeHandles({ pid }) {
const { min, user } = await DialogKeywords.getProcessInfo(pid);

Expand All @@ -98,13 +98,12 @@ export class WebAutomationServices {

public async openPage({ pid, handle, sessionKind, sessionName, url, username, password }) {
const { min, user } = await DialogKeywords.getProcessInfo(pid);
GBLogEx.info(min,`BASIC: Web Automation OPEN ${sessionName ? sessionName : ''} ${url}.`);
GBLogEx.info(min, `BASIC: Web Automation OPEN ${sessionName ? sessionName : ''} ${url}.`);

// Try to find an existing handle.

let session;
if (handle)
{
if (handle) {
session = GBServer.globals.webSessions[handle];
}
else if (sessionName) {
Expand All @@ -116,7 +115,7 @@ export class WebAutomationServices {
break;
}
}
}
}

let page;
if (session) {
Expand Down Expand Up @@ -198,7 +197,7 @@ export class WebAutomationServices {
public async getBySelector({ handle, selector, pid }) {
const page = WebAutomationServices.getPageByHandle(handle);
const { min, user } = await DialogKeywords.getProcessInfo(pid);
GBLogEx.info(min,`BASIC: Web Automation GET element: ${selector}.`);
GBLogEx.info(min, `BASIC: Web Automation GET element: ${selector}.`);
await page.waitForSelector(selector);
let elements = await page.$$(selector);
if (elements && elements.length > 1) {
Expand Down Expand Up @@ -316,7 +315,7 @@ export class WebAutomationServices {
await els[index - 1].click();
await this.debugStepWeb(pid, page);
}

public async clickButton({ pid, handle, text, index }) {
const page = WebAutomationServices.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation CLICK BUTTON: ${text} ${index}.`);
Expand Down Expand Up @@ -428,7 +427,7 @@ export class WebAutomationServices {
folder = folder.replace(/\\/gi, '/');

// Determines full path at source and destination.
const path = DialogKeywords.getGBAIPath(min.botId,`gbdrive`);
const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`);
const root = path;
const dstPath = urlJoin(root, folder, filename);

Expand Down Expand Up @@ -464,6 +463,28 @@ export class WebAutomationServices {
return null;
})
);

return results.find(Boolean);
}


public async getTextOf({ pid, handle, frameOrSelector, selector }) {
const page = WebAutomationServices.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation CLICK element: ${frameOrSelector}.`);
if (frameOrSelector) {
const result = await page.$eval(
frameOrSelector,
(ul) => {
let items = "";
for (let i = 0; i < ul.children.length; i++) {
items = `${items}${ul.children[i].textContent}\n`;
}
return items;
}
)
await this.debugStepWeb(pid, page);

return result;
}
}
}

0 comments on commit a03a7c7

Please sign in to comment.