Fakultas Ilmu Komputer UI

Commit 58d5c0b3 authored by Syahrul Findi's avatar Syahrul Findi
Browse files

Merge branch 'latihan3' into 'master'


See merge request !5
parents de07acef e0261f05
Pipeline #21466 passed with stage
in 1 minute and 46 seconds
......@@ -6,4 +6,4 @@ before_script:
- python manage.py test
- python manage.py test latihan2
# Practice Repository
Production URL: https://pmpl-1506757352-latihan1.herokuapp.com/
## Latihan 3
Perbedaan dari test yang sudah dibuat adalah integration test yang baru akan menunggu sampai ada perubahan pada rows hingga 10 detik setelah selenium menambahkan item. Pengecekan dilakukan setiap 0.5 detik, jika saat lewat dari 10 detik fungsi wait_for_row_in_list_table tidak me-return, maka akan ada error yang di-raise. Dibandingkan dengan test yang lama, fungsi test akan melakukan sleep selama 1 detik dan belum tentu dalam 1 detik tersebut item berhasil ditambahkan.
Selain itu integration test sekarang sudah bisa me-listen request dari url liveserver yang sedang berjalan, tidak perlu ditentukan lagi url nya apa.
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.keys import Keys
import unittest
from django.test import LiveServerTestCase
import time
import os
class NewVisitorTest(unittest.TestCase):
class NewVisitorTest(LiveServerTestCase):
def setUp(self):
self.browser = webdriver.Chrome()
def tearDown(self):
def check_for_row_in_list_table(self, row_text):
table = self.browser.find_element_by_id('id_list_table')
rows = table.find_elements_by_tag_name('tr')
self.assertIn(row_text, [row.text for row in rows])
def wait_for_row_in_list_table(self, row_text):
start_time = time.time()
while True:
table = self.browser.find_element_by_id('id_list_table')
rows = table.find_elements_by_tag_name('tr')
self.assertIn(row_text, [row.text for row in rows])
except (AssertionError, WebDriverException) as e:
if time.time() - start_time > MAX_WAIT:
raise e
def test_can_start_a_list_and_retrieve_it_later(self):
# Edith has heard about a cool new online to-do app. She goes
# to check out its homepage
# She notices the page title and header mention to-do lists
self.assertIn('To-Do', self.browser.title)
......@@ -52,8 +63,7 @@ class NewVisitorTest(unittest.TestCase):
# When she hits enter, the page updates, and now the page lists
# "1: Buy peacock feathers" as an item in a to-do list table
self.check_for_row_in_list_table('1: Buy peacock feathers')
self.wait_for_row_in_list_table('1: Buy peacock feathers')
# There is still a text box inviting her to add another item. She
# enters "Use peacock feathers to make a fly" (Edith is very
......@@ -61,11 +71,10 @@ class NewVisitorTest(unittest.TestCase):
inputbox = self.browser.find_element_by_id('id_new_item')
inputbox.send_keys('Use peacock feathers to make a fly')
# The page updates again, and now shows both items on her list
self.check_for_row_in_list_table('1: Buy peacock feathers')
self.wait_for_row_in_list_table('1: Buy peacock feathers')
'2: Use peacock feathers to make a fly')
# She check the comment when there is few items
......@@ -93,7 +102,3 @@ class NewVisitorTest(unittest.TestCase):
# that the site has generated a unique URL for her -- there is some
# explanatory text to that effect.
self.fail('Finish the test!')
if __name__ == '__main__':
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment