<commit_before>import fs from "fs-promise";
import path from "path";

import { By, until } from "selenium-webdriver";

const DEFAULT_TIMEOUT = 5000;

const delay = (timeout = 0) => new Promise((resolve) => setTimeout(resolve, timeout));

export const findElement = (driver, selector) =>
    // consider looking into a better test reporter
    // default jasmine reporter leaves much to be desired
    console.log(`\nlooking for element: ${selector}`) ||
    driver.findElement(By.css(selector));

export const waitForElement = async (driver, selector, timeout = DEFAULT_TIMEOUT) =>
    console.log(`\nwaiting for element: ${selector}`) ||
    await driver.wait(until.elementLocated(By.css(selector)), timeout);

export const waitForElementRemoved = async (driver, selector, timeout = DEFAULT_TIMEOUT) => {
    console.log(`\nwaiting for element to be removed: ${selector}`);
    try {
        const element = findElement(driver, selector);
        await driver.wait(until.stalenessOf(element), timeout);
    }
    catch (error) {
        return;
    }
};

export const waitForElementText = async (driver, selector, text, timeout = DEFAULT_TIMEOUT) => {
    console.log(`\nwaiting for element text${text ? ` to equal ${text}` : ''}: ${selector}`);
    const element = await waitForElement(driver, selector, timeout);
    const elementText = await element.getText();

    if (!text || text === elementText) {<commit_msg>Added workaround for uncatchable findElement errors<commit_after>import fs from "fs-promise";
import path from "path";

import { By, until } from "selenium-webdriver";

const DEFAULT_TIMEOUT = 5000;

const delay = (timeout = 0) => new Promise((resolve) => setTimeout(resolve, timeout));

export const findElement = (driver, selector) =>
    // consider looking into a better test reporter
    // default jasmine reporter leaves much to be desired
    console.log(`\nlooking for element: ${selector}`) ||
    driver.findElement(By.css(selector));

export const waitForElement = async (driver, selector, timeout = DEFAULT_TIMEOUT) =>
    console.log(`\nwaiting for element: ${selector}`) ||
    await driver.wait(until.elementLocated(By.css(selector)), timeout);

export const waitForElementRemoved = async (driver, selector, timeout = DEFAULT_TIMEOUT) => {
    console.log(`\nwaiting for element to be removed: ${selector}`);
    // workaround for not being able to catch NoSuchElementError from findElement
    const element = driver.findElements(By.css(selector))[0];
    if (!element) {
        return;
    }
    await driver.wait(until.stalenessOf(element), timeout);
};

export const waitForElementText = async (driver, selector, text, timeout = DEFAULT_TIMEOUT) => {
    console.log(`\nwaiting for element text${text ? ` to equal ${text}` : ''}: ${selector}`);
    const element = await waitForElement(driver, selector, timeout);
    const elementText = await element.getText();

    if (!text || text === elementText) {
{'fraction_non_alphanumeric': 0.13115868161739722, 'fraction_numerical': 0.0037376826367652057, 'mean_word_length': 4.343012704174229, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1345885', 'n_tokens_mistral': 816, 'n_tokens_neox': 821, 'n_words': 255}