SauceDemo Script Python
SauceDemo Script Python
com/
import time
driver= webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.saucedemo.com/")
time.sleep(5000)
driver.quit()
driver= webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.saucedemo.com/")
driver.find_element(By.ID, 'user-name').send_keys('locked_out_user')
driver.find_element(By.ID, 'password').send_keys('secret_sauce')
time.sleep(5000)
driver= webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.saucedemo.com/")
driver.find_element(By.ID, 'user-name').send_keys('locked_out_user')
driver.find_element(By.ID, 'password').send_keys('secret_sauce')
driver.find_element(By.ID, 'login-button').click()
time.sleep(5000)
import time
driver= webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.saucedemo.com/")
driver.find_element(By.ID, 'user-name').send_keys('standard_user')
driver.find_element(By.ID, 'password').send_keys('secret_sauce')
driver.find_element(By.ID, 'login-button').click()
time.sleep(500)
driver.quit()
driver= webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.saucedemo.com/")
driver.find_element(By.ID, 'user-name').send_keys('standard_user')
driver.find_element(By.ID, 'password').send_keys('secret_sauce')
driver.find_element(By.ID, 'login-button').click()
driver.find_element(By.ID, 'inventory_container')
print("login successful")
time.sleep(500)
driver.quit()
driver= webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.saucedemo.com/")
driver.find_element(By.ID, 'user-name').send_keys('standard_user')
driver.find_element(By.ID, 'password').send_keys('secret_sauce')
driver.find_element(By.ID, 'login-button').click()
driver.find_element(By.ID, 'inventory_container')
print("login successful")
products = driver.find_elements(By.CLASS_NAME, 'inventory_item_name')
product_names = [product.text for product in products]
assert "Dummy Product" not in product_names, "Dummy Product should not be in the product
list."
print("Assertion passed: 'Dummy Product' is not present in the product list.")
time.sleep(5000)
driver.quit()
import time
driver= webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.saucedemo.com/")
driver.find_element(By.ID, 'user-name').send_keys('standard_user')
driver.find_element(By.ID, 'password').send_keys('secret_sauce')
driver.find_element(By.ID, 'login-button').click()
driver.find_element(By.ID, 'inventory_container')
print("login successful")
products = driver.find_elements(By.CLASS_NAME, 'inventory_item_name')
product_names = [product.text for product in products]
assert "Sauce Labs Bolt T-Shirt" in product_names, "Sauce Labs Bolt T-Shirt is not present in the
product list."
print("Assertion passed: 'Sauce Labs Bolt T-Shirt' is present in the product list.")
time.sleep(5000)
driver.quit()
5. b. If the product is found, grab the price of the product and print
it in the console.
import time
driver= webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.saucedemo.com/")
driver.find_element(By.ID, 'user-name').send_keys('standard_user')
driver.find_element(By.ID, 'password').send_keys('secret_sauce')
driver.find_element(By.ID, 'login-button').click()
driver.find_element(By.ID, 'inventory_container')
print("login successful")
time.sleep(5000)
driver.quit()
6. a. Add this product and any other product to the cart and
navigate to the cart.
import time
driver= webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.saucedemo.com/")
driver.find_element(By.ID, 'user-name').send_keys('standard_user')
driver.find_element(By.ID, 'password').send_keys('secret_sauce')
driver.find_element(By.ID, 'login-button').click()
driver.find_element(By.ID, 'inventory_container')
print("login successful")
other_product = None
sauce_labs_bolt_tshirt = product
other_product = product
if sauce_labs_bolt_tshirt:
sauce_labs_bolt_tshirt.find_element(By.CLASS_NAME, 'btn_inventory').click()
else:
if other_product:
other_product.find_element(By.CLASS_NAME, 'btn_inventory').click()
else:
driver.find_element(By.ID, "add-to-cart-test.allthethings()-t-shirt-(red)").click()
time.sleep(5000)
driver.quit()