annotate _ui_tests/utils.py @ 2936:cd48671a0488

Fixes Language Translation Issue
author Aabhas Majumdar <majumdaraabhas@gmail.com>
date Tue, 10 Mar 2015 00:42:12 +0530
parents 384555088cab
children
rev   line source
1782
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
1 # Copyright: 2012 MoinMoin:LiHaiyan
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
2 # Copyright: 2012 MoinMoin:HughPerkins
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
3 # License: GNU GPL v3 (or any later version), see LICENSE.txt for details.
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
4
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
5 """Functions to facilitate functional testing"""
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
6
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
7 import random
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1814
diff changeset
8 import urllib
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1814
diff changeset
9
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1814
diff changeset
10 import pytest
1784
4e236dcf39cd _ui_tests: skip if selenium is not installed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1782
diff changeset
11
4e236dcf39cd _ui_tests: skip if selenium is not installed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1782
diff changeset
12 try:
4e236dcf39cd _ui_tests: skip if selenium is not installed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1782
diff changeset
13 from selenium import webdriver
4e236dcf39cd _ui_tests: skip if selenium is not installed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1782
diff changeset
14 except ImportError:
4e236dcf39cd _ui_tests: skip if selenium is not installed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1782
diff changeset
15 pytest.skip('selenium needs to be installed for this test')
4e236dcf39cd _ui_tests: skip if selenium is not installed
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1782
diff changeset
16
1814
d9429dafe608 _ui_tests: skip if wiki server is not running
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1784
diff changeset
17 import config
d9429dafe608 _ui_tests: skip if wiki server is not running
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1784
diff changeset
18
d9429dafe608 _ui_tests: skip if wiki server is not running
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1784
diff changeset
19 try:
d9429dafe608 _ui_tests: skip if wiki server is not running
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1784
diff changeset
20 f = urllib.urlopen(config.BASE_URL)
d9429dafe608 _ui_tests: skip if wiki server is not running
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1784
diff changeset
21 except IOError:
d9429dafe608 _ui_tests: skip if wiki server is not running
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1784
diff changeset
22 pytest.skip('The UI tests need a wiki server running on %s' % config.BASE_URL)
d9429dafe608 _ui_tests: skip if wiki server is not running
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1784
diff changeset
23
1782
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
24 import driver_register
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
25
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
26
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
27 def create_browser():
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
28 """
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
29 Instantiates a firefox browser object, and configures it for English language
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
30 and registers it for screenshots, and sets the timeout
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
31 """
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
32 profile = webdriver.FirefoxProfile()
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
33 profile.set_preference("intl.accept_languages", "en")
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
34 driver = webdriver.Firefox(firefox_profile=profile)
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1814
diff changeset
35 driver_register.register_driver(driver) # register with
1782
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
36 # driver_register, which is needed so that printscreen on test
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
37 # failure works
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
38 driver.implicitly_wait(20)
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
39 return driver
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
40
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
41
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
42 def generate_random_word(length):
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
43 """
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
44 generates a random string containing numbers, of length 'length'
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
45 """
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1814
diff changeset
46 word = unicode(random.randint(10 ** (length - 1), 10 ** length))
1782
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
47 return word
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
48
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
49
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
50 def generate_random_name(prefix, totallength):
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
51 """
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
52 create a random name, starting with 'prefix'
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
53 of total length 'totallength'
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
54 """
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
55 length = totallength - len(prefix)
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
56 numberword = generate_random_word(length)
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
57 name = prefix + numberword
f87d2e646c60 created a first selenium test, specifically of adding subitems
Hugh Perkins <hughperkins@gmail.com>
parents:
diff changeset
58 return name