<commit_before># -*- coding: utf-8 -*-

import os

from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support.ui import WebDriverWait

SELENIUM_COMMAND_EXECUTOR = os.getenv("SELENIUM_COMMAND_EXECUTOR",
                                      "http://127.0.0.1:4444/wd/hub")
BASE_APP_URL = "http://localhost:3000"
DEFAULT_WAIT_TIMEOUT = 5


class Driver(WebDriver):
    nick = None

    def __init__(self, *args, **kwargs):
        if "nick" in kwargs and kwargs["nick"] is not None:
            self.nick = kwargs["nick"]
        del kwargs["nick"]
        super(Driver, self).__init__(*args, **kwargs)

    def openConversationWith(self, nick):
        """ Opens a new conversation window with the user matching the provided
            nick.

            Args:
            - nick: Peer username
        """
        self.switchToSidebar()
        nicks = self.waitForElements("ul.nav-list>li>a", visible=True)
        filter(lambda e: e.text == nick, nicks)[0].click()
        return self.switchToChatWindow()

    def clickElement(self, css_selector):
        """ Clicks the element matching the provided CSS selector."""
        self.waitForElement(css_selector, visible=True).click()

    def signin(self):
        """ Signs the user in."""
        if not self.nick:
            raise RuntimeError("No nick provided")
        self.switchToSidebar()
        self.add_cookie({"name": "test email", "value": self.nick})
        self.clickElement("#signin")
        # Ensure we've completed logging in before proceeding
        self.waitForElement("#signout", visible=True)
        return self

    def signout(self):
        """Signs the user out."""
        self.switchToSidebar()
        self.clickElement('#signout button')
        return self

    def startCall(self, video):
        """ Starts a new call.

            Args:
            - video: True for video, else audio only
        """
        self.clickElement(".btn-video>a" if video else ".btn-audio>a")

    def restartCall(self):
        """ Restarts a call. For use when the call is timed out. """<commit_msg>Try to fix an intermittent failure in signing in by waiting until we've loaded the page before adding cookies<commit_after># -*- coding: utf-8 -*-

import os

from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support.ui import WebDriverWait

SELENIUM_COMMAND_EXECUTOR = os.getenv("SELENIUM_COMMAND_EXECUTOR",
                                      "http://127.0.0.1:4444/wd/hub")
BASE_APP_URL = "http://localhost:3000"
DEFAULT_WAIT_TIMEOUT = 5


class Driver(WebDriver):
    nick = None

    def __init__(self, *args, **kwargs):
        if "nick" in kwargs and kwargs["nick"] is not None:
            self.nick = kwargs["nick"]
        del kwargs["nick"]
        super(Driver, self).__init__(*args, **kwargs)

    def openConversationWith(self, nick):
        """ Opens a new conversation window with the user matching the provided
            nick.

            Args:
            - nick: Peer username
        """
        self.switchToSidebar()
        nicks = self.waitForElements("ul.nav-list>li>a", visible=True)
        filter(lambda e: e.text == nick, nicks)[0].click()
        return self.switchToChatWindow()

    def clickElement(self, css_selector):
        """ Clicks the element matching the provided CSS selector."""
        self.waitForElement(css_selector, visible=True).click()

    def signin(self):
        """ Signs the user in."""
        if not self.nick:
            raise RuntimeError("No nick provided")
        self.switchToSidebar()
        # Wait for everything to be loaded before we proceed, this hopefully
        # ensures we don't get into issues with cookies being loaded
        # at the wrong time, or not fully loaded.
        self.waitForElement("#signin", visible=True)
        self.add_cookie({"name": "test email", "value": self.nick})
        self.clickElement("#signin")
        # Ensure we've completed logging in before proceeding
        self.waitForElement("#signout", visible=True)
        return self

    def signout(self):
        """Signs the user out."""
        self.switchToSidebar()
        self.clickElement('#signout button')
        return self

    def startCall(self, video):
        """ Starts a new call.

            Args:
            - video: True for video, else audio only
        """
        self.clickElement(".btn-video>a" if video else ".btn-audio>a")

    def restartCall(self):
        """ Restarts a call. For use when the call is timed out. """
{'fraction_non_alphanumeric': 0.1089961931476658, 'fraction_numerical': 0.006812262071729113, 'mean_word_length': 2.614771904417089, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3069735', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1366, 'n_words': 409}