test_rwt_speech_recognition.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.support.ui import WebDriverWait
55  from selenium.webdriver.common.by import By
56 
57 CLASSNAME = 'rwt_speech_recognition'
58 
59 class TestRwtSpeechRecognition(unittest.TestCase):
60 
61  def setUp(self):
62  parser = argparse.ArgumentParser()
63  parser.add_argument('--no-headless', action='store_true',
64  help='start webdriver with headless mode')
65  args, unknown = parser.parse_known_args()
66 
67  self.url_base = rospy.get_param("url_roswww_testserver")
68 
69  opts = webdriver.firefox.options.Options()
70  if not args.no_headless:
71  opts.add_argument('-headless')
72  self.browser = webdriver.Firefox(options=opts)
73 
74  self.wait = webdriver.support.ui.WebDriverWait(self.browser, 10)
75  # maximize screen
76  if pkg_resources.parse_version(selenium_version) >= pkg_resources.parse_version("4.3.0"):
77  self.browser.fullscreen_window()
78  else:
79  self.browser.find_element_by_tag_name("html").send_keys(Keys.F11)
80 
81  def tearDown(self):
82  try:
83  self.browser.close()
84  self.browser.quit()
85  except:
86  pass
87 
89  url = '%s/rwt_speech_recognition' % (self.url_base)
90  rospy.logwarn("Accessing to %s" % url)
91 
92  self.browser.get(url)
93 
94  # check settings
95  self.wait.until(EC.presence_of_element_located((By.ID, "button-ros-master-settings")))
96  settings = self.find_element_by_id("button-ros-master-settings")
97  self.assertIsNotNone(settings, "Object id=button-ros-master-settings not found")
98  settings.click()
99 
100  self.wait.until(EC.presence_of_element_located((By.ID, "input-ros-master-uri")))
101  uri = self.find_element_by_id("input-ros-master-uri")
102  self.assertIsNotNone(uri, "Object id=input-ros-master-uri not found")
103  uri.clear();
104  uri.send_keys('ws://localhost:9090/')
105 
106  self.wait.until(EC.presence_of_element_located((By.ID, "button-ros-master-connect")))
107  connect = self.find_element_by_id("button-ros-master-connect")
108  self.assertIsNotNone(connect, "Object id=button-ros-master-connect")
109  connect.click()
110 
111  # check language select
112  self.wait.until(EC.presence_of_element_located((By.ID, "select-language")))
113  select = Select(self.find_element_by_id("select-language"))
114  self.assertIsNotNone(select, "Object id=select-language not found")
115  select.select_by_visible_text('日本語')
116 
117  # TODO
118  # Could not test speech API...The driver says
119  # 'Web Speech API is not supported by this browser. '
120 
121  def find_element_by_id(self, name):
122  if pkg_resources.parse_version(selenium_version) >= pkg_resources.parse_version("4.3.0"):
123  return self.browser.find_element(By.ID, name)
124  else:
125  return self.browser.find_element_by_id(name)
126 
127 
128 if __name__ == '__main__':
129  try:
130  rostest.run('test_rwt_speech_recognition', CLASSNAME, TestRwtSpeechRecognition, sys.argv)
131  except KeyboardInterrupt:
132  pass
133  print("{} exiting".format(CLASSNAME))
test_rwt_speech_recognition.TestRwtSpeechRecognition
Definition: test_rwt_speech_recognition.py:59
test_rwt_speech_recognition.TestRwtSpeechRecognition.wait
wait
Definition: test_rwt_speech_recognition.py:74
test_rwt_speech_recognition.TestRwtSpeechRecognition.setUp
def setUp(self)
Definition: test_rwt_speech_recognition.py:61
test_rwt_speech_recognition.TestRwtSpeechRecognition.url_base
url_base
Definition: test_rwt_speech_recognition.py:67
test_rwt_speech_recognition.TestRwtSpeechRecognition.browser
browser
Definition: test_rwt_speech_recognition.py:72
test_rwt_speech_recognition.TestRwtSpeechRecognition.tearDown
def tearDown(self)
Definition: test_rwt_speech_recognition.py:81
test_rwt_speech_recognition.TestRwtSpeechRecognition.test_rwt_speech_recognition
def test_rwt_speech_recognition(self)
Definition: test_rwt_speech_recognition.py:88
test_rwt_speech_recognition.TestRwtSpeechRecognition.find_element_by_id
def find_element_by_id(self, name)
Definition: test_rwt_speech_recognition.py:121


rwt_speech_recognition
Author(s): Yuki Furuta
autogenerated on Sat Jun 3 2023 02:43:59