2

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:

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. 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.

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()
0

1 Answer 1

1

So I took their example and whenever I go to the page with selenium it cannot find anything at that URL.

That test is just making sure the URL is reachable, i.e. that the returned status code is 200. So it's working as expected as no/empty/default server response document is served on that URL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.