test_class_scopes_binding_global.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. 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. if frame := inspect.currentframe():
  32. gui._set_frame(frame)
  33. operand_1 = 0 # noqa: F841
  34. gui.add_page("page1", Page1())
  35. gui.add_page("page2", Page2())
  36. helpers.run_e2e(gui)
  37. page.goto("./page1")
  38. page.expect_websocket()
  39. page.wait_for_selector("#s1")
  40. helpers_assert_value(page, "0", "0", "0")
  41. page.fill("#s1 input", "15")
  42. function_evaluated = True
  43. try:
  44. page.wait_for_function("document.querySelector('#v1').innerText !== '0'")
  45. function_evaluated = True
  46. except Exception as e:
  47. function_evaluated = False
  48. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  49. if not function_evaluated:
  50. return
  51. helpers_assert_value(page, "15", "0", "15")
  52. page.fill("#s2 input", "20")
  53. function_evaluated = True
  54. try:
  55. page.wait_for_function("document.querySelector('#v1').innerText !== '15'")
  56. function_evaluated = True
  57. except Exception as e:
  58. function_evaluated = False
  59. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  60. if not function_evaluated:
  61. return
  62. helpers_assert_value(page, "15", "20", "35")
  63. page.goto("./page2")
  64. page.expect_websocket()
  65. page.wait_for_selector("#s1")
  66. helpers_assert_value(page, "15", "0", "0")
  67. page.fill("#s2 input", "5")
  68. function_evaluated = True
  69. try:
  70. page.wait_for_function("document.querySelector('#v1').innerText !== '0'")
  71. function_evaluated = True
  72. except Exception as e:
  73. function_evaluated = False
  74. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  75. if not function_evaluated:
  76. return
  77. helpers_assert_value(page, "15", "5", "75")
  78. page.fill("#s1 input", "17")
  79. function_evaluated = True
  80. try:
  81. page.wait_for_function("document.querySelector('#v1').innerText !== '75'")
  82. function_evaluated = True
  83. except Exception as e:
  84. function_evaluated = False
  85. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  86. if not function_evaluated:
  87. return
  88. helpers_assert_value(page, "17", "5", "85")
  89. page.goto("./page1")
  90. page.expect_websocket()
  91. page.wait_for_selector("#s1")
  92. helpers_assert_value(page, "17", "20", "37")
  93. page.click("#btn_reset")
  94. try:
  95. page.wait_for_function("document.querySelector('#v1').innerText !== '37'")
  96. function_evaluated = True
  97. except Exception as e:
  98. function_evaluated = False
  99. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  100. if not function_evaluated:
  101. return
  102. helpers_assert_value(page, "17", "0", "17")