test_slider_input_reload.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. 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. gui._set_frame(inspect.currentframe())
  62. gui.add_page(name="page1", page=page_md)
  63. helpers.run_e2e_multi_client(gui)
  64. page.goto("./page1")
  65. page.expect_websocket()
  66. page.wait_for_selector("#val1")
  67. edit_and_assert_page(page)
  68. page.reload()
  69. page.expect_websocket()
  70. page.wait_for_selector("#val1")
  71. assert_input(page, "30")
  72. page.evaluate("window.localStorage.removeItem('TaipyClientId')")
  73. page.reload()
  74. page.expect_websocket()
  75. page.wait_for_selector("#val1")
  76. assert_input(page, "0")