提问人:fathi imran 提问时间:10/17/2023 最后编辑:Daniel Morellfathi imran 更新时间:10/21/2023 访问量:19
使用 Selenium 进行 Django 测试的问题 ( TypeError : expected str, bytes or os.PathLike 对象,而不是 NoneType )
Problem in Django Testing with Selenium ( TypeError : expected str, bytes or os.PathLike object, not NoneType )
问:
我目前正在进行测试,以检查 Django 中的客户端渲染是否存在任何问题。因此,我正在运行一个循环来访问 Django 项目中可用的每个路由并记录浏览器控制台。
代码如下:
class SeleniumTest2(LiveServerTestCase):
def setUp(self) -> None:
super(MySeleniumTests, self).setUp()
User = get_user_model()
self.superuser = User.objects.create_superuser('superuser', '[email protected]', 'password')
self.client.login(username='superuser', password='password')
models = apps.get_models()
factories = generate_dynamic_factories_2(models)
for model_name, factory_class in factories.items():
instances = factory_class.create_batch(10)
for instance in instances :
instance.save()
def tearDown(self):
self.selenium.quit()
super(MySeleniumTests, self).tearDown()
if(check_library_selenium()):
def test_client_side(self):
urls = get_urls()
driver = webdriver.Edge()
live_server = self.live_server_url
for url in urls:
driver.get( str(live_server) + url)
# Print or use the console output as needed
logs = driver.get_log('browser')
print(url, logs)
driver.quit()
else :
print(RED+'Client-side checker skipped'+RESET)
错误如下:
Traceback (most recent call last):
File "/Users/zulfathihanafi/.pyenv/versions/3.9.16/lib/python3.9/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/Users/zulfathihanafi/Desktop/Fathi/test-6/reporter/venv/lib/python3.9/site-packages/django/test/testcases.py", line 1723, in __call__
return super().__call__(environ, start_response)
File "/Users/zulfathihanafi/Desktop/Fathi/test-6/reporter/venv/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 124, in __call__
response = self.get_response(request)
File "/Users/zulfathihanafi/Desktop/Fathi/test-6/reporter/venv/lib/python3.9/site-packages/django/test/testcases.py", line 1706, in get_response
return self.serve(request)
File "/Users/zulfathihanafi/Desktop/Fathi/test-6/reporter/venv/lib/python3.9/site-packages/django/test/testcases.py", line 1718, in serve
return serve(request, final_rel_path, document_root=self.get_base_dir())
File "/Users/zulfathihanafi/Desktop/Fathi/test-6/reporter/venv/lib/python3.9/site-packages/django/views/static.py", line 34, in serve
fullpath = Path(safe_join(document_root, path))
File "/Users/zulfathihanafi/Desktop/Fathi/test-6/reporter/venv/lib/python3.9/site-packages/django/utils/_os.py", line 17, in safe_join
final_path = abspath(join(base, *paths))
File "/Users/zulfathihanafi/.pyenv/versions/3.9.16/lib/python3.9/posixpath.py", line 76, in join
a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
我确实尝试检查是否可用:live_server_url
def test_client_side(self):
urls = get_urls()
driver = webdriver.Edge()
for url in urls:
# Check if the live server URL is None
if self.live_server_url is None:
raise Exception('The live server URL is None.')
driver.get(self.live_server_url + url)
# Print or use the console output as needed
logs = driver.get_log('browser')
print(url, logs)
driver.quit()
但我最终得到了同样的结果。
答: 暂无答案
评论