示例#1
0
def fill_in_improv_and_feature_environment_information(
        browser: webdriver.WebDriver, env_template_path: str) -> None:
    """
    :param browser: instance of a selenium.webdriver() object
    :param env_template_path: Path of the file that contains the environment
    information text
    :return: No return value
    """

    try:
        browser.find_element(
            By.LINK_TEXT,
            elements_jira.tab_improvement_others_link_text).click()

    except NoSuchElementException and StaleElementReferenceException:
        logging.error("'Others' tab not found")

    browser.find_element_by_link_text(
        elements_jira.btn_environment_fld_text_link_text).click()

    with open(env_template_path, 'r') as env_template:
        fill_in_element(browser,
                        By.ID,
                        elements_jira.fld_environment_id,
                        env_template.read(),
                        confirm=True)
def retry_element_can_be_filled(driver: webdriver.WebDriver, by: By, locator,
                                content):
    """
    :param driver: Driver for the browser
    :type driver: webdriver
    :param by: Locator type for the element
    :type by: selenium.webdriver.common.by.By
    :param locator: Element value for the locator type
    :type locator: str
    :param content: Content to write into the element
    :type content: str
    :return: Return the outcome of the action
    :rtype: bool
    """
    result = False
    attempts = 1
    while attempts < 3 and result is False:
        try:
            element = driver.find_element(by, locator)
            # element.click()
            element.send_keys(Keys.DELETE)
            element.send_keys(content)
            # element.clear()
            result = True
        except StaleElementReferenceException:
            pass
        time.sleep(0.5)
        attempts += 1
    return result
示例#3
0
def fill_in_description(browser: webdriver.WebDriver, desc_template_path):
    """
    The fill_in_desc_template(browser, desc_template_path) fills the content of
    the description text file into the designated field
    :param browser: instance of a selenium.webdriver() object
    :param desc_template_path: Path to the description input text file
    :return: No return value
    """
    try:
        browser.find_element(By.LINK_TEXT,
                             elements_jira.tab_info_link_text).click()
    except NoSuchElementException and StaleElementReferenceException:
        logging.error("'Info' tab not found")

    browser.find_element_by_link_text(
        elements_jira.btn_description_fld_text_link_text).click()
    fill_in_element(browser, By.ID, elements_jira.fld_description_id,
                    open(desc_template_path).read())
示例#4
0
def fill_in_environment_information(browser: webdriver.WebDriver,
                                    issue_type: str,
                                    template_path: str) -> None:
    """
    :param browser: instance of a selenium.webdriver() object
    :param template_path: Path of the file that contains the environment
    information text
    :param issue_type: Issue name
    :return: No return value
    """
    if issue_type == "bug":
        try:
            browser.find_element(
                By.LINK_TEXT, elements_jira.tab_bug_details_link_text).click()

        except NoSuchElementException and StaleElementReferenceException:
            logging.error("'Bug Details' tab not found")

        browser.find_element_by_link_text(
            elements_jira.btn_environment_fld_text_link_text).click()

    elif issue_type == "improvement" or "feature":
        try:
            browser.find_element(
                By.LINK_TEXT,
                elements_jira.tab_improvement_others_link_text).click()

        except NoSuchElementException and StaleElementReferenceException:
            logging.error("'Others' tab not found")

        browser.find_element_by_link_text(
            elements_jira.btn_environment_fld_text_link_text).click()

    else:
        logging.error("Environment info cannot be inserted for type " +
                      issue_type)
        pass

    with open(template_path, 'r') as env_template:
        fill_in_element(browser,
                        By.ID,
                        elements_jira.fld_environment_id,
                        env_template.read(),
                        confirm=True)
示例#5
0
def enter_solution(driver: WebDriver, sudoku: KillerSudoku):
    first_cell = driver.find_elements_by_class_name('cell')[0]
    ActionChains(driver).move_to_element(first_cell).click().perform()
    time.sleep(1)

    def press_key(key):
        ActionChains(driver).send_keys(key).perform()

    for row in range(9):
        for column in range(9):
            press_key(str(int(sudoku.grid[row, column])))
            time.sleep(0.03)

            press_key(Keys.ARROW_RIGHT)
            time.sleep(0.03)

        press_key(Keys.ARROW_DOWN)
        time.sleep(0.03)

    time.sleep(2)
    driver.find_element(By.XPATH, '//button[.="Back to the puzzles"]').click()
示例#6
0
def fill_in_assignee(browser: webdriver.WebDriver, assignee: str) -> None:
    """
    The fill_in_assignee(browser, assignee, tab_assign_xpath) function fills
    the assignee text string into the designated field and confirms the
    selection in the browser
    :param browser: instance of a selenium.webdriver() object
    :param assignee: String of the assignee value
    :return: No return value
    """

    try:
        browser.find_element(By.LINK_TEXT,
                             elements_jira.tab_assign_link_text).click()

    except NoSuchElementException and StaleElementReferenceException:
        logging.error("'Assignee' tab not found")

    fill_in_element(browser,
                    By.ID,
                    elements_jira.fld_assigne_id,
                    assignee,
                    confirm=True)
示例#7
0
def prepare_browser(driver: WebDriver):
    driver.find_element(By.XPATH, '//a[.="Sign in"]').click()
    driver.implicitly_wait(3)
    driver.find_element_by_id('user_email').send_keys(
        '*****@*****.**')
    driver.find_element_by_id('user_password').send_keys('fdRQNtZi4m6mYd!')
    driver.find_element_by_id('user_password').send_keys(Keys.ENTER)
    time.sleep(5)
    driver.find_element(By.XPATH, '//span[.="Start Again"]').click()
    try:
        driver.find_element(By.XPATH, '//button[.="Yes"]').click()
    except NoSuchElementException:
        pass

    time.sleep(3)
