Accessing Django's context when testing with Selenium WebDriver -
i want use selenium in django tests, can't find way access django's context, can django's default test client.
for example, using test client, can see if forms have errors , template being used:
response = self.client.get('/') self.asserttemplateused(response, 'home.html') self.assertequal(resp.context['form']['code'].errors, [u'this field required.'])
how do if i'm using selenium webdriver?
driver = self.driver driver.get(self.base_url + "/") # ???
the hint of solution have been able find possibility the django test client can extended. somehow swap out selenium webdriver?
the helpful context stuff stripped out time selenium gets response.
you write simple middleware class add in, though. like:
class addcontextmiddleware(object): def process_response(self, request, response): response['debug_stuff'] = str(response.context_data) return response
then response object have header, "debug_stuff", context_data django offers middleware. examine in selenium.
important: don't on production. there's quite-possibly sensitive stuff in context_data don't want world being able pry into.
this seems useful enough thing wouldn't surprised if has created django add-on it. might check around usual django package sites.
Comments
Post a Comment