[英]Flask-testing and selenium
I am trying to get the tutorial here to work for flask-testing https://flask-testing.readthedocs.org/en/latest/ specifically under Testing with LiveServer If you want your tests done via Selenium or other headless browser like PhantomJS you can use the LiveServerTestCase: 我正在尝试使本教程适用于烧瓶测试https://flask-testing.readthedocs.org/en/latest/特别是在“使用LiveServer进行测试”下如果您希望通过Selenium或其他无头浏览器(如PhantomJS)完成测试,可以使用LiveServerTestCase:
import urllib2
from flask import Flask
from flask_testing import LiveServerTestCase
class MyTest(LiveServerTestCase):
def create_app(self):
app = Flask(__name__)
app.config['TESTING'] = True
# Default port is 5000
app.config['LIVESERVER_PORT'] = 8943
return app
def test_server_is_up_and_running(self):
response = urllib2.urlopen(self.get_server_url())
self.assertEqual(response.code, 200)
So I took their example and whenever I go to the page with selenium it cannot find anything at that URL. 因此,我以他们的示例为例,每当我转到带有硒的页面时,该URL都找不到任何内容。 I tried printing out the URL and it is going to localhost on port 8943. I googled around and couldn't find an example of someone using these two together.
我尝试打印出该URL,然后将其发送到端口8943上的localhost。我在google上搜索,找不到有人将这两个一起使用的示例。
from flask import Flask
from flask.ext.testing import LiveServerTestCase
import requests
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import unittest
class IntegrationTest(LiveServerTestCase):
def create_app(self):
app = Flask(__name__)
app.config['TESTING'] = True
app.config['LIVESERVER_PORT'] = 8943
return app
def setUp(self):
self.app = self.create_app()
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)
def tearDown(self):
self.browser.quit()
def test_get_page(self):
self.browser.get(self.get_server_url())
self.assertNotIn("The requested URL was not found on the server.", self.browser.find_element_by_tag_name("body").text)
if __name__ == '__main__':
unittest.main()
So I took their example and whenever I go to the page with selenium it cannot find anything at that URL.
因此,我以他们的示例为例,每当我转到带有硒的页面时,该URL都找不到任何内容。
That test is just making sure the URL is reachable, ie that the returned status code is 200
. 该测试只是确保URL可以访问,即返回的状态码为
200
。 So it's working as expected as no/empty/default server response document is served on that URL. 因此,它可以正常工作,因为该URL上提供了no / empty / default服务器响应文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.