示例#8
0
class SeleniumRunner:
    """
    A runner that upload and download Icomoon resources using Selenium.
    The WebDriver will use Firefox.
    """

    """
    The long wait time for the driver in seconds.
    """
    LONG_WAIT_IN_SEC = 25

    """
    The medium wait time for the driver in seconds.
    """
    MED_WAIT_IN_SEC = 6

    """
    The short wait time for the driver in seconds.
    """
    SHORT_WAIT_IN_SEC = 0.6

    """
    The Icomoon Url.
    """
    ICOMOON_URL = "https://icomoon.io/app/#/select"

    def __init__(self, download_path: str,
                 geckodriver_path: str, headless: bool):
        """
        Create a SeleniumRunner object.
        :param download_path: the location where you want to download
        the icomoon.zip to.
        :param geckodriver_path: the path to the firefox executable.
        :param headless: whether to run browser in headless (no UI) mode.
        """
        self.driver = None
        self.set_options(download_path, geckodriver_path, headless)

    def set_options(self, download_path: str, geckodriver_path: str,
        headless: bool):
        """
        Build the WebDriver with Firefox Options allowing downloads and
        set download to download_path.
        :param download_path: the location where you want to download
        :param geckodriver_path: the path to the firefox executable.
        the icomoon.zip to.
        :param headless: whether to run browser in headless (no UI) mode.

        :raises AssertionError: if the page title does not contain
        "IcoMoon App".
        """
        options = Options()
        allowed_mime_types = "application/zip, application/gzip, application/octet-stream"
        # disable prompt to download from Firefox
        options.set_preference("browser.helperApps.neverAsk.saveToDisk", allowed_mime_types)
        options.set_preference("browser.helperApps.neverAsk.openFile", allowed_mime_types)

        # set the default download path to downloadPath
        options.set_preference("browser.download.folderList", 2)
        options.set_preference("browser.download.dir", download_path)
        options.headless = headless

        self.driver = WebDriver(options=options, executable_path=geckodriver_path)
        self.driver.get(self.ICOMOON_URL)
        assert "IcoMoon App" in self.driver.title
        # wait until the whole web page is loaded by testing the hamburger input
        WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
            ec.element_to_be_clickable((By.XPATH, "(//i[@class='icon-menu'])[2]"))
        )
        print("Accessed icomoon.io")
        

    def upload_icomoon(self, icomoon_json_path: str):
        """
        Upload the icomoon.json to icomoon.io.
        :param icomoon_json_path: a path to the iconmoon.json.
        :raises TimeoutException: happens when elements are not found.
        """
        print("Uploading icomoon.json file...")
        self.click_hamburger_input()
        
        # find the file input and enter the file path
        import_btn = self.driver.find_element(By.XPATH, "(//li[@class='file'])[1]//input")
        import_btn.send_keys(icomoon_json_path)

        try:
            confirm_btn = WebDriverWait(self.driver, SeleniumRunner.MED_WAIT_IN_SEC).until(
                ec.element_to_be_clickable((By.XPATH, "//div[@class='overlay']//button[text()='Yes']"))
            )
            confirm_btn.click()
        except SeleniumTimeoutException as e:
            raise Exception("Cannot find the confirm button when uploading the icomoon.json" \
                  "Ensure that the icomoon.json is in the correct format for Icomoon.io")

        print("JSON file uploaded.")

    def upload_svgs(self, svgs: List[str], screenshot_folder: str=""):
        """
        Upload the SVGs provided in folder_info
        :param svgs: a list of svg Paths that we'll upload to icomoon.
        :param screenshot_folder: the name of the screenshot_folder. If
        the value is provided, it means the user want to take a screenshot
        of each icon.
        """
        print("Uploading SVGs...")

        edit_mode_btn = self.driver.find_element_by_css_selector(
            "div.btnBar button i.icon-edit"
        )
        edit_mode_btn.click()

        self.click_hamburger_input()

        for i in range(len(svgs)):
            import_btn = self.driver.find_element_by_css_selector(
                "li.file input[type=file]"
            )
            import_btn.send_keys(svgs[i])
            print(f"Uploaded {svgs[i]}")
            self.test_for_possible_alert(self.SHORT_WAIT_IN_SEC, "Dismiss")
            self.click_on_just_added_icon(screenshot_folder, i)

        # take a screenshot of the icons that were just added
        new_icons_path = str(Path(screenshot_folder, "new_icons.png").resolve())
        self.driver.save_screenshot(new_icons_path);

        print("Finished uploading the svgs...")

    def click_hamburger_input(self):
        """
        Click the hamburger input until the pop up menu appears. This
        method is needed because sometimes, we need to click the hamburger
        input two times before the menu appears.
        :return: None.
        """
        hamburger_input = self.driver.find_element_by_xpath(
            "(//i[@class='icon-menu'])[2]"
        )

        menu_appear_callback = ec.element_to_be_clickable(
            (By.CSS_SELECTOR, "h1 ul.menuList2")
        )

        while not menu_appear_callback(self.driver):
            hamburger_input.click()

    def test_for_possible_alert(self, wait_period: float, btn_text: str):
        """
        Test for the possible alert when we upload the svgs.
        :param wait_period: the wait period for the possible alert
        in seconds.
        :param btn_text: the text that the alert's button will have.
        :return: None.
        """
        try:
            dismiss_btn = WebDriverWait(self.driver, wait_period, 0.15).until(
                ec.element_to_be_clickable(
                    (By.XPATH, f"//div[@class='overlay']//button[text()='{btn_text}']"))
            )
            dismiss_btn.click()
        except SeleniumTimeoutException:
            pass  # nothing found => everything is good

    def click_on_just_added_icon(self, screenshot_folder: str, index: int):
        """
        Click on the most recently added icon so we can remove the colors
        and take a snapshot if needed.
        """
        recently_uploaded_icon = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
            ec.element_to_be_clickable((By.XPATH, "//div[@id='set0']//mi-box[1]//div"))
        )
        recently_uploaded_icon.click()

        self.remove_color_from_icon()

        if screenshot_folder:
            screenshot_path = str(Path(screenshot_folder, f"screenshot_{index}.png").resolve())
            self.driver.save_screenshot(screenshot_path)
            print("Took screenshot and saved it at " + screenshot_path)

        close_btn = self.driver \
            .find_element_by_css_selector("div.overlayWindow i.icon-close")
        close_btn.click()

    def remove_color_from_icon(self):
        """
        Remove the color from the most recent uploaded icon.
        This is because some SVG have colors in them and we don't want to
        force contributors to remove them in case people want the colored SVGs.
        The color removal is also necessary so that the Icomoon-generated
        icons fit within one font symbol/ligiature.
        """
        try:
            color_tab = WebDriverWait(self.driver, self.SHORT_WAIT_IN_SEC).until(
                ec.element_to_be_clickable((By.CSS_SELECTOR, "div.overlayWindow i.icon-droplet"))
            )
            color_tab.click()

            remove_color_btn = self.driver \
                .find_element_by_css_selector("div.overlayWindow i.icon-droplet-cross")
            remove_color_btn.click()
        except SeleniumTimeoutException:
            pass # do nothing cause sometimes, the color tab doesn't appear in the site

    def download_icomoon_fonts(self, zip_path: Path):
        """
        Download the icomoon.zip from icomoon.io.
        :param zip_path: the path to the zip file after it's downloaded.
        """
        # select all the svgs so that the newly added svg are part of the collection
        self.click_hamburger_input()
        select_all_button = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
            ec.element_to_be_clickable((By.XPATH, "//button[text()='Select All']"))
        )
        select_all_button.click()

        print("Downloading Font files...")
        font_tab = self.driver.find_element_by_css_selector(
            "a[href='#/select/font']"
        )
        font_tab.click()

        self.test_for_possible_alert(self.MED_WAIT_IN_SEC, "Continue")
        download_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
            ec.presence_of_element_located((By.CSS_SELECTOR, "button.btn4 span"))
        )
        download_btn.click()
        if self.wait_for_zip(zip_path):
            print("Font files downloaded.")
        else:
            raise TimeoutError(f"Couldn't find {zip_path} after download button was clicked.")

    def wait_for_zip(self, zip_path: Path) -> bool:
        """
        Wait for the zip file to be downloaded by checking for its existence
        in the download path. Wait time is self.LONG_WAIT_IN_SEC and check time
        is 1 sec.
        :param zip_path: the path to the zip file after it's
        downloaded.
        :return: True if the file is found within the allotted time, else
        False.
        """
        end_time = time.time() + self.LONG_WAIT_IN_SEC
        while time.time() <= end_time:
            if zip_path.exists():
                return True
            time.sleep(1)    
        return False

    def close(self):
        """
        Close the SeleniumRunner instance.
        """
        print("Closing down SeleniumRunner...")
        self.driver.quit()
