UNPKG

wdio-ui5-service

Version:

WebdriverIO plugin for testing UI5 browser-based apps

38 lines 1.78 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Authenticator_js_1 = __importDefault(require("./Authenticator.js")); class BasicAuthenticator extends Authenticator_js_1.default { options; baseUrl; constructor(options, browserInstanceName, baseUrl) { super(browserInstanceName); this.options = options; this.baseUrl = baseUrl; } async login() { const basicAuthUrls = this.options.basicAuthUrls || [this.baseUrl]; await this.basicAuthLogin(basicAuthUrls); this.setIsLoggedIn(true); // trick 17 ;) // the preload flag of the OData models tries to load the $metadata to early for our authenticators. // We have to reload the application to "force" the application to reload the requests after we are authenticated. await this.browserInstance.url(this.baseUrl); } async basicAuthLogin(basicAuthUrls) { for (const basicAuthUrlsConfig of basicAuthUrls) { const matches = basicAuthUrlsConfig.match(/(\w*:?\/\/)(.+)/); const username = encodeURIComponent(this.getUsername() || ""); const password = encodeURIComponent(this.getPassword() || ""); if (!matches || !matches[1] || !matches[2]) { throw new Error(`Invalid basicAuthUrls config: ${basicAuthUrlsConfig}`); } const basicAuthUrls = matches[1] + username + ":" + password + "@" + matches[2]; await this.browserInstance.url(basicAuthUrls); } } } exports.default = BasicAuthenticator; //# sourceMappingURL=BasicAuthenticator.js.map