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