示例#9
0
def test_nextcloud(IP: str, nc_port: str, driver: WebDriver):
    """ Login and assert admin page checks"""
    test = Test()
    test.new("nextcloud page")
    try:
        driver.get(f"https://{IP}:{nc_port}/index.php/settings/admin/overview")
    except Exception as e:
        test.check(
            e,
            msg=
            f"{tc.red}error:{tc.normal} unable to reach {tc.yellow + IP + tc.normal}"
        )
    test.check("NextCloudPi" in driver.title,
               msg="NextCloudPi not found in page title!")
    trusted_domain_str = "You are accessing the server from an untrusted domain"
    test.report("trusted domain", trusted_domain_str not in driver.page_source,
                f"Domain '{IP}' is not trusted")
    try:
        driver.find_element(By.ID, "user").send_keys(nc_user)
        driver.find_element(By.ID, "password").send_keys(nc_pass)
        driver.find_element(By.ID, "submit-form").click()
    except NoSuchElementException:
        try:
            driver.find_element(By.ID, "submit").click()
        except NoSuchElementException:
            pass

    test.report("password",
                "Wrong password" not in driver.page_source,
                msg="Failed to login with provided password")

    test.new("settings config")
    wait = WebDriverWait(driver, 30)
    try:
        wait.until(
            VisibilityOfElementLocatedByAnyLocator([
                (By.CSS_SELECTOR, "#security-warning-state-ok"),
                (By.CSS_SELECTOR, "#security-warning-state-warning"),
                (By.CSS_SELECTOR, "#security-warning-state-error")
            ]))

        element_ok = driver.find_element(By.ID, "security-warning-state-ok")
        element_warn = driver.find_element(By.ID,
                                           "security-warning-state-warning")

        if element_warn.is_displayed():

            if driver.find_element(By.CSS_SELECTOR, "#postsetupchecks > .errors").is_displayed() \
                    or driver.find_element(By.CSS_SELECTOR, "#postsetupchecks > .warnings").is_displayed():
                raise ConfigTestFailure("There have been errors or warnings")

            infos = driver.find_elements(By.CSS_SELECTOR,
                                         "#postsetupchecks > .info > li")
            for info in infos:
                if re.match(
                        r'.*Your installation has no default phone region set.*',
                        info.text):
                    continue
                else:

                    php_modules = info.find_elements(By.CSS_SELECTOR, "li")
                    if len(php_modules) != 1:
                        raise ConfigTestFailure(
                            f"Could not find the list of php modules within the info message "
                            f"'{infos[0].text}'")
                    if php_modules[0].text != "imagick":
                        raise ConfigTestFailure(
                            "The list of php_modules does not equal [imagick]")

        elif not element_ok.is_displayed():
            raise ConfigTestFailure(
                "Neither the warnings nor the ok status is displayed "
                "(so there are probably errors or the page is broken)")

        test.check(True)

    except Exception as e:
        test.check(e)
