<commit_before>
import { E2EGlobal } from './E2EGlobal'


export class E2EApp {
    static titlePrefix = "4Minitz!";

    // Calls the server method to clean database and create fresh test users
    static resetMyApp (skipUsers) {
        try {
            server.call('e2e.resetMyApp', skipUsers);  // call meteor server method
        } catch (e) {
            console.log("Exception: "+e);
            console.log("Did you forget to run the server with '--settings settings-test-end2end.json'?");
        }
    };

    static isLoggedIn () {
        try {
            browser.waitForExist('#navbar-usermenu', 5000);         // browser = WebdriverIO instance
        } catch (e) {
            // give browser some time, on fresh login
            E2EGlobal.saveScreenshot('isLoggedIn_failed');
        }
        return browser.isExisting('#navbar-usermenu');
    };

    static logoutUser () {
        if (E2EApp.isLoggedIn()) {
            E2EGlobal.clickWithRetry('#navbar-usermenu');
            E2EGlobal.clickWithRetry('#navbar-signout');
            E2EGlobal.waitSomeTime();
        }
        E2EApp._currentlyLoggedInUser = "";
        expect(browser.getTitle()).to.equal(E2EApp.titlePrefix);
    };

    static loginLdapUserWithCredentials(username, password, autoLogout) {
        this.loginUserWithCredentials(username, password, autoLogout, '#tab_ldap');
    }

    static loginUserWithCredentials(username, password, autoLogout, tab) {
        if (autoLogout === undefined) {
            autoLogout = true;
        }

        if (tab === undefined) {
            tab = '#tab_standard';
        }

        if (autoLogout) {
            E2EApp.logoutUser();
        }
        try {
            browser.waitForVisible(tab, 5000);
            E2EGlobal.clickWithRetry(tab);

            let tabIsStandard = browser.isExisting('#at-field-username_and_email');
            let userWantsStandard = tab === '#tab_standard';
            let tabIsLdap = browser.isExisting('#id_ldapUsername');
            let userWantsLdap = tab === '#tab_ldap';

            browser.waitUntil(_ => (tabIsStandard && userWantsStandard) || (tabIsLdap && userWantsLdap), 5000);

            if (tabIsStandard) {
                E2EGlobal.setValueSafe('input[id="at-field-username_and_email"]', username);
                E2EGlobal.setValueSafe('input[id="at-field-password"]', password);
            }

            if (tabIsLdap) {
                E2EGlobal.setValueSafe('input[id="id_ldapUsername"]', username);
                E2EGlobal.setValueSafe('input[id="id_ldapPassword"]', password);
            }

            browser.keys(['Enter']);

            browser.waitUntil(_ => {
                const userMenuExists = browser.isExisting('#navbar-usermenu'),
                    loginErrorAlertExists = browser.isExisting('.alert.alert-danger');

                return userMenuExists || loginErrorAlertExists;
            }, 8000);

            if (browser.isExisting('.alert.alert-danger')) {
                throw new Error ("Unknown user or wrong password.")
            }
            E2EApp.isLoggedIn();
            E2EApp._currentlyLoggedInUser = username;
        } catch (e) {
            E2EGlobal.saveScreenshot('loginUserWithCredentials_failed');
            throw new Error (`Login failed for user ${username} with ${password}\nwith ${e}`);
        }
    }

    /**
     * Logout current user, if necessary, then login a specific test user
     * @param indexOrUsername of test user from setting. optional.
     * @param autoLogout perform logout before login the test user. optional.
     */
    static loginUser (indexOrUsername, autoLogout) {
        if (!indexOrUsername) {<commit_msg>Check alert-error boxes more thoroughly<commit_after>
import { E2EGlobal } from './E2EGlobal'


export class E2EApp {
    static titlePrefix = "4Minitz!";

    // Calls the server method to clean database and create fresh test users
    static resetMyApp (skipUsers) {
        try {
            server.call('e2e.resetMyApp', skipUsers);  // call meteor server method
        } catch (e) {
            console.log("Exception: "+e);
            console.log("Did you forget to run the server with '--settings settings-test-end2end.json'?");
        }
    };

    static isLoggedIn () {
        try {
            browser.waitForExist('#navbar-usermenu', 5000);         // browser = WebdriverIO instance
        } catch (e) {
            // give browser some time, on fresh login
            E2EGlobal.saveScreenshot('isLoggedIn_failed');
        }
        return browser.isExisting('#navbar-usermenu');
    };

    static logoutUser () {
        if (E2EApp.isLoggedIn()) {
            E2EGlobal.clickWithRetry('#navbar-usermenu');
            E2EGlobal.clickWithRetry('#navbar-signout');
            E2EGlobal.waitSomeTime();
        }
        E2EApp._currentlyLoggedInUser = "";
        expect(browser.getTitle()).to.equal(E2EApp.titlePrefix);
    };

    static loginLdapUserWithCredentials(username, password, autoLogout) {
        this.loginUserWithCredentials(username, password, autoLogout, '#tab_ldap');
    }

    static loginUserWithCredentials(username, password, autoLogout = true, tab = '#tab_standard') {
        if (autoLogout) {
            E2EApp.logoutUser();
        }

        try {
            browser.waitForVisible(tab, 5000);
            E2EGlobal.clickWithRetry(tab);

            let tabIsStandard = browser.isExisting('#at-field-username_and_email');
            let userWantsStandard = tab === '#tab_standard';
            let tabIsLdap = browser.isExisting('#id_ldapUsername');
            let userWantsLdap = tab === '#tab_ldap';

            browser.waitUntil(_ => (tabIsStandard && userWantsStandard) || (tabIsLdap && userWantsLdap), 5000);

            if (tabIsStandard) {
                E2EGlobal.setValueSafe('input[id="at-field-username_and_email"]', username);
                E2EGlobal.setValueSafe('input[id="at-field-password"]', password);
            }

            if (tabIsLdap) {
                E2EGlobal.setValueSafe('input[id="id_ldapUsername"]', username);
                E2EGlobal.setValueSafe('input[id="id_ldapPassword"]', password);
            }

            browser.keys(['Enter']);

            browser.waitUntil(_ => {
                const userMenuExists = browser.isExisting('#navbar-usermenu'),
                    loginErrorAlertExists = browser.isExisting('.alert.alert-danger');

                return userMenuExists || loginErrorAlertExists;
            }, 8000);

            if (browser.isExisting('.alert.alert-danger') &&
                browser.getHTML('.alert.alert-danger').includes('403')) {
                throw new Error ("Unknown user or wrong password.")
            }
            E2EApp.isLoggedIn();
            E2EApp._currentlyLoggedInUser = username;
        } catch (e) {
            E2EGlobal.saveScreenshot('loginUserWithCredentials_failed');
            throw new Error (`Login failed for user ${username} with ${password}\nwith ${e}`);
        }
    }

    /**
     * Logout current user, if necessary, then login a specific test user
     * @param indexOrUsername of test user from setting. optional.
     * @param autoLogout perform logout before login the test user. optional.
     */
    static loginUser (indexOrUsername, autoLogout) {
        if (!indexOrUsername) {
{'fraction_non_alphanumeric': 0.11807917290164603, 'fraction_numerical': 0.010746837165011564, 'mean_word_length': 2.2359154929577465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1533405', 'n_tokens_mistral': 2132, 'n_tokens_neox': 2052, 'n_words': 419}