<commit_before>import pytest
from selenium import webdriver
import os
from selenium.webdriver.support.select import Select
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import SeleniumTest
import time
from random import randint

CHROME_CACHE = []
CHROME_INSTANCES = []

class SeleniumTestClass:

    def _to_param(self, name, provider, closer):
        return pytest.param(provider, closer, id=name)

    def pytest_generate_tests(self, metafunc):
        if 'TRAVIS_INTEGRATION' in os.environ:
            chrome = [self._to_param('Firefox headless', _launch_headles_firefox, close_driver)]
        else:
            chrome = [self._to_param('Firefox', _launch_head_firefox, close_driver)]

        metafunc.parametrize(argnames=['get_driver', 'close_driver'], argvalues=chrome, scope="module")

def close_driver(driver):
    if driver in SeleniumTest.CHROME_INSTANCES:
        SeleniumTest.CHROME_INSTANCES.remove(driver)

    #if 'TRAVIS_INTEGRATION' in os.environ:
    #    SeleniumTest.CHROME_CACHE.append(driver)
    #    return
    driver.close()

def _launch_head_firefox():
    firefox_options = Options()
    firefox_options.add_argument("--window-size=1920,1080")
    return webdriver.Firefox(firefox_options=firefox_options)

def _launch_headles_firefox():
    if SeleniumTest.CHROME_CACHE:
        browser = SeleniumTest.CHROME_CACHE[0]
        SeleniumTest.CHROME_CACHE.remove(browser)
        SeleniumTest.CHROME_INSTANCES.append(browser)
        return browser

    firefox_options = Options()
    firefox_options.add_argument("-headless")
    firefox_options.add_argument("--window-size=1920,1080")

    profile = FirefoxProfile()
    profile.set_preference('browser.cache.disk.enable', False)
    profile.set_preference('browser.cache.memory.enable', False)
    profile.set_preference('browser.cache.offline.enable', False)
    profile.set_preference('network.cookie.cookieBehavior', 2)

    browser = webdriver.Firefox(firefox_options=firefox_options, firefox_profile=profile)
    SeleniumTest.CHROME_INSTANCES.append(browser)
    return browser

def enter_test_mode(driver):
    driver.get('http://localhost:5000/production/testmode')


def fill_element(driver, elementname, content):
    elem = driver.find_element_by_name(elementname)
    elem.clear()
    elem.send_keys(content)

def define_kategorie(driver, kategorie_name):
    driver.get('http://127.0.0.1:5000/configuration/')
    fill_element(driver, 'neue_kategorie', kategorie_name)
    button = driver.find_element_by_id('add_kategorie')
    button.click()

def select_option(driver, option_id, item):
    el = driver.find_element_by_id(option_id)
    for option in el.find_elements_by_tag_name('option'):
        if option.text == item:
            option.click()  # select() in earlier versions of webdriver
            break

def get_options(driver, option_id):
    el = driver.find_element_by_id(option_id)
    result = []
    for option in el.find_elements_by_tag_name('option'):
        result.append(option.text)
    return result

def get_selected_option(driver, option_id):
    select = Select(driver.find_element_by_id(option_id))
    selected_option = select.first_selected_option
    return selected_option.text

def pagename(driver):
    return driver.find_element_by_id('pagetitle').get_attribute('innerHTML')

def generate_unique_name():
    return 'u' + str(time.time()).replace('.', '') + str(randint(0,10000))

def login(driver, email, passwd):
    driver.get('http://localhost/login.php')
    fill_element(driver, 'email', email)
    fill_element(driver, 'password', <PASSWORD>)
    driver.find_element_by_id('btn_login').click()
    assert driver.title == 'BudgetButlerWeb - Dashboard'


<commit_msg>added wait form precence on login to fix seleniums slow timeouts<commit_after>import pytest
from selenium import webdriver
import os
from selenium.webdriver.support.select import Select
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

import SeleniumTest
import time
from random import randint

