UNPKG

@serenity-js/protractor

Version:

Adapter that integrates @serenity-js/web with Protractor, enabling Serenity/JS reporting and using the Screenplay Pattern to write end-to-end test scenarios

74 lines 3.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProtractorFrameworkAdapter = void 0; const core_1 = require("@serenity-js/core"); const rest_1 = require("@serenity-js/rest"); const protractor_1 = require("protractor"); const objects_1 = require("tiny-types/lib/objects"); const screenplay_1 = require("../screenplay"); const browser_detector_1 = require("./browser-detector"); const reporter_1 = require("./reporter"); const runner_1 = require("./runner"); const deepmerge = require("deepmerge"); const querySelectorShadowDomPlugin = require('query-selector-shadow-dom/plugins/protractor'); // eslint-disable-line @typescript-eslint/no-var-requires /** * @private */ class ProtractorFrameworkAdapter { serenity; protractorRunner; detector; constructor(serenity, protractorRunner, detector) { this.serenity = serenity; this.protractorRunner = protractorRunner; this.detector = detector; } /** * @param specs * Paths to spec files */ run(specs) { if (!this.protractorRunner.plugins_?.pluginObjs?.some(plugin => plugin.name === querySelectorShadowDomPlugin.name)) { this.protractorRunner.plugins_?.pluginObjs?.push(querySelectorShadowDomPlugin); } const runner = this.detector.runnerFor(this.protractorRunner.getConfig()); const reporter = new reporter_1.ProtractorReporter(this.protractorRunner, runner.successThreshold()); const config = deepmerge(this.defaultConfig(), this.protractorRunner.getConfig(), { isMergeableObject: objects_1.isRecord, }); this.serenity.configure({ cueTimeout: config.serenity.cueTimeout, interactionTimeout: config.serenity.interactionTimeout, diffFormatter: config.serenity.diffFormatter ?? new core_1.AnsiDiffFormatter(), actors: config.serenity.actors || core_1.Cast.where(actor => actor.whoCan(screenplay_1.BrowseTheWebWithProtractor.using(protractor_1.protractor.browser), core_1.TakeNotes.usingAnEmptyNotepad(), rest_1.CallAnApi.using({ baseURL: config.baseUrl, }))), crew: [ browser_detector_1.BrowserDetector.with(browser_detector_1.StandardisedCapabilities.of(() => protractor_1.protractor.browser)), ...config.serenity.crew, reporter, ], }); return Promise.resolve() .then(() => this.protractorRunner.runTestPreparer(runner_1.TestRunnerDetector.protractorCliOptions())) .then(() => runner.load(specs)) .then(() => runner.run()) .then(() => (config.onComplete || noop)()) .then(() => reporter.report()); } defaultConfig() { return { serenity: { crew: [ core_1.ArtifactArchiver.storingArtifactsAt(process.cwd(), 'target/site/serenity'), ], }, }; } } exports.ProtractorFrameworkAdapter = ProtractorFrameworkAdapter; /** @private */ function noop() { // no-op } //# sourceMappingURL=ProtractorFrameworkAdapter.js.map