None response and empty title from selenium webdriver in functional test

荒凉一梦 提交于 2020-07-10 10:26:02

问题


I followed this tutorial (Build DevOps CI/CD pipeline for Python Flask with Azure DevOps). There is a command line task to execute a functional test which I get an error while running it.

The command line task script is as follows:

pip install selenium && pip install pytest && pytest Tests/functional_tests/ --webAppUrl=$(webAppUrl.AppServiceApplicationUrl) --junitxml=TestResults/test-results.xml

This is the script used for functional test:

import pytest
from selenium import webdriver
import unittest
import os
import sys
import pytest
import time

class FunctionalTests(unittest.TestCase):

@pytest.fixture(autouse=True)
def inject_config(self, request):
    self._config = request.config

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 = self._config.getoption('webAppUrl')
    print ('webAppUrl:')
    print (webAppUrl)
    start_timestamp = time.time()
    end_timestamp = start_timestamp + 60*10
    while True:
        try:
            response = self.driver.get(webAppUrl)
            print (response)
            title = self.driver.title
            print ("*****")
            print (title)
            self.assertIn("Home Page - Python Flask Application", title)
            break
        except Exception as e:
            print('"##vso[task.logissue type=error;]Test test_selenium failed with error: ' + str(e))
            current_timestamp = time.time()
            if(current_timestamp > end_timestamp):
                raise
            time.sleep(5)

def tearDown(self):
    try:
        self.driver.quit()
    except Exception as e:
        print('tearDown.Error occurred while trying to close the selenium chrome driver: ' + str(e))

I get the following error:

 >self.assertIn("Home Page - Python Flask Application", title):
[error]Test test_selenium failed with error: 'Home Page - Python Flask Application' not found in ''

When I print response it's None. And title is empty.

Can someone please help me? I'm new to pytest.

来源:https://stackoverflow.com/questions/62791926/none-response-and-empty-title-from-selenium-webdriver-in-functional-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!