2

I'm on Python 3.4. I'm trying to write tests using Selenium. I'm using https://flask-testing.readthedocs.org/en/latest/#testing-with-liveserver as a template. Here's the way I have my class set up:

class APITestCase(LiveServerTestCase):
    def create_app(self):
        app = create_app('testing')
        return app 

    def setUp(self):
        self.display = Display(visible=0, size=(1024, 768))
        self.display.start()
        self.driver = webdriver.Firefox()

    def tearDown(self):
        self.driver.close()
        self.display.stop()

And for my only test:

    def test_register(self):
        register_link = self.get_server_url() + url_for('register')
        self.driver.get(register_link)

I get a 404. Even using the requests library, I still get a 404.

I'm certain that /register is defined for the register view function because I'm printing out the routes right before I call self.driver.get(register_link) using the method here: get a list of all routes defined in the app

Furthermore, if I initialize a test client using self.client = app.test_client() in the create_app function, I'm able to access routes normally using self.client.get or self.client.post but that defeats the purpose of Selenium.

Community
  • 1
  • 1
user1005909
  • 1,825
  • 2
  • 17
  • 27
  • What is the value of `register_link` when the test runs? – Ceasar Jun 24 '15 at 18:33
  • `http://localhost:5001/register` which is correct. – user1005909 Jun 24 '15 at 18:38
  • And if you access it using a web browser, you get something other than a 404? – Ceasar Jun 24 '15 at 21:01
  • As far as I know, when using the command `python manage.py test` to test the app, it only instantiates the app for the duration of the test. The `setUp` and `tearDown` methods call the `create_app` method for each test. So, I can't access with a web browser. It's only up for a few seconds at a time when doing these tests. – user1005909 Jun 25 '15 at 04:10

0 Answers0