class CreateNewGroup(unittest.TestCase):
    def setUp(self):
        self.wd = WebDriver()
        self.wd.implicitly_wait(30)

    def test_create_new_group(self):
        wd = self.wd
        self.open_home_page(wd)
        self.login(wd, username="******", password="******")
        self.open_group_page(wd)
        self.create_group(wd, Group(name="test_group1", header="test_header1", footer="test_footer1"))
        self.return_to_group_page(wd)
        self.logout(wd)

    def test_create_empty_group(self):
        wd = self.wd
        self.open_home_page(wd)
        self.login(wd, username="******", password="******")
        self.open_group_page(wd)
        self.create_group(wd, Group( name="", header="", footer=""))
        self.return_to_group_page(wd)
        self.logout(wd)

    def logout(self, wd):
        wd.find_element_by_link_text("Logout").click()

    def return_to_group_page(self, wd):
        wd.find_element_by_link_text("groups").click()

    def create_group(self, wd, group):
        # init group creation
        wd.find_element_by_name("new").click()
        # fill group form
        wd.find_element_by_name("group_name").click()
        wd.find_element_by_name("group_name").clear()
        wd.find_element_by_name("group_name").send_keys(group.name)
        wd.find_element_by_name("group_header").click()
        wd.find_element_by_name("group_header").clear()
        wd.find_element_by_name("group_header").send_keys(group.header)
        wd.find_element_by_name("group_footer").clear()
        wd.find_element_by_name("group_footer").send_keys(group.footer)
        # submit group creation
        wd.find_element_by_name("submit").click()

    def open_group_page(self, wd):
        wd.find_element_by_link_text("groups").click()

    def login(self, wd, username, password):
        wd.find_element_by_name("user").click()
        wd.find_element_by_name("user").clear()
        wd.find_element_by_name("user").send_keys(username)
        wd.find_element_by_name("pass").clear()
        wd.find_element_by_name("pass").send_keys(password)
        wd.find_element_by_xpath("//input[@value='Login']").click()

    def open_home_page(self, wd):
        wd.get("http://localhost/addressbook/")

    def is_element_present(self, how, what):
        try:
            self.wd.find_element(by=how, value=what)
        except NoSuchElementException as e:
            return False
        return True

    def is_alert_present(self):
        try:
            self.wd.switch_to_alert()
        except NoAlertPresentException as e:
            return False
        return True

    def tearDown(self):
        self.wd.quit()
示例#11
0
class Text_read(Base):

    def setUp(self):
        super(Text_read, self).setUp()
        self.pwd = 'selenium12345!!!'
        self.user_1 = UserFactory(password=self.pwd)
        self.selenium = WebDriver()
        self.language_1 = EnglishLanguagesFactory(owner=self.user_1)
        Settings_currentlang_idFactory(owner=self.user_1, stvalue=self.language_1.id)
        self.selenium.get('{}'.format(self.live_server_url))
        self.find(By.NAME, 'login').send_keys(self.user_1.username)
        self.find(By.NAME, 'password').send_keys(self.pwd)
        self.find(By.CSS_SELECTOR, "button[type='submit']").click()

#     @classmethod
#     def tearDownClass(cls):
#         cls.selenium.quit()
#         super(Text_read, cls).tearDownClass()

    def tearDown(self):
        self.selenium.quit()
        super(Text_read, self).tearDown()

#     @classmethod
#     def setUpClass(cls):
#         super(Text_read, cls).setUpClass()
#         cls.pwd = 'selenium20171106!!!'
#         cls.user_1 = UserFactory(password=cls.pwd)
#         cls.selenium = WebDriver()
#         cls.language_1 = EnglishLanguagesFactory(owner=cls.user_1)
# #         cls.text1 = GermanTextsFactory(owner=cls.user_1, language=cls.language_1)
# #         print(cls.text1.text)
# #         splitText(cls.text1)
#         Settings_currentlang_idFactory(owner=cls.user_1, stvalue=cls.language_1.id)
#         cls.selenium.get('{}'.format(cls.live_server_url))
#         cls.find(By.NAME, 'login').send_keys(cls.user_1.username)
#         cls.find(By.NAME, 'password').send_keys(cls.pwd)
#         cls.find(By.CSS_SELECTOR, "button[type='submit']").click()

#         language_2 = LanguagesFactory(owner=cls.user_1)
#         Settings_currentlang_id.objects.get(owner=cls.user_1).stvalue=language_2

#     def test_go_to_text_read(self):
#         self.selenium.get('{}/text_read/{}'.format(self.live_server_url, self.text1.id))
         
#     def test_click_on_unknown_word(self):
#         self.selenium.get('{}/text_read/{}'.format(self.live_server_url, self.text1.id))
#         all_unknown_words = self.finds(By.XPATH, '//span[@wostatus=0]')
#         random_word = random.choice(all_unknown_words)
#         random_word.click()
#         print('Chosen word : ', random_word.text)
#         self.wait_until(By.CLASS_NAME, 'tooltiptext')
#         self.wait_until(By.XPATH, '//div[@id="bottomright"]/h3')
#         time.sleep(120)
 
    def test_save_word_with_similarity(self):
#         language_2 = LanguagesFactory(owner=self.user_1)
#         Settings_currentlang_id.objects.get(owner=self.user_1).stvalue=language_2
        text2 = TextsFactory(owner=self.user_1, language=self.language_1)
        sentence1 ='Aaa bbb aaa aaa bbb.\n' 
        text2.text = sentence1
        sentence2 = 'Vvv ddd vvv ddd eee rrr ttt uuu eee eee ttt ooo.\n'
        text2.text += sentence2
        sentence3 = 'Ppp lll ppp mmm nnn ooo mmm lll mmm nnn.'
        text2.text += sentence3

        # Verify that the splitting text is working
        splitText(text2)
        self.selenium.get('{}/text_read/{}'.format(self.live_server_url, text2.id))
        thetext = self.find(By.ID, "thetext")
        self.assertEqual(text2.text.strip(), thetext.text.strip(), msg='Text on the text_read screen is not what the new text when created')
        
        # when using move_to_element, we MUST use 'click()' after (even if not needed to click...)
#         tooltip_righthandle_selector = (By.XPATH, "//td[contains(text(),'Close')]") 
#         tooltip_righthandle = self.find(*tooltip_righthandle_selector) 
#         ActionChains(self.selenium).move_to_element(tooltip_righthandle).click().perform()
#         self.wait_until_disappear(*tooltip_righthandle_selector)
#         self.assertEqual(len(self.selenium.find_elements(*tooltip_righthandle_selector)), 0, 
#                          msg="Tooltip doesn't disappear when mouse over the right handle")
# 
        self.wait_until_appear(By.CSS_SELECTOR, 'iframe[id="dictwebpage"]')
        words = self.finds(By.XPATH, "//span[contains(text(),'mmm')]")
        words[0].click()
 
        # verify that new_term_form is created in the top right and submit a translation
        expected_sent = sentence3.replace('mmm', '**mmm**')
        self.wait_until_appear(By.XPATH, "//textarea[@id='id_sentence' and contains(text(), '{}')]".format(expected_sent))
        textarea = self.find(By.ID, 'id_translation')
        textarea.send_keys('a')
        wordtagarea = self.find(By.ID, 'id_wordtags_tags_input_tag')
        wordtagarea.send_keys('masculine')
        wordtagarea.send_keys(',')
        wordtagarea.send_keys('singular')
        wordtagarea.send_keys(',')
        self.wait_until_appear(By.XPATH, '//span[contains(text(), "singular")]')
        self.find(By.ID, 'submit_word').click()
        elements = self.finds(By.CSS_SELECTOR, 'span[wostatus="1"')
        self.assertEqual(len(elements), 3)
        self.assertEqual(elements[0].text, 'mmm')
        
        # creating a new text with the same words:
        text3 = TextsFactory(owner=self.user_1, language=self.language_1)
        text3.text = text2.text
        splitText(text3)
        self.selenium.get('{}/text_read/{}'.format(self.live_server_url, text3.id))
  
        # when using move_to_element, we MUST use 'click()' after (even if not needed to click...)
