UNPKG

chrec-core

Version:

ChRec's core business logic and model for testing HTML locator robustness

68 lines (67 loc) 2.55 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const identififable_1 = require("./identififable"); const locator_test_result_1 = require("./locator-test-result"); var Method; (function (Method) { Method["CSS_SELECTOR_GENERATOR"] = "CssSelectorGenerator"; Method["FINDER"] = "Finder"; Method["GET_QUERY_SELECTOR"] = "GetQuerySelector"; Method["OPTIMAL_SELECT"] = "OptimalSelect"; Method["SELECTOR_QUERY"] = "SelectorQuery"; Method["ROBULA_PLUS"] = "RobulaPlus"; })(Method = exports.Method || (exports.Method = {})); class Locator extends identififable_1.Identificable { constructor(testResults, method, value, id) { super(id); this.testResults = testResults; this.method = method; this.value = value; } get replayable() { if (this.testResults.length > 0) { return this.testResults[0].replayable; } return false; } toJSON() { return Object.assign({ className: this.constructor.name }, this); } addTestResult(testResult) { this.testResults.push(testResult); } replayableTestResultCount() { let count = 0; for (const testResult of this.testResults) { if (testResult.replayable) { count++; } } return count; } test(driver) { return __awaiter(this, void 0, void 0, function* () { try { yield this.findElement(driver); this.addTestResult(new locator_test_result_1.LocatorTestResult(true)); } catch (error) { this.addTestResult(new locator_test_result_1.LocatorTestResult(false)); } }); } findElement(driver) { return __awaiter(this, void 0, void 0, function* () { return driver.findElement(this.toSeleniumLocator()); }); } } exports.Locator = Locator;