test_webapp.py 2.4 KB

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