Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@qawolf/browser

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qawolf/browser - npm Package Compare versions

Comparing version 0.4.4 to 0.5.0

lib/keyboard.d.ts

6

lib/actions.d.ts
import { ScrollValue } from "@qawolf/types";
import { ElementHandle } from "puppeteer";
import { ElementHandle, Page } from "puppeteer";
export declare const click: (element: ElementHandle<Element>) => Promise<void>;
export declare const input: (elementHandle: ElementHandle<Element>, value?: string | null | undefined) => Promise<void>;
export declare const focusClear: (elementHandle: ElementHandle<Element>) => Promise<void>;
export declare const scroll: (elementHandle: ElementHandle<Element>, value: ScrollValue, timeoutMs?: number) => Promise<void>;
export declare const select: (elementHandle: ElementHandle<Element>, value: string | null) => Promise<void>;
export declare const type: (page: Page, value: string) => Promise<void>;

@@ -12,23 +12,24 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = require("@qawolf/logger");
const web_1 = require("@qawolf/web");
const keyboard_1 = require("./keyboard");
exports.click = (element) => __awaiter(void 0, void 0, void 0, function* () {
logger_1.logger.verbose("actions.click");
yield element.click();
});
exports.input = (elementHandle, value) => __awaiter(void 0, void 0, void 0, function* () {
const strValue = value || "";
const handleProperty = yield elementHandle.getProperty("tagName");
const tagName = yield handleProperty.jsonValue();
if (tagName.toLowerCase() === "select") {
yield elementHandle.select(strValue);
exports.focusClear = (elementHandle) => __awaiter(void 0, void 0, void 0, function* () {
logger_1.logger.verbose("actions.focusClear");
yield elementHandle.focus();
const currentValue = yield elementHandle.evaluate((element) => {
if (element.isContentEditable)
return element.innerText;
return element.value;
});
if (currentValue) {
yield elementHandle.evaluate(() => document.execCommand("selectall", false, ""));
yield elementHandle.press("Backspace");
}
else {
yield elementHandle.focus();
const currentValue = yield elementHandle.evaluate(element => element.value);
if (currentValue) {
yield elementHandle.evaluate(() => document.execCommand("selectall", false, ""));
yield elementHandle.press("Backspace");
}
yield elementHandle.type(strValue);
}
});
exports.scroll = (elementHandle, value, timeoutMs = 10000) => __awaiter(void 0, void 0, void 0, function* () {
logger_1.logger.verbose("actions.scroll");
yield elementHandle.evaluate((element, value, timeoutMs) => {

@@ -39,2 +40,20 @@ const qawolf = window.qawolf;

});
exports.select = (elementHandle, value) => __awaiter(void 0, void 0, void 0, function* () {
logger_1.logger.verbose("actions.select");
yield elementHandle.select(value || "");
});
exports.type = (page, value) => __awaiter(void 0, void 0, void 0, function* () {
logger_1.logger.verbose("actions.type");
for (const stroke of keyboard_1.convertStringToStrokes(value)) {
if (stroke.prefix === "↓") {
logger_1.logger.debug(`keyboard.down("${stroke.code}")`);
yield page.keyboard.down(stroke.code);
}
else {
logger_1.logger.debug(`keyboard.up("${stroke.code}")`);
yield page.keyboard.up(stroke.code);
}
yield web_1.sleep(50);
}
});
//# sourceMappingURL=actions.js.map
export * from "./actions";
export * from "./Browser";
export * from "./find";
export * from "./keyboard";
export * from "./retry";

@@ -9,3 +9,4 @@ "use strict";

__export(require("./find"));
__export(require("./keyboard"));
__export(require("./retry"));
//# sourceMappingURL=index.js.map

@@ -123,9 +123,17 @@ "use strict";

exports.QAWolfPage = QAWolfPage;
const formatJsHandle = (jsHandle) => jsHandle.executionContext().evaluate(obj => {
return obj instanceof HTMLElement
?
obj.outerHTML.replace(/(\r\n|\n|\r)/gm, "").substring(0, 100)
:
JSON.stringify(obj);
}, jsHandle);
const formatJsHandle = (jsHandle) => {
const element = jsHandle.asElement();
return jsHandle.executionContext().evaluate((obj, element) => {
try {
if (element) {
const qawolf = window.qawolf;
return qawolf.xpath.getXpath(element);
}
return JSON.stringify(obj);
}
catch (e) {
return obj.toString();
}
}, jsHandle, element);
};
//# sourceMappingURL=QAWolfPage.js.map
{
"name": "@qawolf/browser",
"description": "qawolf browser manager",
"version": "0.4.4",
"version": "0.5.0",
"license": "BSD-3.0",

@@ -27,6 +27,6 @@ "main": "./lib/index.js",

"dependencies": {
"@qawolf/config": "^0.4.4",
"@qawolf/logger": "^0.4.4",
"@qawolf/types": "^0.4.4",
"@qawolf/web": "^0.4.4",
"@qawolf/config": "^0.5.0",
"@qawolf/logger": "^0.5.0",
"@qawolf/types": "^0.5.0",
"@qawolf/web": "^0.5.0",
"fs-extra": "^8.1.0",

@@ -41,3 +41,3 @@ "lodash": "^4.17.15",

},
"gitHead": "46e1d99d06c223f1fa8281e957856da4a7c152f1"
"gitHead": "ab0de314c354a4adb5889edd2a35a98ea7708798"
}

@@ -1,36 +0,33 @@

import { QAWolfWeb } from "@qawolf/web";
import { logger } from "@qawolf/logger";
import { ScrollValue } from "@qawolf/types";
import { ElementHandle } from "puppeteer";
import { QAWolfWeb, sleep } from "@qawolf/web";
import { ElementHandle, Page } from "puppeteer";
import { convertStringToStrokes } from "./keyboard";
export const click = async (element: ElementHandle): Promise<void> => {
logger.verbose("actions.click");
await element.click();
};
export const input = async (
elementHandle: ElementHandle,
value?: string | null
export const focusClear = async (
elementHandle: ElementHandle
): Promise<void> => {
const strValue = value || "";
const handleProperty = await elementHandle.getProperty("tagName");
const tagName = await handleProperty.jsonValue();
logger.verbose("actions.focusClear");
await elementHandle.focus();
if (tagName.toLowerCase() === "select") {
await elementHandle.select(strValue);
} else {
await elementHandle.focus();
const currentValue = await elementHandle.evaluate((element: HTMLElement) => {
if (element.isContentEditable) return element.innerText;
const currentValue = await elementHandle.evaluate(
element => (element as HTMLInputElement).value
return (element as HTMLInputElement).value;
});
if (currentValue) {
// Select all so we replace the text
// from https://github.com/GoogleChrome/puppeteer/issues/1313#issuecomment-471732011
// We do this instead of setting the value directly since that does not mimic user behavior.
// Ex. Some sites might rely on an isTrusted change event which we cannot simulate.
await elementHandle.evaluate(() =>
document.execCommand("selectall", false, "")
);
if (currentValue) {
// select all so we replace the text
// from https://github.com/GoogleChrome/puppeteer/issues/1313#issuecomment-471732011
await elementHandle.evaluate(() =>
document.execCommand("selectall", false, "")
);
await elementHandle.press("Backspace");
}
await elementHandle.type(strValue);
await elementHandle.press("Backspace");
}

@@ -44,2 +41,3 @@ };

): Promise<void> => {
logger.verbose("actions.scroll");
await elementHandle.evaluate(

@@ -54,1 +52,28 @@ (element, value, timeoutMs) => {

};
export const select = async (
elementHandle: ElementHandle,
value: string | null
): Promise<void> => {
logger.verbose("actions.select");
await elementHandle.select(value || "");
};
export const type = async (page: Page, value: string): Promise<void> => {
logger.verbose("actions.type");
// logging the keyboard codes below will leak secrets
// which is why we have it hidden behind the DEBUG flag
// since we default logs to VERBOSE
for (const stroke of convertStringToStrokes(value)) {
if (stroke.prefix === "↓") {
logger.debug(`keyboard.down("${stroke.code}")`);
await page.keyboard.down(stroke.code);
} else {
logger.debug(`keyboard.up("${stroke.code}")`);
await page.keyboard.up(stroke.code);
}
await sleep(50);
}
};
export * from "./actions";
export * from "./Browser";
export * from "./find";
export * from "./keyboard";
export * from "./retry";
import { logger } from "@qawolf/logger";
import { Event } from "@qawolf/types";
import { QAWolfWeb } from "@qawolf/web";
import { readFileSync, outputFile } from "fs-extra";

@@ -110,2 +111,3 @@ import { compile } from "handlebars";

const url = this._page.url().substring(0, 40);
try {

@@ -123,2 +125,3 @@ const args = await Promise.all(

// ex. when the context is destroyed due to page navigation
// XXX this is why we need to change logging to be intercepted on the client
logger.verbose(`${url}: ${msg.text()}`);

@@ -171,10 +174,22 @@ }

const formatJsHandle = (jsHandle: JSHandle) =>
// format a jsHandle to a string so we can log it
jsHandle.executionContext().evaluate(obj => {
return obj instanceof HTMLElement
? // log html elements by their html, without newlines
obj.outerHTML.replace(/(\r\n|\n|\r)/gm, "").substring(0, 100)
: // log other objects by their JSON string
JSON.stringify(obj);
}, jsHandle);
const formatJsHandle = (jsHandle: JSHandle) => {
const element = jsHandle.asElement();
return jsHandle.executionContext().evaluate(
(obj, element) => {
try {
if (element) {
// log elements by their xpath
const qawolf: QAWolfWeb = (window as any).qawolf;
return qawolf.xpath.getXpath(element);
}
return JSON.stringify(obj);
} catch (e) {
return obj.toString();
}
},
jsHandle,
element
);
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc