Fakultas Ilmu Komputer UI

functional_tests_chrome.py 1.84 KB
Newer Older
Muhammad Ilham Peruzzi's avatar
Muhammad Ilham Peruzzi committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
import unittest
import environ

root = environ.Path(__file__)
env = environ.Env(DEBUG=(bool, False), )
environ.Env.read_env('.env')

HEROKU_APP_HOST = env("HEROKU_APP_HOST")

MAX_WAIT = 5


class NewVisitorTest(unittest.TestCase):

    def setUp(self):
        chrome_options = Options()
        chrome_options.add_argument('--dns-prefetch-disable')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('disable-gpu')
        try:
            self.browser = webdriver.Chrome('./chromedriver.exe', chrome_options=chrome_options)
        except:
            self.browser = webdriver.Chrome('./chromedriver', chrome_options=chrome_options)
        super(NewVisitorTest, self).setUp()

    def tearDown(self):
        self.browser.quit()

    def test_can_start_a_list_and_retrieve_it_later(self):
        self.browser.get(HEROKU_APP_HOST)

        inputbox = self.browser.find_element_by_id('id_new_item')
        self.assertEqual(
            inputbox.get_attribute('placeholder'),
            'Enter a to-do item'
        )

        inputbox.send_keys('Buy peacock feathers')

        inputbox.send_keys(Keys.ENTER)


        inputbox = self.browser.find_element_by_id('id_new_item')
        inputbox.send_keys('Use peacock feathers to make a fly')
        inputbox.send_keys(Keys.ENTER)

        for i in range(3):
            inputbox = self.browser.find_element_by_id('id_new_item')
            inputbox.send_keys('Activity' + str(i))
            inputbox.send_keys(Keys.ENTER)

        assert 'oh tidak' in self.browser.page_source


if __name__ == '__main__':
    unittest.main(warnings='ignore')