UNPKG

@progress/kendo-e2e

Version:

Kendo UI end-to-end test utilities.

56 lines 3.17 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.snapshotMarkup = snapshotMarkup; const fs_1 = require("fs"); const js_beautify_1 = require("js-beautify"); const jsdom_1 = require("jsdom"); const selenium_webdriver_1 = require("selenium-webdriver"); const filter_attributes_1 = require("./filter-attributes"); const filter_comment_nodes_1 = require("./filter-comment-nodes"); const html_template_1 = require("./html-template"); const visual_test_template_1 = require("./visual-test-template"); function snapshotMarkup(driver, selector, outputPath, options) { return __awaiter(this, void 0, void 0, function* () { var _a; const source = yield driver.findElement(selenium_webdriver_1.By.css(selector)).getAttribute('outerHTML'); const doc = new jsdom_1.JSDOM(source).window.document; const root = doc.querySelector(selector); if (!root) { throw new Error(`No element with selector ${selector} found.`); } if (!(options === null || options === void 0 ? void 0 : options.preserveAttributes)) { (0, filter_attributes_1.filterAttributes)(doc, root); } if (!(options === null || options === void 0 ? void 0 : options.preserveCommentNodes)) { (0, filter_comment_nodes_1.filterCommentNodes)(doc, root); } let output = root.outerHTML; const template = (_a = options === null || options === void 0 ? void 0 : options.template) !== null && _a !== void 0 ? _a : 'empty'; switch (template) { case 'visual-test': output = (0, visual_test_template_1.visualTestTemplate)(output, options === null || options === void 0 ? void 0 : options.data); break; case 'html5': output = (0, html_template_1.htmlTemplate)(output, options === null || options === void 0 ? void 0 : options.data); break; default: if (typeof template === 'function') { output = template(output, options === null || options === void 0 ? void 0 : options.data); } break; } const beautifyOptions = Object.assign({ indent_size: 4 }, options === null || options === void 0 ? void 0 : options.beautifyOptions); output = (0, js_beautify_1.html)(output, beautifyOptions); (0, fs_1.writeFileSync)(outputPath, output); }); } //# sourceMappingURL=snapshot-markup.js.map