'How to use StaticLiveServerTestCase with different domains?
I am using selenium for functional tests with geckodriver and firefox.
I see the host is http://localhost:62305
and this is generated in that class with:
@classproperty
def live_server_url(cls):
return 'http://%s:%s' % (cls.host, cls.server_thread.port)
In the functionality I am creating, I give the user a way to create a tenant with its own subdomain but for the purpose of the unit test it can be a domain.
So for example I create a tenant with domain example.com
, how can I get
StaticLiveServerTestCase
to point that domain name to the currently running app on that same port, within the same functional test method.
I looked at this post suggesting editing /etc/hosts
. The problem with that is it won't just work on CI and other people's computers.
Solution 1:[1]
You can do this.
class SeleniumTests(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
cls.host = 'host.com'
cls.port = 3000
super(SeleniumTests, cls).setUpClass()
....
in your test class and once you do this for instance
self.selenium.get('%s%s' % (self.live_server_url), 'some_url')
your browser gonna be launch with the right URL like this
http://host.com:3000/some_url/
,
notice how the super call is made after setup the port and host.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Reidel |