comparison _ui_tests/test_subitems.py @ 1782:f87d2e646c60

created a first selenium test, specifically of adding subitems to an item
author Hugh Perkins <hughperkins@gmail.com>
date Tue, 18 Sep 2012 21:29:28 +0800
parents
children d7ed70f19dc3
comparison
equal deleted inserted replaced
1781:90eb2ea82c32 1782:f87d2e646c60
1 # Copyright: 2012 MoinMoin:HughPerkins
2 # License: GNU GPL v3 (or any later version), see LICENSE.txt for details.
3
4 """Functional test: create subitem"""
5
6 from selenium import webdriver
7
8 import config
9 import utils
10
11
12 class TestSubitems(object):
13 """Functional test: create subitem"""
14
15 def setup_class(self):
16 """opens browser and creates some random item names for these tests"""
17 self.driver = utils.create_browser()
18 self.base_url = config.BASE_URL
19 self.base_item_name = u"page_" + utils.generate_random_word(5)
20 self.subitem_name = u"subitem_" + utils.generate_random_word(5)
21
22 def create_wiki_item(self, item_name):
23 """Creates a new wiki item with name 'item_name'"""
24 driver = self.driver
25
26 driver.get(self.base_url + u"/" + item_name)
27 driver.find_element_by_link_text(u"Default").click()
28 driver.find_element_by_link_text(u"Wiki (MoinMoin)").click()
29 driver.find_element_by_link_text(
30 u"create the item from scratch").click()
31 driver.find_element_by_id("f_content_form_data_text").send_keys(
32 u"This is a test item\n")
33 driver.find_element_by_id("f_submit").click()
34
35 def test_createsubitem(self):
36 """Test create subitem"""
37 driver = self.driver
38
39 self.create_wiki_item(self.base_item_name)
40
41 driver.get(self.base_url + u"/" + self.base_item_name)
42 driver.find_element_by_link_text(u"Modify").click()
43 driver.find_element_by_id(u"f_content_form_data_text").send_keys(
44 u"\n[[/" + self.subitem_name + "]]\n")
45 driver.find_element_by_id(u"f_submit").click()
46 driver.find_element_by_link_text(u"/" + self.subitem_name).click()
47 driver.find_element_by_link_text(u"Default").click()
48 driver.find_element_by_link_text(u"Wiki (MoinMoin)").click()
49 driver.find_element_by_link_text(u"create the item from scratch").click()
50 driver.find_element_by_id(u"f_content_form_data_text").send_keys(
51 u"This is a test subitem")
52 driver.find_element_by_id(u"f_submit").click()
53 assert u"This is a test subitem" in driver.find_element_by_id(
54 u"moin-content-data").text
55 assert driver.title.split(u" - ")[0] == self.base_item_name + \
56 u"/" + self.subitem_name
57
58 def teardown_class(self):
59 """shuts down browser"""
60 self.driver.quit()
61
62 if __name__ == u'__main__':
63 # This lets us run the test directly, without using py.test
64 # This is useful for example for being able to call help, eg
65 # 'help(driver)', or 'help(driver.find_element_by_id("f_submit"))'
66 testSubitems = TestSubitems()
67 testSubitems.setup_class()
68 testSubitems.test_createsubitem()
69 testSubitems.teardown_class()