Package omeroweb :: Package webadmin :: Package tests :: Module seleniumtests
[hide private]
[frames] | no frames]

Source Code for Module omeroweb.webadmin.tests.seleniumtests

  1  #!/usr/bin/env python 
  2  # 
  3  # 
  4  # 
  5  # Copyright (c) 2008 University of Dundee.  
  6  # 
  7  # This program is free software: you can redistribute it and/or modify 
  8  # it under the terms of the GNU Affero General Public License as 
  9  # published by the Free Software Foundation, either version 3 of the 
 10  # License, or (at your option) any later version. 
 11  # 
 12  # This program is distributed in the hope that it will be useful, 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 15  # GNU Affero General Public License for more details. 
 16  # 
 17  # You should have received a copy of the GNU Affero General Public License 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 19  # 
 20   
 21  import os 
 22  import omero 
 23  from omeroweb.webgateway.tests.seleniumbase import SeleniumTestBase, Utils 
 24  from random import random 
 25  from django.conf import settings 
 26   
27 -def createGroup(sel, groupName):
28 """ 29 Helper method for creating a new group with the give name. 30 Must be logged in as root. Creates a private group. 31 Returns groupId if creation sucessful (the groups page displays new group name) 32 Otherwise returns 0 33 """ 34 sel.open("/webadmin/groups") 35 sel.click("link=Add new group") 36 sel.wait_for_page_to_load("30000") 37 sel.type("id_name", groupName) 38 sel.click("//input[@value='Save']") 39 sel.wait_for_page_to_load("30000") 40 41 gId = 0 42 if sel.is_element_present("jquery=#groupTable tbody tr td:containsExactly(%s)" % groupName): 43 # find group in the table 44 i = 1 45 while sel.get_text("//table[@id='groupTable']/tbody/tr[%s]/td[2]" % i) != groupName: 46 i+=1 47 # raises exception if out of bounds for the html table 48 idTxt = sel.get_text("//table[@id='groupTable']/tbody/tr[%s]/td[1]" % i) 49 gId = long(idTxt.strip("id:")) 50 return gId
51 52
53 -def createExperimenter(sel, omeName, groupNames, password="ome", firstName="Selenium", lastName="Test"):
54 """ 55 Helper method for creating an experimenter in the specified group. 56 The group 'groupName' must already exist. 57 Returns the expId if experimenter created successfully (omeName is found in table of experimenters) 58 Otherwise returns 0 59 """ 60 sel.open("/webadmin/experimenters") 61 sel.click("link=Add new scientist") 62 sel.wait_for_page_to_load("30000") 63 sel.type("id_omename", omeName) 64 sel.type("id_first_name", firstName) 65 sel.type("id_last_name", lastName) 66 sel.type("id_password", password) 67 sel.type("id_confirmation", password) 68 69 # choose existing group, add to new user, choose one as default group 70 for gName in groupNames: 71 sel.add_selection("id_available_groups", "label=%s" % gName) 72 sel.click("add") 73 sel.click("default_group") 74 sel.click("//input[@value='Save']") 75 sel.wait_for_page_to_load("30000") 76 77 eId = 0 78 if sel.is_element_present("jquery=#experimenterTable tbody tr td:containsExactly(%s)" % omeName): 79 # try to get experimenter ID, look in the table 80 i = 0 # jquery selector uses 0-based index 81 while sel.get_text('jquery=#experimenterTable tbody tr td.action+td+td:eq(%d)' % i) != omeName: 82 i+=1 83 # raises exception if out of bounds for the html table 84 idTxt = sel.get_text("//table[@id='experimenterTable']/tbody/tr[%d]/td[1]" % (i+1) ) # 1-based index 85 eId = long(idTxt.strip("id:")) # 'id:123' 86 87 return eId
88
89 -class WebAdminTestBase (SeleniumTestBase):
90
91 - def login (self, u, p, sid):
92 sel = self.selenium 93 if self.selenium.is_element_present('link=Log out'): 94 self.logout() 95 sel.open("/webadmin/login") 96 sel.type("id_username", u) 97 sel.type("id_password", p) 98 sel.type("id_server", sid) 99 sel.click("//input[@value='Connect']") 100 self.waitForElementPresence('link=Scientists')
101
102 - def logout (self):
103 self.selenium.click("link=Logout") 104 self.selenium.wait_for_page_to_load("30000") 105 self.waitForElementPresence("//input[@value='Connect']")
106 107
108 -class AdminTests (WebAdminTestBase):
109
110 - def setUp(self):
111 super(AdminTests, self).setUp() 112 113 c = omero.client(pmap=['--Ice.Config='+(os.environ.get("ICE_CONFIG"))]) 114 try: 115 root_password = c.ic.getProperties().getProperty('omero.rootpass') 116 omero_host = c.ic.getProperties().getProperty('omero.host') 117 finally: 118 c.__del__() 119 server_id = settings.SERVER_LIST.find(server_host=omero_host).id 120 self.login('root', root_password, server_id)
121 122
123 - def testPages (self):
124 """ 125 This checks that the links exist for the main pages. 126 Visits each page in turn. Starts at experimenters and clicks links to each other main page ' 127 """ 128 # login done already in setUp() 129 130 sel = self.selenium 131 sel.open("/webadmin/experimenters") 132 sel.wait_for_page_to_load("30000") 133 self.assertEqual("WebAdmin - Scientists", sel.get_title()) 134 sel.click("link=Groups") 135 sel.wait_for_page_to_load("30000") 136 sel.click("link=My Account") 137 sel.wait_for_page_to_load("30000") 138 sel.click("link=Drive Space") 139 sel.wait_for_page_to_load("30000")
140 141
142 - def testCreateExperimenter (self):
143 """ 144 Creates a new experimenter (creates group first). Tests that ommiting to fill 145 in 'ome-name' gives a correct message to user. 146 Checks that the new user is displayed in the table of experimenters. 147 """ 148 #print "testCreateExperimenter" #print 149 150 groupName = "Selenium-testCreateExp%s" % random() 151 152 # uuid = self.root.sf.getAdminService().getEventContext().sessionUuid 153 uuid = random() 154 omeName = 'OmeName%s' % uuid 155 firstName = 'Selenium' 156 lastName = 'Test' 157 password = 'secretPassword' 158 159 # first create a group for the new experimenter 160 sel = self.selenium 161 self.assertTrue(createGroup(sel, groupName)) 162 163 sel.open("/webadmin/experimenters") 164 sel.click("link=Add new scientist") 165 sel.wait_for_page_to_load("30000") 166 # Don't fill out omeName here. 167 sel.type("id_first_name", firstName) 168 sel.type("id_last_name", lastName) 169 sel.type("id_password", password) 170 sel.type("id_confirmation", password) 171 172 # choose existing group, add to new user, choose one as default group 173 sel.add_selection("id_available_groups", "label=%s" % groupName) 174 sel.click("add") 175 sel.click("default_group") 176 sel.click("//input[@value='Save']") 177 sel.wait_for_page_to_load("30000") 178 179 # check that we failed to create experimenter - ome-name wasn't filled out 180 self.failUnless(sel.is_text_present("This field is required.")) 181 sel.type("id_omename", omeName) 182 sel.click("//input[@value='Save']") 183 sel.wait_for_page_to_load("30000") 184 185 # check omeName and 'Full Name' are on the page of Scientists. 186 self.assertEqual("WebAdmin - Scientists", sel.get_title()) 187 self.failUnless(sel.is_text_present(omeName)) 188 self.failUnless(sel.is_text_present("%s %s" % (firstName, lastName))) 189 # better to check text in right place 190 self.assert_(sel.is_element_present("jquery=#experimenterTable tbody tr td:containsExactly(%s)" % omeName))
191 192
193 - def testCreateGroup(self):
194 """ 195 This needs to run before testCreateExperimenter() 196 """ 197 #print "testCreateGroup" 198 groupName = "Selenium-testCreateGroup%s" % random() 199 200 sel = self.selenium 201 # check new Group is on the page of Groups. 202 gId = createGroup(sel, groupName) 203 self.assertTrue(gId > 0)
204 205
206 - def testRemoveExpFromGroup(self):
207 208 #print "testRemoveExpFromGroup" 209 210 groupName1 = "Sel-test1%s" % random() 211 groupName2 = "Sel-test2%s" % random() 212 groupName3 = "Sel-test3%s" % random() 213 214 omeName = 'OmeName%s' % random() 215 firstName = 'Selenium' 216 lastName = 'Test' 217 password = 'secretPassword' 218 sel = self.selenium 219 220 # first create groups and a new experimenter in both groups 221 group1Id = createGroup(sel, groupName1) 222 self.assertTrue(group1Id > 0) 223 group2Id = createGroup(sel, groupName2) 224 self.assertTrue(group2Id > 0) 225 group3Id = createGroup(sel, groupName3) 226 self.assertTrue(group2Id > 0) 227 228 # create the experimenter in 2 groups 229 eId = createExperimenter(sel, omeName, [groupName1, groupName2]) 230 self.assertTrue(eId > 0) 231 sel.open("/webadmin/experimenter/edit/%d" % eId) 232 sel.wait_for_page_to_load("30000") 233 self.assertEqual("WebAdmin - Edit scientist", sel.get_title()) 234 235 # try promoting the user to admin and adding to new group, making that group the default 236 sel.click("id_administrator") 237 sel.add_selection("id_available_groups", "label=%s" % groupName3) 238 sel.click("add") 239 self.waitForElementVisibility('id_default_group_%d' % group3Id, True) # radio button for 'default group' 240 sel.click('id_default_group_%d' % group3Id) 241 242 # try remove one of the original groups 243 sel.click("default_group_%d" % group1Id) 244 #self.waitForElementVisibility('id_default_group_%d' % group1Id, False) 245 self.waitForElementVisibility('default_group_%d' % group1Id, False) # BUG: this is not working at the moment. 246 247 # save 248 sel.click("//input[@value='Save']") 249 sel.wait_for_page_to_load("30000") 250 251 # find experimenter in table - look for 'admin' icon 252 i = 1 253 while sel.get_text("//table[@id='experimenterTable']/tbody/tr[%s]/td[3]" % i) != omeName: 254 i+=1 255 # raises exception if out of bounds for the html table 256 self.assert_(sel.is_element_present("//table[@id='experimenterTable']/tbody/tr[%s]/td[5]/img[@alt='admin']" % i))
257 258
259 - def tearDown(self):
260 self.logout() 261 super(AdminTests, self).tearDown()
262 263 264 if __name__ == "__main__": 265 Utils.runAsScript('webadmin') 266