#         tooltip_righthandle_selector = (By.XPATH, "//td[contains(text(),'Close')]") 
#         tooltip_righthandle = self.find(*tooltip_righthandle_selector) 
#         ActionChains(self.selenium).move_to_element(tooltip_righthandle).click().perform()
#         self.wait_until_disappear(*tooltip_righthandle_selector)
#         self.assertEqual(len(self.selenium.find_elements(*tooltip_righthandle_selector)), 0, 
#                          msg="Tooltip doesn't disappear when mouse over the right handle")
# 
        elements = self.finds(By.CSS_SELECTOR, 'span[wostatus="2"')
        self.assertEqual(len(elements), 3, msg="New text don't get the already saved words")
        self.assertEqual(elements[0].text, 'mmm')
         
        #editing a word translation:
        elements[0].click()
        self.wait_until_appear(By.CLASS_NAME, 'tooltiptext')
        self.find(By.XPATH, "//a[contains(text(),'Edit term')]").click()
        submit = self.find(By.XPATH, "//button[@id='submit_word' and contains(text(),'Change')]")
        textarea = self.find(By.ID, 'id_translation')
        textarea.clear()
        textarea.send_keys('b')
        wordtagarea = self.find(By.ID, 'id_wordtags_tags_input_tag')
        wordtagarea.send_keys('masculine')
        wordtagarea.send_keys(',')
        wordtagarea.send_keys('singular')
        wordtagarea.send_keys(',')
        submit.click()
        elements[2].click()
        tooltip = self.find(By.CLASS_NAME, 'tooltiptext')
        self.assertEqual('mmm\n▶ b\nEdit term | Delete term & similar\nDelete single term\nLookup Term: Dict1 Dict2 GTr\nLookup Sentence: GTr',
                                 tooltip.text)
         
        #editing a word status to 'well-known':
        tooltip_righthandle_selector = (By.XPATH, '//td[@align="RIGHT"]/a') 
        tooltip_righthandle = self.find(*tooltip_righthandle_selector) 
        ActionChains(self.selenium).move_to_element(tooltip_righthandle).click().perform()
        self.wait_until_disappear(*tooltip_righthandle_selector)
 
        elements[1].click()
        self.wait_until_appear(By.CLASS_NAME, 'tooltiptext')
        self.find(By.XPATH, "//a[contains(text(),'Edit term')]").click()
        submit = self.find(By.XPATH, "//button[@id='submit_word' and contains(text(),'Change')]")
        textarea = self.find(By.ID, 'id_translation')
        textarea.clear()
        textarea.send_keys('c')
        wordtagarea = self.find(By.ID, 'id_wordtags_tags_input_tag')
        wordtagarea.send_keys('masculine')
        wordtagarea.send_keys(',')
        wordtagarea.send_keys('singular')
        wordtagarea.send_keys(',')
        # changing status to well known
        self.find(By.CSS_SELECTOR, 'input[value="100"]').click()
        submit.click()
        elements = self.finds(By.XPATH, '//span[@wostatus="100" and contains(text(),"mmm")]')
        self.assertEqual(len(elements), 3)
         
        # and changing again the status 'well-known' to learning:
        elements[2].click()
        self.wait_until_appear(By.CLASS_NAME, 'tooltiptext')
        self.find(By.XPATH, "//a[contains(text(),'Edit term')]").click()
        submit = self.find(By.XPATH, "//button[@id='submit_word' and contains(text(),'Change')]")
        textarea = self.find(By.ID, 'id_translation')
        textarea.clear()
        textarea.send_keys('d')
        wordtagarea = self.find(By.ID, 'id_wordtags_tags_input_tag')
        wordtagarea.send_keys('masculine')
        wordtagarea.send_keys(',')
        wordtagarea.send_keys('singular')
        wordtagarea.send_keys(',')
        # changing status to well known
        self.find(By.CSS_SELECTOR, 'input[value="1"]').click()
        submit.click()
        elements = self.finds(By.XPATH, '//span[@wostatus="1" and contains(text(),"mmm")]')
        self.assertEqual(len(elements), 3)
         
    def test_submit_similar_word(self):
