我遵循了本教程(使用 Azure DevOps 为 Python Flask 构建 DevOps CI/CD 管道)。有一个命令行任务来执行功能测试,我在运行它时遇到错误。
命令行任务脚本如下:
pip install selenium && pip install pytest && pytest Tests/functional_tests/ --webAppUrl=$(webAppUrl.AppServiceApplicationUrl) --junitxml=TestResults/test-results.xml
Run Code Online (Sandbox Code Playgroud)
这是用于功能测试的脚本:
import pytest
from selenium import webdriver
import unittest
import os
import sys
import pytest
import time
class FunctionalTests(unittest.TestCase):
def setUp(self):
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
self.driver = webdriver.Chrome(os.path.join(os.environ["ChromeWebDriver"], 'chromedriver.exe'), chrome_options=options)
self.driver.implicitly_wait(300)
def test_selenium(self):
webAppUrl = pytest.config.getoption('webAppUrl')
start_timestamp = time.time()
end_timestamp = start_timestamp + 60*10
while True:
try:
response = self.driver.get(webAppUrl)
title = self.driver.title
self.assertIn("Home Page …Run Code Online (Sandbox Code Playgroud)