test_page_load.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 .assets6_page_load.page1 import page as page1
  19. @pytest.mark.timeout(300)
  20. @pytest.mark.teste2e
  21. def test_page_scopes(page: "Page", gui: Gui, helpers):
  22. gui._set_frame(inspect.currentframe())
  23. x = 15 # noqa: F841
  24. def on_page_load(state):
  25. state.x = 30
  26. gui.add_page(Gui._get_root_page_name(), "<|{x}|id=text_x|>")
  27. gui.add_page("page1", page1)
  28. helpers.run_e2e(gui)
  29. page.goto("./page1")
  30. page.expect_websocket()
  31. page.wait_for_selector("#text_a")
  32. function_evaluated = True
  33. try:
  34. page.wait_for_function("document.querySelector('#text_a').innerText !== '10'")
  35. function_evaluated = True
  36. except Exception as e:
  37. function_evaluated = False
  38. logging.getLogger().debug(f"Function evaluation timeout.\n{e}")
  39. if not function_evaluated:
  40. return
  41. assert page.query_selector("#text_a").inner_text() == "20"
  42. assert page.query_selector("#text_x").inner_text() == "30"