How can Selenium see a record that I can't find from a debugger?

39 views
Skip to first unread message

Bryan

unread,
Jun 26, 2012, 9:59:09 AM6/26/12
to django...@googlegroups.com
I am creating Selenium tests for my App.
I can create a new user, but I can't seem to figure out how to have it deleted from the database.

After the tests run successfully the first time, subsequent tests fail because the username already exists.

**Why am I not able to query the newly created record in the debugger despite being able to see the new record on the page?** 

**How do I delete a record from the database in a test?**

This is what I have been doing: 

    from selenium import webdriver 
    from django.utils import unittest 
    from forum.models import Question, Answer, User 
     
    class TestOSQAAuthentication(unittest.TestCase): 
        scheme = 'http' 
        host = 'localhost' 
        port = '4444' 
            
        def setUp(self): 
            self._driver = webdriver.Firefox() 
            self._driver.implicitly_wait(25) 
         
     
        def test_anon_can_create_new_account_manually(self): 
            self._driver.get('http://localhost:8000/account/local/register/') 
            self._driver.find_element_by_id('id_username').send_keys('MrManual') 
            self._driver.find_element_by_id('id_email').send_keys('te...@gmail.com') 
            self._driver.find_element_by_id('id_password1').send_keys('test') 
            self._driver.find_element_by_id('id_password2').send_keys('test') 
            self._driver.find_element_by_id('bnewaccount').click()  
            # verify MrManual was created 
            self._driver.get('http://localhost:8000/users/') 
            self._driver.find_element_by_link_text('MrManual') 
            # MrManual seems to be created, but I don't see MrManual in the database during debugging with: 
            # import ipdb; ipdb.set_trace() 
            #ipdb> User.objects.all() 
            #[<User: Bryan>, <User: Kallie>, <User: Stalin>] 
            # here I am trying to delete the user from the database directly.
            User.objects.filter(username="MrManual").delete() 
            """For some reason I can't delete the record from the database from the test. 
            Selenium can find the new user in the browser, but I can't query the database to find it."""

Bryan

unread,
Jul 2, 2012, 11:17:09 AM7/2/12
to django...@googlegroups.com
I'm still stuck regarding how to delete a user from the database directly.


On Tuesday, June 26, 2012 9:59:09 AM UTC-4, Bryan wrote:
I am creating Selenium tests for my App.
I can create a new user, but I can't seem to figure out how to have it deleted from the database.

After the tests run successfully the first time, subsequent tests fail because the username already exists.

**Why am I not able to query the newly created record in the debugger despite being able to see the new record on the page?** 

**How do I delete a record from the database in a test?**

This is what I have been doing: 

    from selenium import webdriver 
    from django.utils import unittest 
    from forum.models import Question, Answer, User 
     
    class TestOSQAAuthentication(unittest.TestCase): 
        scheme = 'http' 
        host = 'localhost' 
        port = '4444' 
            
        def setUp(self): 
            self._driver = webdriver.Firefox() 
            self._driver.implicitly_wait(25) 
         
     
        def test_anon_can_create_new_account_manually(self): 
            self._driver.get('http://localhost:8000/account/local/register/') 
            self._driver.find_element_by_id('id_username').send_keys('MrManual') 
            self._driver.find_element_by_id('id_email').send_keys('test@gmail.com') 

Rohan

unread,
Jul 2, 2012, 4:04:29 PM7/2/12
to django...@googlegroups.com
Hi Bryan,

I believe the problem is that selenium and the django testing framework are looking up different databases. To run selenium, you would be starting the actual server

One solution is to use 'manage.py testserver <jsonfixture>' for running the selenium tests. This will ensure that the data is populated into the testserver, and will be deleted once the server is stopped
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/_swPDw1iq-0J.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


Reply all
Reply to author
Forward
0 new messages