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

Source Code for Module omeroweb.webclient.tests.seleniumtests

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  # 
  4  # 
  5  # Copyright (C) 2011 University of Dundee & Open Microscopy Environment. 
  6  # All rights reserved. 
  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  from omeroweb.webgateway.tests.seleniumbase import SeleniumTestBase, Utils 
 23  from omero.gateway.scripts import dbhelpers 
 24  from random import random 
 25   
 26  import sys 
 27   
 28   
29 -class WebClientTestBase (SeleniumTestBase):
30 31
32 - def login (self, u, p):
33 sel = self.selenium 34 if self.selenium.is_element_present('link=Log out'): 35 self.logout() 36 sel.open("/webclient/login") 37 sel.type("id_username", u) 38 sel.type("id_password", p) 39 sel.click("//input[@value='Connect']")
40
41 - def logout (self):
42 self.selenium.open("/webclient/logout") 43 self.selenium.wait_for_page_to_load("30000") 44 self.waitForElementPresence("//input[@value='Connect']")
45 46
47 - def import_image(self, filename = None):
48 """ 49 This code from OmeroPy/tests/integration/library.py 50 TODO: Trying to find a way to do import from here, but no luck yet. 51 """ 52 #server = self.client.getProperty("omero.host") 53 #port = self.client.getProperty("omero.port") 54 #key = self.client.getSessionId() 55 server = 'localhost' 56 port = '4064' 57 key = '' 58 59 if filename is None: 60 filename = self.OmeroPy / ".." / ".." / ".." / "components" / "common" / "test" / "tinyTest.d3d.dv" 61 62 # Search up until we find "OmeroPy" 63 dist_dir = self.OmeroPy / ".." / ".." / ".." / "dist" 64 args = [sys.executable] 65 args.append(str(path(".") / "bin" / "omero")) 66 args.extend(["-s", server, "-k", key, "-p", port, "import", filename]) 67 popen = subprocess.Popen(args, cwd=str(dist_dir), stdout=subprocess.PIPE, stderr=subprocess.PIPE) 68 out, err = popen.communicate() 69 rc = popen.wait() 70 if rc != 0: 71 raise Exception("import failed: [%r] %s\n%s" % (args, rc, err)) 72 pix_ids = [] 73 for x in out.split("\n"): 74 if x and x.find("Created") < 0 and x.find("#") < 0: 75 try: # if the line has an image ID... 76 imageId = str(long(x.strip())) 77 pix_ids.append(imageId) 78 except: pass 79 return pix_ids
80 81
82 -class WebClientTests (WebClientTestBase):
83 84 from omero.gateway.scripts import dbhelpers 85
86 - def setUp(self):
87 super(WebClientTests, self).setUp() 88 #dbhelpers.refreshConfig() 89 #user = dbhelpers.ROOT.name 90 #password = dbhelpers.ROOT.passwd 91 #print user, password # seems to always be 'root', 'ome' 92 self.login('will', 'ome')
93 94
95 - def testMetadata (self):
96 """ 97 Displays the metadata page for an image. 98 """ 99 100 #print "testMetadata" 101 102 sel = self.selenium 103 sel.open("/webclient/metadata_details/image/4183") 104 #sel.click("link=Metadata") # Making metadata 'visible' to user is unecessary for tests below 105 self.assertEqual("480 x 480 x 46 x 1", sel.get_table("//div[@id='metadata_tab']/table[2].0.1")) 106 107 # Check channel names... 108 self.failUnless(sel.is_text_present("DAPI")) # anywhere on page 109 # more specific (too fragile?) 110 self.assertEqual("DAPI", sel.get_text("//div[@id='metadata_tab']/h1[5]/span")) 111 self.assertEqual("FITC", sel.get_text("//div[@id='metadata_tab']/h1[6]/span")) 112 self.assertEqual("RD-TR-PE", sel.get_text("//div[@id='metadata_tab']/h1[7]/span")) 113 self.assertEqual("CY-5", sel.get_text("//div[@id='metadata_tab']/h1[8]/span")) 114 115 # check value of Channel inputs. 116 self.assertEqual("DAPI", sel.get_value("//div[@id='metadata_tab']/div[4]/table/tbody/tr[1]/td[2]/input")) # Name 117 self.assertEqual("360", sel.get_value("//div[@id='metadata_tab']/div[4]/table/tbody/tr[2]/td[2]/input")) # Excitation 118 self.assertEqual("457", sel.get_value("//div[@id='metadata_tab']/div[4]/table/tbody/tr[3]/td[2]/input")) # Excitation 119 120 # using id='id_name' gets us the FIRST element with that id (currently 1 per channel) 121 self.assertEqual("DAPI", sel.get_value("//input[@id='id_name']"))
122 123
124 - def tearDown(self):
125 self.logout() 126 super(WebClientTests, self).tearDown()
127 128 129 if __name__ == "__main__": 130 Utils.runAsScript('webadmin') 131