UNPKG

wdio-ui5-service

Version:

WebdriverIO plugin for testing UI5 browser-based apps

33 lines 1.49 kB
import Authenticator from "./Authenticator.js"; class BasicAuthenticator extends Authenticator { 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()); const basicAuthUrls = matches[1] + username + ":" + password + "@" + matches[2]; if (!matches[1] || !matches[2]) { throw new Error(`Invalid basicAuthUrls config: ${basicAuthUrlsConfig}`); } await this.browserInstance.url(basicAuthUrls); } } } export default BasicAuthenticator; //# sourceMappingURL=BasicAuthenticator.js.map