Example code
from selenium import webdriver from selenium.
webdriver.common.keys import Keys import unittest as ut
import time from webdriver_manager.chrome
import ChromeDriverManager
class NewPaymentTest(ut.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(ChromeDriverManager().install()) self.driver.implicitly_wait(3) def tearDown(self):
self.driver.quit() def test_can_sign_up(self): self.driver.get('https://www.buymeacoffee.com/josephsunny') self.driver.maximize_window() self.driver.execute_script("window.scrollTo(0, 100)") element = self.driver.find_element_by_xpath('//*[@id="support"]/div[2]/div/a') self.driver.execute_script("arguments[0].click();", element) time.sleep(3) element =self.driver.find_element_by_xpath('//*[@id="pay_braintree_new"]') self.driver.execute_script("arguments[0].click();", element) time.sleep(2) # He clicks the "Subscribe" button stripe_button = self.driver.find_element_by_css_selector('button.stripe-button-el') stripe_button.click() # Test that Stripe has taken over the screen ## We switch context to the stripe iframe with name stripe_checkout_app iframe = driver.find_elements_by_tag_name("iframe") self.driver.switch_to.frame('stripe_checkout_app') stripe_overlay = self.driver.find_element_by_css_selector('.overlayView') classes = stripe_overlay.get_attribute('class') self.assertEqual(classes, 'overlayView active') # Proceed through the Stripe workflow and redirect to a confirmation page email_input = self.driver.find_element_by_css_selector('#email') email_input.send_keys('[email protected]') email_input.send_keys(Keys.TAB) # the time.sleep statements are here to let selenium catch up with stripe card_input = self.driver.find_element_by_css_selector('#card_number') card_input.send_keys('4242') time.sleep(0.25) card_input.send_keys('4242') time.sleep(0.25) card_input.send_keys('4242') time.sleep(0.25) card_input.send_keys('4242') time.sleep(0.25) exp_input = self.driver.find_element_by_css_selector('#cc-exp') exp_input.send_keys('16') exp_input.send_keys('08') time.sleep(0.25) csc_input = self.driver.find_element_by_css_selector('#cc-csc') csc_input.send_keys('424') submit_button = self.driver.find_element_by_css_selector('#submitButton') submit_button.click() ## The part where he's redirected, time.sleep is here to allow the redirect to catch up self.driver.switch_to_default_content() time.sleep(4) # The thank you self.assertIn('Thank you!', self.driver.page_source)