CHROME_CACHE = []
CHROME_INSTANCES = []

class SeleniumTestClass:

    def _to_param(self, name, provider, closer):
        return pytest.param(provider, closer, id=name)

    def pytest_generate_tests(self, metafunc):
        if 'TRAVIS_INTEGRATION' in os.environ:
            chrome = [self._to_param('Firefox headless', _launch_headles_firefox, close_driver)]
        else:
            chrome = [self._to_param('Firefox', _launch_head_firefox, close_driver)]

        metafunc.parametrize(argnames=['get_driver', 'close_driver'], argvalues=chrome, scope="module")

def close_driver(driver):
    if driver in SeleniumTest.CHROME_INSTANCES:
        SeleniumTest.CHROME_INSTANCES.remove(driver)

    #if 'TRAVIS_INTEGRATION' in os.environ:
    #    SeleniumTest.CHROME_CACHE.append(driver)
    #    return
    driver.close()

def _launch_head_firefox():
    firefox_options = Options()
    firefox_options.add_argument("--window-size=1920,1080")
    return webdriver.Firefox(firefox_options=firefox_options)

def _launch_headles_firefox():
    if SeleniumTest.CHROME_CACHE:
        browser = SeleniumTest.CHROME_CACHE[0]
        SeleniumTest.CHROME_CACHE.remove(browser)
        SeleniumTest.CHROME_INSTANCES.append(browser)
        return browser

    firefox_options = Options()
    firefox_options.add_argument("-headless")
    firefox_options.add_argument("--window-size=1920,1080")

    profile = FirefoxProfile()
    profile.set_preference('browser.cache.disk.enable', False)
    profile.set_preference('browser.cache.memory.enable', False)
    profile.set_preference('browser.cache.offline.enable', False)
    profile.set_preference('network.cookie.cookieBehavior', 2)

    browser = webdriver.Firefox(firefox_options=firefox_options, firefox_profile=profile)
    SeleniumTest.CHROME_INSTANCES.append(browser)
    return browser

def enter_test_mode(driver):
    driver.get('http://localhost:5000/production/testmode')


def fill_element(driver, elementname, content):
    elem = driver.find_element_by_name(elementname)
    elem.clear()
    elem.send_keys(content)

def define_kategorie(driver, kategorie_name):
    driver.get('http://127.0.0.1:5000/configuration/')
    fill_element(driver, 'neue_kategorie', kategorie_name)
    button = driver.find_element_by_id('add_kategorie')
    button.click()

def select_option(driver, option_id, item):
    el = driver.find_element_by_id(option_id)
    for option in el.find_elements_by_tag_name('option'):
        if option.text == item:
            option.click()  # select() in earlier versions of webdriver
            break

def get_options(driver, option_id):
    el = driver.find_element_by_id(option_id)
    result = []
    for option in el.find_elements_by_tag_name('option'):
        result.append(option.text)
    return result

def get_selected_option(driver, option_id):
    select = Select(driver.find_element_by_id(option_id))
    selected_option = select.first_selected_option
    return selected_option.text

def pagename(driver):
    return driver.find_element_by_id('pagetitle').get_attribute('innerHTML')

def generate_unique_name():
    return 'u' + str(time.time()).replace('.', '') + str(randint(0,10000))


def wait_for_dashboard(driver):
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'fullsizecontent')))

def login(driver, email, passwd):
    driver.get('http://localhost/login.php')
    fill_element(driver, 'email', email)
    fill_element(driver, 'password', <PASSWORD>)
    driver.find_element_by_id('btn_login').click()
    wait_for_dashboard(driver)
    assert driver.title == 'BudgetButlerWeb - Dashboard'



{'fraction_non_alphanumeric': 0.1062169645104455, 'fraction_numerical': 0.009816259753335011, 'mean_word_length': 4.616254416961131, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1662585', 'n_tokens_mistral': 2627, 'n_tokens_neox': 2509, 'n_words': 436}