RitehWebTeam / django-thesis

0 stars 0 forks source link

e2e tests #7

Open askoki opened 3 years ago

askoki commented 3 years ago

Ima mnogo ispunjavanja forme i onda da biste nešto testirali svaki puta morate klikati. Moguće je napraviti end-to-end testove koji će to napraviti za vas. Jedan od alata kojima to možete napraviti je i selenium https://www.selenium.dev/documentation/en/. Bilo bi odlično obuhvatiti cijeli proces: student uploada, mentor odobrava, voditelj šalje na doradu...

Primjer iz jedne app za testirati login:

import os
from django.test import LiveServerTestCase
from selenium.webdriver import Remote, DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from core.tests.helpers.helpers import create_user, login_submit

class AuthTest(LiveServerTestCase):

    @classmethod
    def setUpClass(cls):
        create_user()
        cls.host = 'physio-server'
        cls.driver = Remote(
            command_executor=os.getenv("TEST_URL"),
            desired_capabilities=DesiredCapabilities.FIREFOX
        )
        super().setUpClass()

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()
        super().tearDownClass()

    def test_login(self):
        login_submit(
            self.driver,
            self.live_server_url,
            os.getenv("TEST_USERNAME"),
            os.getenv("TEST_PASSWORD"),
        )
        WebDriverWait(self.driver, timeout=3).until(lambda d: d.find_element(By.ID, 'user-tools'))