3

I am currently testing my website with Selenium, Python and nosetests. Everything works fine for success tests, I got a problem on failure tests (I have never test with Python / Selenium / Nosetest so ...). For the following test :

 @unittest.expectedFailure
    def test_connection_failure(self):

        # Fill the username with the login only
        self.driver.find_element_by_id('form_identifiant').send_keys(test_login)

        # Send the form
        self.driver.find_element_by_id('form_submit').click()

        # Check the landing URL
        page_url = self.driver.current_url
        self.assertEqual(page_url, page_home)

I am testing a very simple case : when you enter only a login, you can't connect to the website. So I do except a failure when I compare my current page URL and the page where I should be if the login / password couple were correct.

I got the following message from nosetests prompt :

[root@localhost AppGestion]# nosetests ConnectionTests.py
/usr/lib64/python2.7/unittest/case.py:380: RuntimeWarning: TestResult has no addExpectedFailure method, reporting as passes
  RuntimeWarning)

I just don't understand this error. I found the "addExpectedFailure" method on the net but didn't found how to use it, where to put it ... I would like to because the test is just skipped by nosetest actually.

Any clues ?

Ecterion
  • 161
  • 3
  • 19

1 Answers1

0

The decorator with nose to handle an expected exception is @raises(...):

http://nose.readthedocs.io/en/latest/testing_tools.html

But in your case, you could simply use assertNotEqual without the decorator:

def test_connection_failure(self):

    # Fill the username with the login only
    self.driver.find_element_by_id('form_identifiant').send_keys(test_login)

    # Send the form
    self.driver.find_element_by_id('form_submit').click()

    # Check the landing URL
    page_url = self.driver.current_url
    self.assertNotEqual(page_url, page_home)
Florent B.
  • 41,537
  • 7
  • 86
  • 101
  • Yes, for the assertNotEqual, I would like to had some visual difference to other developers. Thank you for the documentation, did not manage to find it out. – Ecterion May 25 '16 at 08:29