Browse Source

Test creating pages after startup.
This currently fails because the feature is not yet implemented.

Rodja Trappe 2 years ago
parent
commit
e9d775c659
2 changed files with 19 additions and 1 deletions
  1. 11 0
      tests/test_pages.py
  2. 8 1
      tests/user.py

+ 11 - 0
tests/test_pages.py

@@ -31,3 +31,14 @@ async def test_link_to_page_by_passing_function(user: User):
     user.open()
     user.click('link to subpage')
     user.should_see('the subpage')
+
+
+async def test_creating_new_page_after_startup(user: User):
+    user.open()
+
+    @ui.page('/late_page')
+    def page():
+        ui.label('page created after startup')
+
+    user.open('/late_page')
+    user.should_see('page created after startup')

+ 8 - 1
tests/user.py

@@ -5,6 +5,7 @@ from time import sleep
 from nicegui import globals as nicegui_globals
 from nicegui import ui
 from selenium import webdriver
+from selenium.common.exceptions import NoSuchElementException
 from selenium.webdriver.common.by import By
 from selenium.webdriver.remote.webelement import WebElement
 
@@ -40,4 +41,10 @@ class User():
         self.find(target_text).click()
 
     def find(self, text: str) -> WebElement:
-        return self.selenium.find_element(By.XPATH, f'//*[contains(text(),"{text}")]')
+        try:
+            return self.selenium.find_element(By.XPATH, f'//*[contains(text(),"{text}")]')
+        except NoSuchElementException:
+            raise AssertionError(f'Could not find "{text}" on:\n{self.get_body()}')
+
+    def get_body(self) -> str:
+        return self.selenium.find_element(By.TAG_NAME, 'body').text