~erobererunc/sahana-eden/tropo_xforms

« back to all changes in this revision

Viewing changes to static/selenium/scripts/createTestAccount.py

  • Committer: Michael
  • Date: 2010-12-16 13:45:28 UTC
  • mfrom: (1479.1.91 eden)
  • Revision ID: ero@gmail.com-20101216134528-7x3m6m3fk9uc9i69
mergeĀ fromĀ trunk...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
import unittest, time, re
 
3
import testSuite
 
4
import actions
 
5
 
 
6
class CreateTestAccount(unittest.TestCase):
 
7
    
 
8
 
 
9
    def setUp(self):
 
10
        self.selenium = testSuite.SahanaTestSuite.selenium
 
11
        self.user = testSuite.SahanaTestSuite.user;
 
12
        self.password = testSuite.SahanaTestSuite.password;
 
13
        self.action = actions.Action()
 
14
    
 
15
    def test_create_test_accounts(self):
 
16
        sel = self.selenium
 
17
        
 
18
        # *** NOTE this script needs to be run by a user with Administrator privileges. END NOTE ***
 
19
        self.action.login(self, self.user, self.password, False)
 
20
        # This script creates a test account with the user name of admin@example.com the account is given administrator rights and can be used throughout the testing suite.
 
21
        # The user admin@example.com will be deleted by the "Delete Test Account" test case.
 
22
        sel.open("/eden/admin/user")
 
23
        self.failUnless(sel.is_element_present("show-add-btn"))
 
24
        sel.click("show-add-btn")
 
25
        sel.type("auth_user_first_name", "Admin")
 
26
        sel.type("auth_user_last_name", "User")
 
27
        sel.select("auth_user_language", "label=English")
 
28
        sel.type("auth_user_email", "admin@example.com")
 
29
        sel.type("auth_user_password", "testing")
 
30
        sel.click("//input[@value='Save']")
 
31
        sel.wait_for_page_to_load("30000")
 
32
        # Now that the user has been created search for this user using the list filter so that the "Administrator" role can be added to it.
 
33
        # The search filter is part of the http://datatables.net/ JavaScript getting it to work with Selenium needs a bit of care.
 
34
        # Entering text in the filter textbox doesn't always trigger off the filtering and it is not possible with this method to clear the filter.
 
35
        # The solution is to put in a call to the DataTables API, namely the fnFilter function
 
36
        # However, the first time that the fnFilter() is called in the testing suite it doesn't complete the processing, hence it is called twice.
 
37
        sel.run_script("oTable = $('#list').dataTable();  oTable.fnFilter( '' );")
 
38
        sel.run_script("oTable = $('#list').dataTable();  oTable.fnFilter( 'admin@example.com' );")
 
39
        for i in range(60):
 
40
            try:
 
41
                if re.search(r"^[\s\S]*1 entries[\s\S]*$", sel.get_text("//div[@class='dataTables_info']")): break
 
42
            except: pass
 
43
            time.sleep(1)
 
44
        else: self.fail("time out")
 
45
        sel.click("link=Open")
 
46
        sel.wait_for_page_to_load("30000")
 
47
        sel.click("//div[@id='content']/a[2]")
 
48
        sel.wait_for_page_to_load("30000")
 
49
        sel.click("auth_membership_group_id")
 
50
        sel.select("auth_membership_group_id", "label=1: Administrator")
 
51
        sel.click("//input[@value='Add']")
 
52
        sel.wait_for_page_to_load("30000")
 
53
 
 
54
        # This script creates a test account with the user name of user@example.com which is not given administrator rights and should be used throughout the testing suite.
 
55
        # The user user@example.com will be deleted by the "Delete Test Account" test case.
 
56
        sel.open("/eden/admin/user")
 
57
        self.failUnless(sel.is_element_present("show-add-btn"))
 
58
        sel.click("show-add-btn")
 
59
        sel.type("auth_user_first_name", "Normal")
 
60
        sel.type("auth_user_last_name", "User")
 
61
        sel.select("auth_user_language", "label=English")
 
62
        sel.type("auth_user_email", "user@example.com")
 
63
        sel.type("auth_user_password", "testing")
 
64
        sel.click("//input[@value='Save']")
 
65
        sel.wait_for_page_to_load("30000")
 
66
 
 
67
        # Log out from the current "Administrator" user and log back in for the remaining test cases as admin@example.com
 
68
        #sel.click("link=Logout")
 
69
        #sel.wait_for_page_to_load("30000")
 
70
        #self.action.login(self, "admin@example.com", "testing" )
 
71
        #sel.click("link=Logout")
 
72
        #sel.wait_for_page_to_load("30000")
 
73
    
 
74
 
 
75
 
 
76
if __name__ == "__main__":
 
77
    unittest.main()