UNPKG

wdio-ui5-service

Version:

WebdriverIO plugin for testing UI5 browser-based apps

63 lines 2.8 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 BTPAuthenticator extends Authenticator_js_1.default { disableBiometricAuth; idpDomain; idpDomainOpt; constructor(options, browserInstanceName) { super(browserInstanceName); this.usernameSelector = options.usernameSelector ?? "#j_username"; this.passwordSelector = options.passwordSelector ?? "#j_password"; this.submitSelector = options.submitSelector ?? "#logOnFormSubmit"; this.disableBiometricAuth = options.disableBiometricAuthentication ?? false; this.idpDomainOpt = options.idpDomain?.trim() ?? ""; if (this.disableBiometricAuth) { if (!options?.idpDomain) { throw new Error("idpDomain is required when disableBiometricAuthentication is set to `true` your wdi5.conf.(j|t)s"); } this.idpDomain = options.idpDomain; } } async disableBiometricAuthentication() { await this.browserInstance.setCookies({ name: "__HOST-skipPasswordlessAuthnDeviceConfig", value: "true", path: "/", secure: true }); } async login() { if (!(await this.getIsLoggedIn())) { if (this.idpDomainOpt) { const targetIdpEle = await this.browserInstance.$(`a[href*="idp=${this.idpDomainOpt}"]`); if (targetIdpEle.elementId) { targetIdpEle.click(); } } const usernameControl = await this.browserInstance.$(this.usernameSelector || ""); const passwordControl = await this.browserInstance.$(this.passwordSelector || ""); const submit = await this.browserInstance.$(this.submitSelector || ""); const wdi5Username = this.getUsername(); const wdi5Password = this.getPassword(); if (await passwordControl.isExisting()) { await usernameControl.setValue(wdi5Username); await passwordControl.setValue(wdi5Password); await submit.click(); } else { await usernameControl.setValue(wdi5Username); await submit.click(); const password = await this.browserInstance.$(this.passwordSelector || ""); await password.setValue(wdi5Password); await submit.click(); } this.setIsLoggedIn(true); } } } exports.default = BTPAuthenticator; //# sourceMappingURL=BTPAuthenticator.js.map