def test_pythonabot_page_function_success(self): self.browser.get(self.static_home_page_url + 'pythonabot') functional_testing_utilities.wait_for_element_to_load_by_id( self, 'notify_me_email_address') # she types her email address in the email text box notify_me_email_address = self.browser.find_element_by_id( 'notify_me_email_address') notify_me_email_address.send_keys('*****@*****.**') # she selects how excited she is about PythonABot functional_testing_utilities.wait_click_by_id(self, 'how_excited_option_4') # She clicks the submit button functional_testing_utilities.wait_click_by_id( self, 'coming_soon_submit_button') # she sees the "success" message that her email was submitted self.assertNotIn( 'hide', self.browser.find_element_by_id( 'coming_soon_success_message').get_attribute('class')) # verify the success text coming_soon_success_text = self.browser.find_element_by_id( 'coming_soon_success_text') self.assertEqual( 'Thanks for sharing your emaill address with me. I\'ll let you know when I\'m ready!', coming_soon_success_text.text)
def test_pythonabot_page_function_missing_how_excited(self): self.browser.get(self.static_home_page_url + 'pythonabot') functional_testing_utilities.wait_for_element_to_load_by_id( self, 'notify_me_email_address') # she types her email address in the email text box notify_me_email_address = self.browser.find_element_by_id( 'notify_me_email_address') notify_me_email_address.send_keys('*****@*****.**') # She clicks the submit button functional_testing_utilities.wait_click_by_id( self, 'coming_soon_submit_button') # she sees the "error" message that how excited is required self.assertNotIn( 'login-form-error-text-hidden', self.browser.find_element_by_id('how_excited_error').get_attribute( 'class')) self.assertIn( 'login-form-error-text', self.browser.find_element_by_id('how_excited_error').get_attribute( 'class')) self.assertEqual( 'Please select one of the options for how excited you are to meet PythonABot.', self.browser.find_element_by_id('how_excited_error').text)
def test_pythonabot_page_function_invalid_email(self): self.browser.get(self.static_home_page_url + 'pythonabot') functional_testing_utilities.wait_for_element_to_load_by_id( self, 'notify_me_email_address') # she types her email address in the email text box notify_me_email_address = self.browser.find_element_by_id( 'notify_me_email_address') notify_me_email_address.send_keys('tellme@more') # she selects how excited she is about PythonABot functional_testing_utilities.wait_click_by_id(self, 'how_excited_option_2') # She clicks the submit button functional_testing_utilities.wait_click_by_id( self, 'coming_soon_submit_button') # she sees the "error" message that email address is invalid self.assertNotIn( 'login-form-error-text-hidden', self.browser.find_element_by_id( 'notify_me_email_address_error').get_attribute('class')) self.assertIn( 'login-form-error-text', self.browser.find_element_by_id( 'notify_me_email_address_error').get_attribute('class')) self.assertEqual( 'Please enter a valid email address. For example [email protected].', self.browser.find_element_by_id( 'notify_me_email_address_error').text)
def test_pythonabot_page_function_empty_email(self): self.browser.get(self.static_home_page_url + 'pythonabot') functional_testing_utilities.wait_for_element_to_load_by_id( self, 'notify_me_email_address') # she selects how excited she is about PythonABot functional_testing_utilities.wait_click_by_id(self, 'how_excited_option_1') # She clicks the submit button functional_testing_utilities.wait_click_by_id( self, 'coming_soon_submit_button') # she sees the "error" message that email address is required self.assertNotIn( 'login-form-error-text-hidden', self.browser.find_element_by_id( 'notify_me_email_address_error').get_attribute('class')) self.assertIn( 'login-form-error-text', self.browser.find_element_by_id( 'notify_me_email_address_error').get_attribute('class')) self.assertEqual( 'This is a required field.', self.browser.find_element_by_id( 'notify_me_email_address_error').text)
def test_about_page(self): self.browser.get(self.static_home_page_url + 'ad') functional_testing_utilities.wait_for_page_title(self, 'Ad Example') self.assertEqual('Ad Example', self.browser.title) functional_testing_utilities.wait_for_element_to_load_by_id(self, 'pythonabot-google-ad-example') # ensure the ad link is correct self.assertIn('/pythonabot?ad_cd=E0y04nClr68pywMIyUxn', self.browser.find_element_by_id('pythonabot-google-ad-example').get_attribute('href')) # ensure that the add image is visible self.assertNotIn('hide', self.browser.find_element_by_id('pythonabot-google-ad-example-img').get_attribute('class'))
def test_pythonabot_page_function_duplicate_error(self): self.browser.get(self.static_home_page_url + 'pythonabot') functional_testing_utilities.wait_for_element_to_load_by_id( self, 'notify_me_email_address') # she types her email address in the email text box notify_me_email_address = self.browser.find_element_by_id( 'notify_me_email_address') notify_me_email_address.send_keys('*****@*****.**') # she selects how excited she is about PythonABot functional_testing_utilities.wait_click_by_id(self, 'how_excited_option_5') # She clicks the submit button functional_testing_utilities.wait_click_by_id( self, 'coming_soon_submit_button') # Do it again self.browser.get(self.static_home_page_url + 'pythonabot') functional_testing_utilities.wait_for_element_to_load_by_id( self, 'notify_me_email_address') # she types her email address in the email text box notify_me_email_address = self.browser.find_element_by_id( 'notify_me_email_address') notify_me_email_address.send_keys('*****@*****.**') # she selects how excited she is about PythonABot functional_testing_utilities.wait_click_by_id(self, 'how_excited_option_5') # She clicks the submit button functional_testing_utilities.wait_click_by_id( self, 'coming_soon_submit_button') functional_testing_utilities.wait_for_element_to_display_by_id( self, 'notify_me_email_address_error') # she sees the "error" message that this email already exists self.assertNotIn( 'login-form-error-text-hidden', self.browser.find_element_by_id( 'notify_me_email_address_error').get_attribute('class')) self.assertIn( 'login-form-error-text', self.browser.find_element_by_id( 'notify_me_email_address_error').get_attribute('class')) self.assertEqual( 'I already know about this email address. Please enter a different email address.', self.browser.find_element_by_id( 'notify_me_email_address_error').text)
def test_pythonabot_page_load(self): self.browser.get(self.static_home_page_url + 'pythonabot') functional_testing_utilities.wait_for_page_title(self, 'PythonABot') self.assertEqual('PythonABot', self.browser.title) functional_testing_utilities.wait_click_by_id(self, 'header-hamburger-menu') # she reads each item in the expanded menu and sees that the current page is not in the list menu_expanded = self.browser.find_element_by_id('hamburger-menu-open') expected_menu_values = [ 'Login', 'Home', 'Products', 'About', 'Contact', 'Terms of Use', 'Privacy Policy' ] for num, item in enumerate( menu_expanded.find_elements_by_tag_name("a"), start=0): for element in item.find_elements_by_tag_name( "menu-item-expanded"): self.assertEqual(element.text, expected_menu_values[num]) # she reads the coming soon text coming_soon_text = self.browser.find_element_by_id('coming_soon_text') self.assertEqual( 'Hi, and thanks for coming to learn more about me! As you might already know my name is PythonABot. I\'m a personal assistant robot and you can interact with me by writing in your favorite language - Python! I also write back to you in Python as I assume you prefer to think like a Python interpreter as well! Belive me, it\'s fun to communicate this way!', coming_soon_text.text) # she reads the how excited text coming_soon_status = self.browser.find_element_by_id( 'coming_soon_status') self.assertEqual( 'My creators aren\'t quite ready to let you use me, but I should be ready soon! If you want me to notify you when they\'re ready just give me your email address and I\'ll let you know!', coming_soon_status.text) # she reads the how excited text coming_soon_features = self.browser.find_element_by_id( 'coming_soon_features') self.assertEqual( 'Here are a few of the things they\'re teaching me to do:', coming_soon_features.text) # she reads the how excited text how_excited_text = self.browser.find_element_by_id('how_excited_text') self.assertEqual( 'I\'m also curious to know how excited you are to meet me. Knowing that helps my creators work faster!', how_excited_text.text) # ensure that the success div is present but hidden functional_testing_utilities.wait_for_element_to_load_by_id( self, 'coming_soon_success_message') self.assertIn( 'hide', self.browser.find_element_by_id( 'coming_soon_success_message').get_attribute('class'))
def test_header(self): # she notices the menu icon and clicks on it self.browser.get(self.static_home_page_url) main_window = self.browser.current_window_handle functional_testing_utilities.wait_click_by_id(self, 'header-hamburger-menu') # she reads each item in the expanded menu menu_expanded = self.browser.find_element_by_id('hamburger-menu-open') expected_menu_values = [ 'Login', 'PythonABot', 'Products', 'About', 'Contact', 'Terms of Use', 'Privacy Policy' ] for num, item in enumerate( menu_expanded.find_elements_by_tag_name("a"), start=0): for element in item.find_elements_by_tag_name( "menu-item-expanded"): self.assertEqual(element.text, expected_menu_values[num]) # she notices the shopping cart icon, that it's empty and clicks on it functional_testing_utilities.wait_for_shopping_cart_count( self, '0', 'You have no items in your cart.') functional_testing_utilities.wait_click_by_id(self, 'header-shopping-cart') self.assertEqual('Shopping Cart', self.browser.title) functional_testing_utilities.wait_for_element_to_load_by_id( self, 'menu-home-link') # she clicks the back button to go back to the previous page self.browser.back() # she notices the account icon and clicks on it functional_testing_utilities.wait_click_by_id(self, 'header-account') self.assertEqual('My Account', self.browser.title) ## There is a javascript window.location redirect from My Account to Log In due to the user being anonymous at this point functional_testing_utilities.wait_for_page_title(self, 'Log In') self.assertEqual('Log In', self.browser.title) # she clicks the home image button to go back to the previous page functional_testing_utilities.wait_for_element_to_load_by_id( self, 'menu-home-link') functional_testing_utilities.wait_click_by_id(self, 'header-logo-image') self.assertEqual('Home Page', self.browser.title) # she notices the Twitter icon and clicks on it previous_window_handles = self.browser.window_handles functional_testing_utilities.wait_click_by_id(self, 'header-twitter') new_window_handle = functional_testing_utilities.wait_for_new_window_handle( self, previous_window_handles) self.browser.switch_to_window(new_window_handle) #functional_testing_utilities.wait_for_element_to_load_by_id(self, 'search-query') functional_testing_utilities.wait_for_page_title( self, 'Twitter. It\'s what\'s happening.') self.assertEqual('Twitter. It\'s what\'s happening.', self.browser.title) # she closes the tab to go back to the previous tab #self.browser.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 'w') self.browser.switch_to_window(main_window) # she notices the Facebook icon and clicks on it previous_window_handles = self.browser.window_handles functional_testing_utilities.wait_click_by_id(self, 'header-facebook') new_window_handle = functional_testing_utilities.wait_for_new_window_handle( self, previous_window_handles) self.browser.switch_to_window(new_window_handle) functional_testing_utilities.wait_for_page_title( self, 'Facebook - Log In or Sign Up') self.assertEqual('Facebook - Log In or Sign Up', self.browser.title) # she closes the tab to go back to the previous tab #self.browser.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 'w') self.browser.switch_to_window(main_window) # she clicks the home image button to see what it does functional_testing_utilities.wait_click_by_id(self, 'header-logo-image') self.assertIn('Home Page', self.browser.title) functional_testing_utilities.wait_for_element_to_load_by_id( self, 'menu-login-link') # she notices the Call Us link and clicks on it self.assertEqual( 'tel:+1-800-800-8000', self.browser.find_element_by_id('header-phone-number'). find_element_by_tag_name('a').get_attribute('href')) call_us_element = self.browser.find_element_by_id( 'header-phone-number').find_element_by_tag_name('a') try: call_us_element.click() except (WebDriverException) as e: print( 'clicking on the call us phone number raised exception as expected!', e) pass