test_slider_input_reload.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Copyright 2023 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. def edit_and_assert_page(page: "Page"):
  19. assert_input(page, "0")
  20. page.fill("#input2 input", "20")
  21. function_evaluated = True
  22. try:
  23. page.wait_for_function("document.querySelector('#val1').innerText !== '0'")
  24. except Exception as e:
  25. function_evaluated = False
  26. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  27. if not function_evaluated:
  28. return
  29. assert_input(page, "20")
  30. page.fill("#input1", "30")
  31. function_evaluated = True
  32. try:
  33. page.wait_for_function("document.querySelector('#val1').innerText !== '20'")
  34. function_evaluated = True
  35. except Exception as e:
  36. function_evaluated = False
  37. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  38. if not function_evaluated:
  39. return
  40. assert_input(page, "30")
  41. def assert_input(page: "Page", val: str):
  42. val1 = page.query_selector("#val1").inner_text()
  43. assert str(val1).startswith(val)
  44. val2 = page.query_selector("#val2").inner_text()
  45. assert str(val2).startswith(f"Val: {val}")
  46. inp1 = page.input_value("input#input1")
  47. assert str(inp1).startswith(val)
  48. inp2 = page.input_value("#input2 input")
  49. assert str(inp2).startswith(val)
  50. @pytest.mark.filterwarnings("ignore::Warning")
  51. @pytest.mark.teste2e
  52. def test_slider_input_reload(page: "Page", gui: Gui, helpers):
  53. page_md = """
  54. #Test Multi Number
  55. <|{val}|id=val1|>
  56. <|Val: {val}|id=val2|>
  57. <|{val}|number|id=input1|>
  58. <|{val}|slider|id=input2|>
  59. """
  60. val = 0 # noqa: F841
  61. if frame := inspect.currentframe():
  62. gui._set_frame(frame)
  63. gui.add_page(name="page1", page=page_md)
  64. helpers.run_e2e_multi_client(gui)
  65. page.goto("./page1")
  66. page.expect_websocket()
  67. page.wait_for_selector("#val1")
  68. edit_and_assert_page(page)
  69. page.reload()
  70. page.expect_websocket()
  71. page.wait_for_selector("#val1")
  72. assert_input(page, "30")
  73. page.evaluate("window.localStorage.removeItem('TaipyClientId')")
  74. page.reload()
  75. page.expect_websocket()
  76. page.wait_for_selector("#val1")
  77. assert_input(page, "0")