Falko Schindler 2 gadi atpakaļ
vecāks
revīzija
c805483cdf
4 mainītis faili ar 13 papildinājumiem un 13 dzēšanām
  1. 1 1
      tests/README.md
  2. 7 5
      tests/conftest.py
  3. 2 2
      tests/requirements.txt
  4. 3 5
      tests/user.py

+ 1 - 1
tests/README.md

@@ -7,7 +7,7 @@
 ```bash
 cd nicegui # enter the project root dir
 brew install cask chromedriver
-python3 -m pip install tests/requirements.txt
+python3 -m pip install -r tests/requirements.txt
 ```
 
 ## Usage

+ 7 - 5
tests/conftest.py

@@ -1,8 +1,10 @@
 import datetime
 import os
+from typing import Callable, Generator
 
 import icecream
 import pytest
+from selenium import webdriver
 
 from .user import User
 
@@ -10,7 +12,7 @@ icecream.install()
 
 
 @pytest.fixture
-def chrome_options(chrome_options):
+def chrome_options(chrome_options: webdriver.ChromeOptions) -> webdriver.ChromeOptions:
     chrome_options.add_argument('headless')
     chrome_options.add_argument('disable-gpu')
     chrome_options.add_argument('window-size=1200x600')
@@ -19,23 +21,23 @@ def chrome_options(chrome_options):
 
 
 @pytest.fixture
-def selenium(selenium):
+def selenium(selenium: webdriver.Chrome) -> webdriver.Chrome:
     selenium.implicitly_wait(0.1)
     selenium.set_page_load_timeout(1)
     return selenium
 
 
 @pytest.fixture()
-def user(selenium):
+def user(selenium: webdriver.Chrome) -> Generator[User, None, None]:
     user = User(selenium)
     yield user
     user.stop_server()
 
 
 @pytest.fixture
-def screenshot(selenium):
+def screenshot(selenium: webdriver.Chrome) -> Callable[[str], None]:
     # original taken from https://github.com/theserverlessway/pytest-chrome/blob/master/tests/conftest.py
-    def shot(name=''):
+    def shot(name: str = '') -> None:
         directory = 'screenshots'
         if not os.path.exists(directory):
             os.makedirs(directory)

+ 2 - 2
tests/requirements.txt

@@ -1,3 +1,3 @@
-selenium
+pytest
 pytest-selenium
-pytest
+selenium

+ 3 - 5
tests/user.py

@@ -1,6 +1,6 @@
+import logging
 import threading
 import time
-from asyncio import start_server
 
 from nicegui import globals as nicegui_globals
 from nicegui import ui
@@ -12,7 +12,7 @@ from selenium.webdriver.remote.webelement import WebElement
 
 class User():
 
-    def __init__(self, selenium: webdriver.Chrome):
+    def __init__(self, selenium: webdriver.Chrome) -> None:
         self.selenium = selenium
         self.thread = None
 
@@ -44,9 +44,7 @@ class User():
                 logging.warning(f'Failed to open page at {path}, retrying...')
 
     def should_see(self, text: str) -> None:
-        if text == self.selenium.title:
-            return
-        assert self.find(text).text == text
+        assert self.selenium.title == text or self.find(text).text == text
 
     def click(self, target_text: str) -> None:
         self.find(target_text).click()