test_rwt_image_view.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2021, Kei Okada
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above
16 # copyright notice, this list of conditions and the following
17 # disclaimer in the documentation and/or other materials provided
18 # with the distribution.
19 # * Neither the name of the Copyright holder. nor the
20 # names of its contributors may be used to endorse or promote products
21 # derived from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 # POSSIBILITY OF SUCH DAMAGE.
35 #
36 
37 import argparse
38 import sys
39 import time
40 import rospy
41 import rostest
42 import unittest
43 
44 from selenium import webdriver
45 from selenium.webdriver.common.keys import Keys
46 from selenium.webdriver.common.by import By
47 from selenium.webdriver.support import expected_conditions as EC
48 
49 import pkg_resources
50 selenium_version = pkg_resources.get_distribution("selenium").version
51 # Check if selenium version is greater than 4.3.0
52 if pkg_resources.parse_version(selenium_version) >= pkg_resources.parse_version("4.3.0"):
53  from selenium.webdriver.support.ui import WebDriverWait
54  from selenium.webdriver.common.by import By
55 
56 CLASSNAME = 'rwt_image_view'
57 
58 class TestRwtImageView(unittest.TestCase):
59 
60  def setUp(self):
61  parser = argparse.ArgumentParser()
62  parser.add_argument('--no-headless', action='store_true',
63  help='start webdriver with headless mode')
64  args, unknown = parser.parse_known_args()
65 
66  self.url_base = rospy.get_param("url_roswww_testserver")
67 
68  opts = webdriver.firefox.options.Options()
69  if not args.no_headless:
70  opts.add_argument('-headless')
71  self.browser = webdriver.Firefox(options=opts)
72 
73  self.wait = webdriver.support.ui.WebDriverWait(self.browser, 10)
74  # maximize screen
75  if pkg_resources.parse_version(selenium_version) >= pkg_resources.parse_version("4.3.0"):
76  self.browser.fullscreen_window()
77  else:
78  self.browser.find_element_by_tag_name("html").send_keys(Keys.F11)
79 
80  def tearDown(self):
81  try:
82  self.browser.close()
83  self.browser.quit()
84  except:
85  pass
86 
88  url = '%s/rwt_image_view' % (self.url_base)
89  rospy.logwarn("Accessing to %s" % url)
90 
91  self.browser.get(url)
92 
93  # check settings
94  self.wait.until(EC.presence_of_element_located((By.ID, "button-ros-master-settings")))
95  settings = self.find_element_by_id("button-ros-master-settings")
96  self.assertIsNotNone(settings, "Object id=button-ros-master-settings not found")
97  settings.click()
98 
99  self.wait.until(EC.presence_of_element_located((By.ID, "input-ros-master-uri")))
100  uri = self.find_element_by_id("input-ros-master-uri")
101  self.assertIsNotNone(uri, "Object id=input-ros-master-uri not found")
102  uri.clear();
103  uri.send_keys('ws://localhost:9090/')
104 
105  self.wait.until(EC.presence_of_element_located((By.ID, "button-ros-master-connect")))
106  connect = self.find_element_by_id("button-ros-master-connect")
107  self.assertIsNotNone(connect, "Object id=button-ros-master-connect")
108  connect.click()
109 
110  # check image topic
111  self.wait.until(EC.presence_of_element_located((By.ID, "topic-select")))
112  topic = self.find_element_by_id("topic-select")
113  self.assertIsNotNone(topic, "Object id=topic-select not found")
114  loop = 0
115  while topic.text == u'' and loop < 10:
116  loop = loop + 1
117  time.sleep(1)
118  topic = self.find_element_by_id("topic-select")
119  self.assertIsNotNone(topic, "Object id=topic-select not found")
120  self.assertEqual(topic.text, u'/image_publisher/image_raw')
121 
122  def find_element_by_id(self, name):
123  if pkg_resources.parse_version(selenium_version) >= pkg_resources.parse_version("4.3.0"):
124  return self.browser.find_element(By.ID, name)
125  else:
126  return self.browser.find_element_by_id(name)
127 
128 
129 if __name__ == '__main__':
130  try:
131  rostest.run('test_rwt_image_view', CLASSNAME, TestRwtImageView, sys.argv)
132  except KeyboardInterrupt:
133  pass
134  print("{} exiting".format(CLASSNAME))


rwt_image_view
Author(s): Ryohei Ueda , Yuki Furuta
autogenerated on Fri Jun 2 2023 02:53:31