Browse Source

added test for page at custom path

Rodja Trappe 2 năm trước cách đây
mục cha
commit
b8dd6f8ab3
3 tập tin đã thay đổi với 20 bổ sung2 xóa
  1. 5 0
      tests/README.md
  2. 2 0
      tests/server.py
  3. 13 2
      tests/test_pages.py

+ 5 - 0
tests/README.md

@@ -9,3 +9,8 @@ cd nicegui # enter the project root dir
 brew install cask chromedriver
 brew install cask chromedriver
 python3 -m pip install tests/requirements.txt
 python3 -m pip install tests/requirements.txt
 ```
 ```
+
+## Usage
+
+Use selenium-fixture to control and query the website.
+See https://selenium-python.readthedocs.io/getting-started.html for documentation of the available method calls to the webdriver.

+ 2 - 0
tests/server.py

@@ -8,11 +8,13 @@ from nicegui import ui
 class Server():
 class Server():
 
 
     def start(self):
     def start(self):
+        '''Start the webserver in a separate thread. This is the equivalent of `ui.run()` in a normal script.'''
         self.thread = threading.Thread(target=ui.run, kwargs={'port': 3392, 'show': False, 'reload': False})
         self.thread = threading.Thread(target=ui.run, kwargs={'port': 3392, 'show': False, 'reload': False})
         self.thread.start()
         self.thread.start()
         sleep(1)
         sleep(1)
 
 
     def stop(self):
     def stop(self):
+        '''Stop the webserver.'''
         nicegui_globals.server.should_exit = True
         nicegui_globals.server.should_exit = True
         self.thread.join()
         self.thread.join()
 
 

+ 13 - 2
tests/test_pages.py

@@ -1,10 +1,21 @@
 from nicegui import ui
 from nicegui import ui
+from selenium.webdriver.common.by import By
 
 
 
 
 async def test_title(server, selenium):
 async def test_title(server, selenium):
     @ui.page('/', title='My Custom Title')
     @ui.page('/', title='My Custom Title')
     def page():
     def page():
-        ui.label('hello world')
+        ui.label('some content')
     server.start()
     server.start()
     selenium.get(server.base_url)
     selenium.get(server.base_url)
-    assert "My Custom Title" in selenium.title
+    assert 'My Custom Title' in selenium.title
+
+
+async def test_route_with_custom_path(server, selenium):
+    @ui.page('/test_route')
+    def page():
+        ui.label('page with custom path')
+    server.start()
+    selenium.get(server.base_url + '/test_route')
+    element = selenium.find_element(By.XPATH, '//*[contains(text(),"custom path")]')
+    assert element.text == 'page with custom path'