#         language_3 = LanguagesFactory(owner=self.user_1)
#         Settings_currentlang_id.objects.get(owner=self.user_1).stvalue=language_3
        text2 = TextsFactory(owner=self.user_1, language=self.language_1)
        sentences ='''aimer aimerais aimeront aimant aimer.
                       aimerais aimable aimable.'''
        text2.text = sentences
        splitText(text2)
        self.selenium.get('{}/text_read/{}'.format(self.live_server_url, text2.id))
  
        self.wait_until_appear(By.CSS_SELECTOR, 'iframe[id="dictwebpage"]')
         
        # moving on the 'x' of the tooltip makes it disappear
        tooltip_righthandle_selector = (By.XPATH, '//td[@align="RIGHT"]/a') 
        tooltip_righthandle = self.find(*tooltip_righthandle_selector) 
        ActionChains(self.selenium).move_to_element(tooltip_righthandle).click().perform()
        self.wait_until_disappear(*tooltip_righthandle_selector)
        self.assertEqual(self.selenium.find_element(*tooltip_righthandle_selector).text, '', 
                         msg="Tooltip doesn't disappear when mouse over the right handle")
  
        # submit the word 'aimer'
        words_aimer = self.finds(By.XPATH, "//span[contains(text(),'aimer')]")
        words_aimer[0].click()
        textarea = self.find(By.ID, 'id_translation')
        textarea.send_keys('to love')
        wordtagarea = self.find(By.ID, 'id_wordtags_tags_input_tag')
        wordtagarea.send_keys('verb')
        wordtagarea.send_keys(',')
        wordtagarea.send_keys('transitive')
        wordtagarea.send_keys(',')
 
        self.find(By.ID, 'submit_word').click()
 
        self.wait_until_text_appear((By.XPATH, '//div[@id="topright"]'), '"aimerais"')
         
        # then click on another word: 'aimerais' in text_read
        words_aimerais = self.finds(By.XPATH, "//span[contains(text(),'aimerais')]")
        words_aimerais[0].click()
        # click on the similar word (word already saved)
        similarwords = self.finds(By.XPATH, '//span[@class="possible_similarword"]')
        self.assertEqual(len(similarwords), 1)
        similarwords[0].click()
        totalsavedwords = self.finds(By.XPATH, '//*[@id="thetext"]/p[1]/span[@wostatus="1"]')
        self.assertEqual(len(totalsavedwords), 4)
        newsavedwords = self.finds(By.XPATH, '//*[@id="thetext"]/p[1]/span[@wostatus="1" and contains(text(), "aimerais")]')
        self.assertEqual(len(newsavedwords), 2)
         
        # create a new text with the same text
        text3 = TextsFactory(owner=self.user_1, language=self.language_1)
        text3.text = text2.text
        splitText(text3)
        self.selenium.get('{}/text_read/{}'.format(self.live_server_url, text3.id))
  
        # when using move_to_element, we MUST use 'click()' after (even if not needed to click...)
#         tooltip_righthandle_selector = (By.XPATH, "//td[contains(text(),'Close')]") 
#         tooltip_righthandle = self.find(*tooltip_righthandle_selector) 
#         ActionChains(self.selenium).move_to_element(tooltip_righthandle).click().perform()
#         self.wait_until_disappear(*tooltip_righthandle_selector)
#         self.assertEqual(len(self.selenium.find_elements(*tooltip_righthandle_selector)), 0, 
#                          msg="Tooltip doesn't disappear when mouse over the right handle")
 
        totalsavedwords = self.finds(By.XPATH, '//span[@wostatus="2"]')
        self.assertEqual(len(totalsavedwords), 4)
        newsavedwords = self.finds(By.XPATH, '//span[@wostatus="2" and contains(text(), "aimerais")]')
        self.assertEqual(len(newsavedwords), 2, )
 
        # clicking on word 'aimeront' should make only one similar word to appear:
        words = self.finds(By.XPATH, "//span[contains(text(),'aimeront')]")
        words[0].click()
        similarwords = self.finds(By.CSS_SELECTOR, '#possible_similarword_result span.possible_similarword')
        self.assertEqual(len(similarwords), 1)
         
        #editing a word make all similar words updated:
        tooltip_righthandle_selector = (By.XPATH, '//td[@align="RIGHT"]/a') 
        tooltip_righthandle = self.find(*tooltip_righthandle_selector) 
        ActionChains(self.selenium).move_to_element(tooltip_righthandle).click().perform()
        self.wait_until_disappear(*tooltip_righthandle_selector)
 
        self.finds(By.XPATH, '//span[@wostatus="2" and contains(text(), "aimerais")]')[1].click()
        self.wait_until_appear(By.CLASS_NAME, 'tooltiptext')
        self.find(By.XPATH, "//a[contains(text(),'Edit term')]").click()
        submit = self.find(By.XPATH, "//button[@id='submit_word' and contains(text(),'Change')]")
        textarea = self.find(By.ID, 'id_translation')
        textarea.clear()
        textarea.send_keys('to hate')
        wordtagarea = self.find(By.ID, 'id_wordtags_tags_input_tag')
        wordtagarea.send_keys('verb')
        wordtagarea.send_keys(',')
        wordtagarea.send_keys('transitive')
        wordtagarea.send_keys(',')
        submit.click()
        self.finds(By.XPATH, '//span[@wostatus="1" and contains(text(), "aimer")]')[1].click()
        tooltip = self.find(By.CLASS_NAME, 'tooltiptext')
        self.assertTrue('▶ to hate' in tooltip.text)
 
    def test_saving_one_compoundword(self):
#         language_2 = EnglishLanguagesFactory(owner=self.user_1)
#         Settings_currentlang_id.objects.get(owner=self.user_1).stvalue=language_2
        text2 = TextsFactory(owner=self.user_1, language=self.language_1, text='''
        Do you carry the surplus over?
it is over. the carry. the carry is well over. 
is over the carry?''')
        splitText(text2)
        # initial database
        first_word_DB_before = Words.objects.filter( wordtext="carry").first()
        second_word_DB_before = Words.objects.filter( wordtext="over").first()
        self.assertEqual(first_word_DB_before.compoundword, None) 
        self.assertEqual(second_word_DB_before.compoundword, None)
        self.assertEqual(first_word_DB_before.status, 0) 
  
        self.selenium.get('{}/text_read/{}'.format(self.live_server_url, text2.id))
        first_word_before = self.find(By.XPATH, '//span[@wowordtext="carry"]')
        self.assertEqual(first_word_before.get_attribute('title'), 'carry\r▶ Unknown [0]')
        first_word_before.click()
        self.wait_until_appear(By.CLASS_NAME, 'tooltiptext')
        self.wait_until_appear(By.XPATH, '//div[@id="bottomright"]/iframe[@id="dictwebpage"]')
        second_word_before = self.find(By.XPATH, '//span[@wowordtext="over"]')
        # ctrl+click the second word
        ActionChains(self.selenium).key_down(Keys.CONTROL).click(second_word_before).key_up(Keys.CONTROL).perform()
  
        self.wait_until_appear(By.XPATH, '//textarea[@id="id_sentence"][contains(.,"Do you **carry** the surplus **over**?")]') 
        trans_textarea = self.find(By.XPATH, '//textarea[@id="id_translation"]')
        trans_textarea.send_keys('excédent')
        wordtagarea = self.find(By.ID, 'id_wordtags_tags_input_tag')
        wordtagarea.send_keys('economics')
        wordtagarea.send_keys(',')
        wordtagarea.send_keys('masculine')
        wordtagarea.send_keys(',')
        self.find(By.XPATH, '//button[@id="submit_word"]').click()
        self.wait_until_appear(By.XPATH, '//div[@id="topright"][contains(.,"it")]')
        # good in database
        compoundword = Words.objects.get(isCompoundword=True, isnotword=True)
        self.assertEqual(compoundword.status, 1) # and now is 'Learning'
        first_word_DB_after = Words.objects.filter( wordtext="carry").first()
        second_word_DB_after = Words.objects.filter( wordtext="over").first()
        self.assertEqual(first_word_DB_after.compoundword, compoundword) # and now is 'Learning'
        self.assertEqual(second_word_DB_after.compoundword, compoundword) # and now is 'Learning'
        self.assertEqual(first_word_DB_after.show_compoundword, True) # and now is 'Learning'
        self.assertEqual(first_word_DB_after.status, 1) 
        # and good css:
        firstword_after = self.find(By.XPATH, '//span[@wowordtext="carry" and @cowordtext="carry+over"]')
        secondword_after = self.find(By.XPATH, '//span[@wowordtext="over" and @cowordtext="carry+over"]')
        self.assertEqual(firstword_after.get_attribute('wostatus'), '1')
        self.assertEqual(secondword_after.get_attribute('wostatus'), '1')
        self.assertEqual(firstword_after.get_attribute('show_compoundword'), 'True')
        self.assertEqual(firstword_after.get_attribute('iscompoundword'), 'True')
        self.assertEqual(firstword_after.get_attribute('title'), 'carry+over\r• excédent\r• Learning [1]')
  
    ####### FUNCTIONS BELOW TO BE CHECKED ###########

