I want to start a server with the manage.py runserver command and I'm trying for some time now but don't really find the right way.
from subprocess import Popen, PIPE
from django.test import TestCase
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class ExampleClass(TestCase):
def startServer(self):
process = Popen(['cd C:\mypath'], stdin=PIPE, stdout=PIPE)
process.stdin.write(['python', 'manage.py runserver'])
.
.
.
def test_examplename(self):
self.browser.get('http://localhost:8000')
Everytime I start the test it seems like the process is starting in background but as soon as the browser window pops up it shows me a "can't connect" error. So the server is not running.
Please note that the test is working fine when I start the server myself.
I recommend you use LiveServerTestCase
instead of TestCase
for tests that use Selenium. Django will take care of starting and stopping the server, so you don't have to worry about it.
For more information and an example of a test case that uses Selenium, see the docs.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments