test_text_edit.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. import inspect
  12. import logging
  13. from importlib import util
  14. import pytest
  15. if util.find_spec("playwright"):
  16. from playwright._impl._page import Page
  17. from taipy.gui import Gui
  18. @pytest.mark.teste2e
  19. def test_text_edit(page: "Page", gui: Gui, helpers):
  20. page_md = """
  21. <|{x}|text|id=text1|>
  22. <|{x}|input|id=input1|>
  23. """
  24. x = "Hey" # noqa: F841
  25. gui._set_frame(inspect.currentframe())
  26. gui.add_page(name="test", page=page_md)
  27. helpers.run_e2e(gui)
  28. page.goto("./test")
  29. page.expect_websocket()
  30. page.wait_for_selector("#text1")
  31. text1 = page.query_selector("#text1")
  32. assert text1.inner_text() == "Hey"
  33. page.wait_for_selector("#input1")
  34. page.fill("#input1", "There")
  35. function_evaluated = True
  36. try:
  37. page.wait_for_function("document.querySelector('#text1').innerText !== 'Hey'")
  38. except Exception as e:
  39. function_evaluated = False
  40. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  41. if function_evaluated:
  42. text1_2 = page.query_selector("#text1")
  43. assert text1_2.inner_text() == "There"
  44. @pytest.mark.teste2e
  45. def test_number_edit(page: "Page", gui: Gui, helpers):
  46. page_md = """
  47. <|{x}|text|id=text1|>
  48. <|{x}|number|id=number1|>
  49. """
  50. x = 10 # noqa: F841
  51. gui._set_frame(inspect.currentframe())
  52. gui.add_page(name="test", page=page_md)
  53. helpers.run_e2e(gui)
  54. page.goto("./test")
  55. page.expect_websocket()
  56. page.wait_for_selector("#text1")
  57. text1 = page.query_selector("#text1")
  58. assert text1.inner_text() == "10"
  59. page.wait_for_selector("#number1")
  60. page.fill("#number1", "20")
  61. function_evaluated = True
  62. try:
  63. page.wait_for_function("document.querySelector('#text1').innerText !== '10'")
  64. function_evaluated = True
  65. except Exception as e:
  66. function_evaluated = False
  67. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  68. if function_evaluated:
  69. text1_2 = page.query_selector("#text1")
  70. assert text1_2.inner_text() == "20"