test_darkmode.py 1.85 KB
Newer Older
1
2
3
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
dennisjl's avatar
dennisjl committed
4
import time
Johannes Tomren Røsvik's avatar
Johannes Tomren Røsvik committed
5
import os
dennisjl's avatar
dennisjl committed
6
7

url = "http://127.0.0.1:8000/"
8
9
10
11

class AgreelanceDarkMode(unittest.TestCase):

    def setUp(self):
12
13
        if os.name == "nt":
            self.driver = webdriver.Chrome("./bin/chromedriver.exe")
Johannes Tomren Røsvik's avatar
Johannes Tomren Røsvik committed
14
15
        else:
            self.driver = webdriver.Chrome("./bin/chromedriver")
16

dennisjl's avatar
dennisjl committed
17
18
    #Checks that toggleelement should be availeble through togglebar
    def test_dark_mode_in_toggle(self):
19
        driver = self.driver
dennisjl's avatar
dennisjl committed
20
        driver.get(url)
21
22
        self.assertNotIn(driver.find_element_by_class_name("custom-control-label"), driver.find_elements_by_class_name("navbar navbar-expand-lg navbar-light bg-light"))

dennisjl's avatar
dennisjl committed
23
24
25
    #Find the darkmode elements
    def test_dark_mode_elements(self):
        driver = self.driver
dennisjl's avatar
dennisjl committed
26
        driver.get(url)
dennisjl's avatar
dennisjl committed
27
28
29

        darkmode_control_label = driver.find_element_by_class_name("custom-control-label")
        darkmode_control_input = driver.find_element_by_class_name("custom-control-input")
30

dennisjl's avatar
dennisjl committed
31
32
        self.assertTrue(darkmode_control_label)
        self.assertTrue(darkmode_control_input)
dennisjl's avatar
dennisjl committed
33
34
35
36
37
    
    #Checks if CSS changes if button is clicked
    def test_dark_mode_clicked(self):
        driver = self.driver
        driver.get(url)
Johannes Tomren Røsvik's avatar
Johannes Tomren Røsvik committed
38
39
        
        # Try to open navbar in case the screen is small
dennisjl's avatar
dennisjl committed
40
41
42
43
        try:
            toggler = driver.find_element_by_class_name("navbar-toggler")
            toggler.click()
            time.sleep(1)
Johannes Tomren Røsvik's avatar
Johannes Tomren Røsvik committed
44
45
46
47
48
49
        except Exception:
            pass

        darkmode_click = driver.find_element_by_class_name("custom-control-label")
        darkmode_click.click()
        time.sleep(1)
dennisjl's avatar
dennisjl committed
50

dennisjl's avatar
dennisjl committed
51
52
        self.assertEqual(driver.find_element_by_tag_name("body").value_of_css_property("background-color"), "rgba(0, 0, 0, 1)")
    
53
54
55
56
57

    def tearDown(self):
        self.driver.close()

if __name__ == "__main__":
Johannes Tomren Røsvik's avatar
Johannes Tomren Røsvik committed
58
    unittest.main()