#     def test_click_on_unknown_word_dictwebpage(self):
#         language_2 = EnglishLanguagesFactory(owner=self.user_1)
#         Settings_currentlang_id.objects.get(owner=self.user_1).stvalue=language_2
#         text2 = EnglishTextsFactory(owner=self.user_1, language=language_2)
#         splitText(text2)
#         self.selenium.get('{}/text_read/{}'.format(self.live_server_url, text2.id))
#  
#         all_unknown_words = self.finds(By.XPATH, '//span[@wostatus=0]')
#         random_word = random.choice(all_unknown_words)
#         random_word.click()
#         print('Chosen word : ', random_word.text)
#         self.wait_until(By.CLASS_NAME, 'tooltiptext')
#         self.wait_until(By.XPATH, '//div[@id="bottomright"]/iframe[@id="dictwebpage"]')
#         time.sleep(60)
# 
#     def test_saving_one_unknownword(self):
#         language_2 = EnglishLanguagesFactory(owner=self.user_1)
#         Settings_currentlang_id.objects.get(owner=self.user_1).stvalue=language_2
#         text2 = TextsFactory(owner=self.user_1, language=language_2, text='''
#         This surplus will be carry over to the next season.
#         Do you carry the surplus over?
#         I like to carry this surplus''')
#         splitText(text2)
#         savedword = Words.objects.get(owner=self.user_1, wordtext="season")
#         self.assertEqual(savedword.status, 0) # is unknown for the moment
#         self.selenium.get('{}/text_read/{}'.format(self.live_server_url, text2.id))
#         word = self.find(By.XPATH, '//span[@wowordtext="season"]')
#         self.assertEqual(word.get_attribute('title'), 'season\r▶Unknown [?]')
#         word.click()
#         self.wait_until(By.CLASS_NAME, 'tooltiptext')
#         self.wait_until(By.XPATH, '//div[@id="bottomright"]/iframe[@id="dictwebpage"]')
#         trans_textarea = self.find(By.XPATH, '//textarea[@id="id_translation"]')
#         trans_textarea.send_keys('excédent')
#         self.find(By.XPATH, '//button[@id="submit_word"]').click()
#         self.wait_until(By.XPATH, '//div[@id="topright"][contains(.,"OK: Term saved.")]')
#         savedword = Words.objects.get(owner=self.user_1, wordtext="season")
#         self.assertEqual(savedword.status, 1) # and now is 'Learning'
#         word = self.find(By.XPATH, '//span[@wowordtext="season"]')
#         self.assertEqual(word.get_attribute('title'), 'season\r▶ excédent\r▶ Learning [1]')
#         
#     def test_saving_one_unknownword_saves_all_the_others(self):
#         language_2 = EnglishLanguagesFactory(owner=self.user_1)
#         Settings_currentlang_id.objects.get(owner=self.user_1).stvalue=language_2
#         text2 = TextsFactory(owner=self.user_1, language=language_2, text='''
#         This surplus will be carry over to the next season.
#         Do you carry the surplus over?
#         I like to carry this surplus''')
#         splitText(text2)
#         self.selenium.get('{}/text_read/{}'.format(self.live_server_url, text2.id))
# 
#         word = self.finds(By.XPATH, '//span[@wowordtext="surplus"]')
#         word[0].click()
#         self.wait_until(By.CLASS_NAME, 'tooltiptext')
#         self.wait_until(By.XPATH, '//div[@id="bottomright"]/iframe[@id="dictwebpage"]')
#         trans_textarea = self.find(By.XPATH, '//textarea[@id="id_translation"]')
#         trans_textarea.send_keys('excédent')
#         self.find(By.XPATH, '//button[@id="submit_word"]').click()
#         self.wait_until(By.XPATH, '//div[@id="topright"][contains(.,"OK: Term saved.")]')
#         savedwords = Words.objects.filter(owner=self.user_1, wordtext="surplus", status=1).count()
#         self.assertEqual(savedwords, 3)
# 
         
#     def test_deleting_one_compoundword(self):
#         language_2 = EnglishLanguagesFactory(owner=self.user_1)
#         Settings_currentlang_id.objects.get(owner=self.user_1).stvalue=language_2
#         text2 = TextsFactory(owner=self.user_1, language=language_2, text='''
#         Do you carry the surplus over?''')
#         splitText(text2)
#         first_word_inside = Words.objects.get( wordtext="carry")
#         second_word_inside = Words.objects.get( wordtext="over")
#         self.selenium.get('{}/text_read/{}'.format(self.live_server_url, text2.id))
#         first_word_before = self.find(By.XPATH, '//span[@wowordtext="carry"]')
#         first_word_before.click()
#         self.wait_until(By.CLASS_NAME, 'tooltiptext')
#         self.wait_until(By.XPATH, '//div[@id="bottomright"]/iframe[@id="dictwebpage"]')
#         second_word_before = self.find(By.XPATH, '//span[@wowordtext="over"]')
#         ActionChains(self.selenium).key_down(Keys.CONTROL).click(second_word_before).key_up(Keys.CONTROL).perform()
# 
#         self.wait_until(By.XPATH, '//textarea[@id="id_sentence"][contains(.,"{carry} the surplus {over}")]') 
#         
#         trans_textarea = self.find(By.XPATH, '//textarea[@id="id_translation"]')
#         trans_textarea.send_keys('excédent')
#         self.wait_until(By.XPATH, '//button[@id="submit_word"]')
#         self.find(By.XPATH, '//button[@id="submit_word"]').click()
#         self.wait_until(By.XPATH, '//div[@id="topright"][contains(.,"OK: Term saved.")]')
# 
#         # deleting the compound word:
#         self.find(By.XPATH, '//span[@wowordtext="carry"]').click()
# 
#         self.find(By.XPATH, '//a[contains(.,"Delete term")]').click()
#         self.wait_until(By.XPATH, '//div[@id="topright"][contains(.,"OK: term deleted")]')
# 
#         compoundword = Words.objects.filter(isCompoundword=True, isnotword=True).all()
#         self.assertEqual(len(compoundword), 0) # and now is 'Unknown'
#         first_word_inside = Words.objects.get( wordtext="carry")
#         second_word_inside = Words.objects.get( wordtext="over")
#         self.assertEqual(first_word_inside.compoundword, None) # and now is 'Learning'
#         self.assertEqual(second_word_inside.compoundword, None) # and now is 'Learning'
#         self.assertEqual(first_word_inside.show_compoundword, False) # and now is 'Learning'
#         # and good css:
#         firstword_after = self.find(By.XPATH, '//span[@wowordtext="carry"]')
#         secondword_after = self.find(By.XPATH, '//span[@wowordtext="over"]')
#         self.assertEqual(firstword_after.get_attribute('cowostatus'), '0')
#         self.assertEqual(secondword_after.get_attribute('cowostatus'), '0')
#         self.assertEqual(firstword_after.get_attribute('show_compoundword'), 'False')
#         self.assertEqual(firstword_after.get_attribute('iscompoundword'), 'False')
#         self.assertEqual(firstword_after.get_attribute('title'), 'carry\r▶ Unknown [?]')
# 
#     def test_toggling_show_compoundword(self):
#         language_2 = EnglishLanguagesFactory(owner=self.user_1)
#         Settings_currentlang_id.objects.get(owner=self.user_1).stvalue=language_2
#         text2 = TextsFactory(owner=self.user_1, language=language_2, text='''
#         Do you carry the surplus over?''')
#         splitText(text2)
# 
#         self.selenium.get('{}/text_read/{}'.format(self.live_server_url, text2.id))
#         first_word_before = self.find(By.XPATH, '//span[@wowordtext="carry"]')
#         first_word_before.click()
#         self.wait_until(By.CLASS_NAME, 'tooltiptext')
#         self.wait_until(By.XPATH, '//div[@id="bottomright"]/iframe[@id="dictwebpage"]')
#         second_word_before = self.find(By.XPATH, '//span[@wowordtext="over"]')
#         ActionChains(self.selenium).key_down(Keys.CONTROL).click(second_word_before).key_up(Keys.CONTROL).perform()
# 
#         self.wait_until(By.XPATH, '//textarea[@id="id_sentence"][contains(.,"{carry} the surplus {over}")]') 
# 
#         trans_textarea = self.find(By.XPATH, '//textarea[@id="id_translation"]')
#         trans_textarea.send_keys('excédent')
#         self.find(By.XPATH, '//button[@id="submit_word"]').click()
#         self.wait_until(By.XPATH, '//div[@id="topright"][contains(.,"OK: Term saved.")]')
#         # in DB
#         first_word_DB = Words.objects.get( wordtext="carry")
#         second_word_DB = Words.objects.get( wordtext="over")
#         self.assertEqual(first_word_DB.show_compoundword, True) 
#         self.assertEqual(second_word_DB.show_compoundword, True) 
#         
#         # check untoggling 
#         self.find(By.XPATH, '//span[@wowordtext="carry"]').click()
#         self.find(By.XPATH, '//input[@name="show_compoundword_checkbox"]').click()
#         # check the status of both words
#         # in DB:
#         first_word_DB = Words.objects.get( wordtext="carry")
#         second_word_DB = Words.objects.get( wordtext="over")
#         self.assertEqual(first_word_DB.show_compoundword, False) 
#         self.assertEqual(second_word_DB.show_compoundword, False)
#         # in HTML:
#         first_word = self.find(By.XPATH, '//span[@wowordtext="carry"]')
#         second_word = self.find(By.XPATH, '//span[@wowordtext="over"]')
#         self.assertEqual(first_word.get_attribute('show_compoundword'), 'false')
#         self.assertEqual(second_word.get_attribute('show_compoundword'), 'false')
# 
#         # and toggling again 
#         self.find(By.XPATH, '//span[@wowordtext="carry"]').click()
#         self.find(By.XPATH, '//input[@name="show_compoundword_checkbox"]').click()
#         # check the status of both words
#         # in DB:
#         first_word_DB = Words.objects.get( wordtext="carry")
#         second_word_DB = Words.objects.get( wordtext="over")
#         self.assertEqual(first_word_DB.show_compoundword, True) 
#         self.assertEqual(second_word_DB.show_compoundword, True)
#         # in HTML:
#         first_word = self.find(By.XPATH, '//span[@wowordtext="carry"]')
#         second_word = self.find(By.XPATH, '//span[@wowordtext="over"]')
#         self.assertEqual(first_word.get_attribute('show_compoundword'), 'true')
#         self.assertEqual(second_word.get_attribute('show_compoundword'), 'true')