test_class_scopes_binding_global.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. from taipy.gui import Gui
  16. if util.find_spec("playwright"):
  17. from playwright._impl._page import Page
  18. from .assets2_class_scopes.page1 import Page1
  19. from .assets2_class_scopes.page2 import Page2
  20. def helpers_assert_value(page, s1, s2, v1):
  21. s1_val = page.input_value("#s1 input")
  22. assert str(s1_val).startswith(s1)
  23. s2_val = page.input_value("#s2 input")
  24. assert str(s2_val).startswith(s2)
  25. val1 = page.query_selector("#v1").inner_text()
  26. assert str(val1).startswith(v1)
  27. @pytest.mark.timeout(300)
  28. @pytest.mark.teste2e
  29. @pytest.mark.filterwarnings("ignore::Warning")
  30. def test_class_scopes_binding(page: "Page", gui: Gui, helpers):
  31. gui._set_frame(inspect.currentframe())
  32. operand_1 = 0 # noqa: F841
  33. gui.add_page("page1", Page1())
  34. gui.add_page("page2", Page2())
  35. helpers.run_e2e(gui)
  36. page.goto("./page1")
  37. page.expect_websocket()
  38. page.wait_for_selector("#s1")
  39. helpers_assert_value(page, "0", "0", "0")
  40. page.fill("#s1 input", "15")
  41. function_evaluated = True
  42. try:
  43. page.wait_for_function("document.querySelector('#v1').innerText !== '0'")
  44. function_evaluated = True
  45. except Exception as e:
  46. function_evaluated = False
  47. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  48. if not function_evaluated:
  49. return
  50. helpers_assert_value(page, "15", "0", "15")
  51. page.fill("#s2 input", "20")
  52. function_evaluated = True
  53. try:
  54. page.wait_for_function("document.querySelector('#v1').innerText !== '15'")
  55. function_evaluated = True
  56. except Exception as e:
  57. function_evaluated = False
  58. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  59. if not function_evaluated:
  60. return
  61. helpers_assert_value(page, "15", "20", "35")
  62. page.goto("./page2")
  63. page.expect_websocket()
  64. page.wait_for_selector("#s1")
  65. helpers_assert_value(page, "15", "0", "0")
  66. page.fill("#s2 input", "5")
  67. function_evaluated = True
  68. try:
  69. page.wait_for_function("document.querySelector('#v1').innerText !== '0'")
  70. function_evaluated = True
  71. except Exception as e:
  72. function_evaluated = False
  73. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  74. if not function_evaluated:
  75. return
  76. helpers_assert_value(page, "15", "5", "75")
  77. page.fill("#s1 input", "17")
  78. function_evaluated = True
  79. try:
  80. page.wait_for_function("document.querySelector('#v1').innerText !== '75'")
  81. function_evaluated = True
  82. except Exception as e:
  83. function_evaluated = False
  84. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  85. if not function_evaluated:
  86. return
  87. helpers_assert_value(page, "17", "5", "85")
  88. page.goto("./page1")
  89. page.expect_websocket()
  90. page.wait_for_selector("#s1")
  91. helpers_assert_value(page, "17", "20", "37")
  92. page.click("#btn_reset")
  93. try:
  94. page.wait_for_function("document.querySelector('#v1').innerText !== '37'")
  95. function_evaluated = True
  96. except Exception as e:
  97. function_evaluated = False
  98. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  99. if not function_evaluated:
  100. return
  101. helpers_assert_value(page, "17", "0", "17")