Finished 4.2 Using selenium to test user interactions
parent
bfaffaa997
commit
4f7cb1bb5a
|
@ -1,4 +1,6 @@
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
|
from selenium.webdriver.common.keys import Keys
|
||||||
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
class NewVisitorTest(unittest.TestCase):
|
class NewVisitorTest(unittest.TestCase):
|
||||||
|
@ -16,18 +18,33 @@ class NewVisitorTest(unittest.TestCase):
|
||||||
|
|
||||||
# She notices the page title and header mention to-do lists
|
# She notices the page title and header mention to-do lists
|
||||||
self.assertIn('To-Do', self.browser.title)
|
self.assertIn('To-Do', self.browser.title)
|
||||||
self.fail('Finish the test!')
|
header_text = self.browser.find_element_by_tag_name('h1').text
|
||||||
|
self.assertIn('To-Do', header_text)
|
||||||
|
|
||||||
# She is invited to enter a to-do item straight away
|
# She is invited to enter a to-do item straight away
|
||||||
|
inputbox = self.browser.find_element_by_id('id_new_item')
|
||||||
|
self.assertEqual(
|
||||||
|
inputbox.get_attribute('placeholder'),
|
||||||
|
'Enter a to-do item'
|
||||||
|
)
|
||||||
|
|
||||||
# She types "Buy peacock feathers" into a text box (Edith's hobby
|
# She types "Buy peacock feathers" into a text box (Edith's hobby
|
||||||
# is tying fly-fishing lures)
|
# is tying fly-fishing lures)
|
||||||
|
inputbox.send_keys('Buy peacock feathers')
|
||||||
|
|
||||||
# When she hits enter, the page updates, and now the page lists
|
# When she hits enter, the page updates, and now the page lists
|
||||||
# "1: Buy peacock feathers" as an item in a to-do list
|
# "1: Buy peacock feathers" as an item in a to-do list
|
||||||
|
inputbox.send_keys(Keys.ENTER)
|
||||||
|
time.sleep(1)
|
||||||
|
table = self.browser.find_element_by_id('id_list_table')
|
||||||
|
rows = table.find_element_by_tag_name('tr')
|
||||||
|
self.assertTrue(
|
||||||
|
any(row.text == '1: Buy peacock feathers' for row in rows)
|
||||||
|
)
|
||||||
|
|
||||||
# There is still a text box inviting her to add another item. She
|
# There is still a text box inviting her to add another item. She
|
||||||
# enters "Use peacock feathers to make a fly" (Edith is very methodical)
|
# enters "Use peacock feathers to make a fly" (Edith is very methodical)
|
||||||
|
self.fail('Finish the test!')
|
||||||
|
|
||||||
# The page updates again, and now shows both items on her list
|
# The page updates again, and now shows both items on her list
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue