view _ui_tests/utils.py @ 2960:b2417a0dd48f tip

trivial change to prevent traceback when 0 is passed to TableOfContents macro
author RogerHaase <haaserd@gmail.com>
date Thu, 18 Jun 2015 15:31:51 -0700
parents 384555088cab
children
line wrap: on
line source
# Copyright: 2012 MoinMoin:LiHaiyan
# Copyright: 2012 MoinMoin:HughPerkins
# License: GNU GPL v3 (or any later version), see LICENSE.txt for details.

"""Functions to facilitate functional testing"""

import random
import urllib

import pytest

try:
    from selenium import webdriver
except ImportError:
    pytest.skip('selenium needs to be installed for this test')

import config

try:
    f = urllib.urlopen(config.BASE_URL)
except IOError:
    pytest.skip('The UI tests need a wiki server running on %s' % config.BASE_URL)

import driver_register


def create_browser():
    """
    Instantiates a firefox browser object, and configures it for English language
    and registers it for screenshots, and sets the timeout
    """
    profile = webdriver.FirefoxProfile()
    profile.set_preference("intl.accept_languages", "en")
    driver = webdriver.Firefox(firefox_profile=profile)
    driver_register.register_driver(driver)  # register with
    # driver_register, which is needed so that printscreen on test
    # failure works
    driver.implicitly_wait(20)
    return driver


def generate_random_word(length):
    """
    generates a random string containing numbers, of length 'length'
    """
    word = unicode(random.randint(10 ** (length - 1), 10 ** length))
    return word


def generate_random_name(prefix, totallength):
    """
    create a random name, starting with 'prefix'
    of total length 'totallength'
    """
    length = totallength - len(prefix)
    numberword = generate_random_word(length)
    name = prefix + numberword
    return name