test_webapp.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # pylint: disable=missing-module-docstring,missing-function-docstring
  3. from time import sleep
  4. url = "http://localhost:11111/"
  5. def test_index(browser):
  6. # Visit URL
  7. browser.visit(url)
  8. assert browser.is_text_present('searxng')
  9. def test_404(browser):
  10. # Visit URL
  11. browser.visit(url + 'missing_link')
  12. assert browser.is_text_present('Page not found')
  13. def test_about(browser):
  14. browser.visit(url)
  15. browser.links.find_by_text('searxng').click()
  16. assert browser.is_text_present('Why use it?')
  17. def test_preferences(browser):
  18. browser.visit(url)
  19. browser.links.find_by_href('/preferences').click()
  20. assert browser.is_text_present('Preferences')
  21. assert browser.is_text_present('COOKIES')
  22. assert browser.is_element_present_by_xpath('//label[@for="checkbox_dummy"]')
  23. def test_preferences_engine_select(browser):
  24. browser.visit(url)
  25. browser.links.find_by_href('/preferences').click()
  26. assert browser.is_element_present_by_xpath('//label[@for="tab-engines"]')
  27. browser.find_by_xpath('//label[@for="tab-engines"]').first.click()
  28. assert not browser.find_by_xpath('//input[@id="engine_general_dummy__general"]').first.checked
  29. browser.find_by_xpath('//label[@for="engine_general_dummy__general"]').first.check()
  30. browser.find_by_xpath('//input[@type="submit"]').first.click()
  31. # waiting for the redirect - without this the test is flaky..
  32. sleep(1)
  33. browser.visit(url)
  34. browser.links.find_by_href('/preferences').click()
  35. browser.find_by_xpath('//label[@for="tab-engines"]').first.click()
  36. assert browser.find_by_xpath('//input[@id="engine_general_dummy__general"]').first.checked
  37. def test_preferences_locale(browser):
  38. browser.visit(url)
  39. browser.links.find_by_href('/preferences').click()
  40. browser.find_by_xpath('//label[@for="tab-ui"]').first.click()
  41. browser.select('locale', 'fr')
  42. browser.find_by_xpath('//input[@type="submit"]').first.click()
  43. # waiting for the redirect - without this the test is flaky..
  44. sleep(1)
  45. browser.visit(url)
  46. browser.links.find_by_href('/preferences').click()
  47. browser.is_text_present('Préférences')
  48. def test_search(browser):
  49. browser.visit(url)
  50. browser.fill('q', 'test search query')
  51. browser.find_by_xpath('//button[@type="submit"]').first.click()
  52. assert browser.is_text_present('No results were found')