test_rwt_nav.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 from selenium.webdriver.support.ui import Select
49 
50 import pkg_resources
51 selenium_version = pkg_resources.get_distribution("selenium").version
52 # Check if selenium version is greater than 4.3.0
53 if pkg_resources.parse_version(selenium_version) >= pkg_resources.parse_version("4.3.0"):
54  from selenium.webdriver.common.by import By
55 
56 from move_base_msgs.msg import MoveBaseActionGoal
57 
58 CLASSNAME = 'rwt_nav'
59 
60 class TestRwtNav(unittest.TestCase):
61 
62  def goal_cb(self, msg):
63  rospy.logwarn("{} received".format(msg))
64  self.goal_msg = msg
66 
67  def __init__(self, *args):
68  super(TestRwtNav, self).__init__(*args)
69  rospy.init_node('test_rwt_nav')
70 
71  def setUp(self):
72  parser = argparse.ArgumentParser()
73  parser.add_argument('--no-headless', action='store_true',
74  help='start webdriver with headless mode')
75  args, unknown = parser.parse_known_args()
76 
77  self.goal_msg = None
78  self.goal_msg_received = 0
79 
80  rospy.Subscriber('/move_base/goal', MoveBaseActionGoal, self.goal_cb)
81  self.url_base = rospy.get_param("url_roswww_testserver")
82 
83  opts = webdriver.firefox.options.Options()
84  if not args.no_headless:
85  opts.add_argument('-headless')
86  self.browser = webdriver.Firefox(options=opts)
87 
88  self.wait = webdriver.support.ui.WebDriverWait(self.browser, 10)
89  # maximize screen
90  if pkg_resources.parse_version(selenium_version) >= pkg_resources.parse_version("4.3.0"):
91  self.browser.fullscreen_window()
92  else:
93  self.browser.find_element_by_tag_name("html").send_keys(Keys.F11)
94 
95  def tearDown(self):
96  try:
97  self.browser.close()
98  self.browser.quit()
99  except:
100  pass
101 
102  def test_rwt_nav(self):
103  url = '%s/rwt_nav' % (self.url_base)
104  rospy.logwarn("Accessing to %s" % url)
105 
106  self.browser.get(url)
107 
108  # check settings
109  self.wait.until(EC.presence_of_element_located((By.ID, "button-ros-master-settings")))
110  settings = self.find_element_by_id("button-ros-master-settings")
111  self.assertIsNotNone(settings, "Object id=button-ros-master-settings not found")
112  settings.click()
113 
114  self.wait.until(EC.presence_of_element_located((By.ID, "input-ros-master-uri")))
115  uri = self.find_element_by_id("input-ros-master-uri")
116  self.assertIsNotNone(uri, "Object id=input-ros-master-uri not found")
117  uri.clear();
118  uri.send_keys('ws://localhost:9090/')
119 
120  self.wait.until(EC.presence_of_element_located((By.ID, "button-ros-master-connect")))
121  connect = self.find_element_by_id("button-ros-master-connect")
122  self.assertIsNotNone(connect, "Object id=button-ros-master-connect")
123  connect.click()
124 
125  # check image topic
126  self.wait.until(EC.presence_of_element_located((By.ID, "image-topic-select")))
127  image_topic = self.find_element_by_id("image-topic-select")
128  self.assertIsNotNone(image_topic, "Object id=topic-select not found")
129  loop = 0
130  while image_topic.text == u'' and loop < 10:
131  loop = loop + 1
132  time.sleep(1)
133  image_topic = self.find_element_by_id("image-topic-select")
134  self.assertIsNotNone(image_topic, "Object id=image-topic-select not found")
135  self.assertEqual(image_topic.text, u'/image_publisher/image_raw')
136 
137  # wait for /map topic
138  self.wait.until(EC.presence_of_element_located((By.ID, "map")))
139  map = self.find_element_by_id("map")
140  self.assertIsNotNone(map, "Object id=map not found")
141  map.click()
142 
143  loop = 0
144  while loop < 20 and self.goal_msg == None:
145  loop = loop + 1
146  time.sleep(1)
147  map.click()
148 
149  self.assertNotEqual(self.goal_msg, None)
150 
151  def find_element_by_id(self, name):
152  if pkg_resources.parse_version(selenium_version) >= pkg_resources.parse_version("4.3.0"):
153  return self.browser.find_element(By.ID, name)
154  else:
155  return self.browser.find_element_by_id(name)
156 
157 
158 if __name__ == '__main__':
159  try:
160  rostest.run('rwt_nav', CLASSNAME, TestRwtNav, sys.argv)
161  except KeyboardInterrupt:
162  pass
163  print("{} exiting".format(CLASSNAME))
test_rwt_nav.TestRwtNav.tearDown
def tearDown(self)
Definition: test_rwt_nav.py:95
test_rwt_nav.TestRwtNav.goal_msg
goal_msg
Definition: test_rwt_nav.py:64
test_rwt_nav.TestRwtNav.url_base
url_base
Definition: test_rwt_nav.py:81
test_rwt_nav.TestRwtNav
Definition: test_rwt_nav.py:60
test_rwt_nav.TestRwtNav.wait
wait
Definition: test_rwt_nav.py:88
test_rwt_nav.TestRwtNav.test_rwt_nav
def test_rwt_nav(self)
Definition: test_rwt_nav.py:102
test_rwt_nav.TestRwtNav.setUp
def setUp(self)
Definition: test_rwt_nav.py:71
test_rwt_nav.TestRwtNav.find_element_by_id
def find_element_by_id(self, name)
Definition: test_rwt_nav.py:151
test_rwt_nav.TestRwtNav.browser
browser
Definition: test_rwt_nav.py:86
test_rwt_nav.TestRwtNav.goal_msg_received
goal_msg_received
Definition: test_rwt_nav.py:65
test_rwt_nav.TestRwtNav.__init__
def __init__(self, *args)
Definition: test_rwt_nav.py:67
test_rwt_nav.TestRwtNav.goal_cb
def goal_cb(self, msg)
Definition: test_rwt_nav.py:62


rwt_nav
Author(s): Yug Ajmera , Shingo Kitagawa
autogenerated on Sat Jun 3 2023 02:43:56