Tests of selenium after the first test

I am trying to run the selenium tests that I wrote for a Django project on a Debian server using xvfb.

I have 3 tests that I try to run, after the first test they fail with this error: NoSuchElementException: Message: u'It cannot find the element: {"method":"xpath","selector":"//a[@href=\\"#detail\\"]"}'

I have launched export DISPLAY=:99and am using Django LiveServerTestCase with django-selenium. SELENIUM_DISPLAY = ':99'installed in my .py settings.

Here is my test runner:

class BaseLiveTest(LiveServerTestCase):
    @classmethod
    def setUpClass(cls):
        cls.selenium = WebDriver()
        super(BaseLiveTest, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(BaseLiveTest, cls).tearDownClass()
        cls.selenium.quit()

    def login(self, user):
        #helper function, to log in users
        #go to login page
        self.selenium.get("%s%s" % (self.live_server_url, reverse('userena_signin')))
        #wait for page to display
        WebDriverWait(self.selenium, 10).until(
            lambda x: self.selenium.find_element_by_id('id_identification'),
        )
        #fill in form and submit
        identifictation_input = self.selenium.find_element_by_id('id_identification')
        identifictation_input.send_keys(user.email)
        password_input = self.selenium.find_element_by_id("id_password")
        password_input.send_keys('password')
        self.selenium.find_element_by_xpath('//form/descendant::button[@type="submit"]').click()

        #wait for dashboard to load
        WebDriverWait(self.selenium, 10).until(
            lambda x: self.selenium.find_element_by_id('container'),
        )

When I run each test on their own, they all pass, but if I try to run them one by one, the last 2 fail. Any ideas?

+2
source share
1 answer

setUp() tearDown(), setUpClass() tearDownClass(). , 3 WebDriver, , , , .

+3

All Articles