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