test_margin.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Copyright 2021-2025 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. from importlib import util
  13. import pytest
  14. if util.find_spec("playwright"):
  15. from playwright._impl._page import Page
  16. from taipy.gui import Gui
  17. @pytest.mark.teste2e
  18. def test_margin_1(page: "Page", gui: Gui, helpers):
  19. page_md = """
  20. <|Just a page|id=text1|>
  21. """
  22. gui._set_frame(inspect.currentframe())
  23. gui.add_page(name="test", page=page_md)
  24. helpers.run_e2e(gui, dark_mode=False, margin="10rem")
  25. page.goto("./")
  26. page.expect_websocket()
  27. page.wait_for_selector("#text1")
  28. margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")')
  29. assert margin == "160px"
  30. @pytest.mark.teste2e
  31. def test_margin_2(page: "Page", gui: Gui, helpers):
  32. page_md = """
  33. <|Just a page|id=text1|>
  34. """
  35. gui._set_frame(inspect.currentframe())
  36. gui.add_page(name="test", page=page_md)
  37. helpers.run_e2e(gui, dark_mode=False)
  38. page.goto("./")
  39. page.expect_websocket()
  40. page.wait_for_selector("#text1")
  41. margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")')
  42. assert margin == "16px"
  43. @pytest.mark.teste2e
  44. def test_margin_3(page: "Page", gui: Gui, helpers):
  45. page_md = """
  46. <|Just a page|id=text1|>
  47. """
  48. gui._set_frame(inspect.currentframe())
  49. gui.add_page(name="test", page=page_md)
  50. helpers.run_e2e(gui, dark_mode=False, margin="10rem", stylekit=True)
  51. page.goto("./")
  52. page.expect_websocket()
  53. page.wait_for_selector("#text1")
  54. margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")')
  55. assert margin == "160px"
  56. @pytest.mark.teste2e
  57. def test_margin_4(page: "Page", gui: Gui, helpers):
  58. page_md = """
  59. <|Just a page|id=text1|>
  60. """
  61. gui._set_frame(inspect.currentframe())
  62. gui.add_page(name="test", page=page_md)
  63. helpers.run_e2e(gui, dark_mode=False, stylekit={"root_margin": "20rem"})
  64. page.goto("./")
  65. page.expect_websocket()
  66. page.wait_for_selector("#text1")
  67. margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")')
  68. assert margin == "320px"
  69. @pytest.mark.teste2e
  70. def test_margin_5(page: "Page", gui: Gui, helpers):
  71. page_md = """
  72. <|Just a page|id=text1|>
  73. """
  74. gui._set_frame(inspect.currentframe())
  75. gui.add_page(name="test", page=page_md)
  76. helpers.run_e2e(gui, dark_mode=False, stylekit={"root_margin": "20rem"}, margin="10rem")
  77. page.goto("./")
  78. page.expect_websocket()
  79. page.wait_for_selector("#text1")
  80. margin = page.evaluate('window.getComputedStyle(document.querySelector("#root"), null).getPropertyValue("margin")')
  81. assert margin == "320px"