Exemplo n.º 1
0
 def test_shopping_cart_05_ninja(self):
     wait = WebDriverWait(self.driver, 10)
     shopcart = ShoppingCartNinja(self.driver)
     # Click on "My Account" link
     shopcart.click_my_account_link()
     # Click on "Login" link
     shopcart.click_login_link()
     # Enter an existing email address
     shopcart.set_email(self.email_address)
     # Enter an existing password
     shopcart.set_password(self.password)
     # Click "Login" button
     shopcart.click_login_button()
     # Go to main page
     shopcart.click_main_page()
     # Randomly select a product and click "Add to Wish List" button
     element_1 = self.driver.find_element_by_xpath(ShoppingCartNinja.elem_1)
     elem_1 = element_1.text
     shopcart.click_wish_list_button()
     # Click on "Wish List" link
     shopcart.click_wish_list_link()
     # Verify if the selected product is in "Wish List"
     element_2 = self.driver.find_element_by_xpath(ShoppingCartNinja.wishlist_elem)
     elem_2 = element_2.text
     assert elem_1 == elem_2, "ERROR. User cannot view the selected book in the Wish List."
     # Click on "Add to Cart" button
     shopcart.click_addtocart_button()
     # Click On "Shopping Cart" link
     shopcart.click_shopping_cart()
     # Verify if the product was moved to "Shopping Cart"
     element_2 = wait.until(EC.presence_of_element_located((By.XPATH, ShoppingCartNinja.elem_2)))
     assert element_2.is_displayed(), "ERROR. The product wasn't moved to Shopping Cart."
Exemplo n.º 2
0
 def test_shopping_cart_12_ninja(self):
     wait = WebDriverWait(self.driver, 10)
     shopcart = ShoppingCartNinja(self.driver)
     # Add to cart a random item
     element_1 = self.driver.find_element_by_xpath(ShoppingCartNinja.elem_1)
     elem_1 = element_1.text
     shopcart.click_add_item_1()
     # Click on "Shopping Cart" link
     shopcart.click_shopping_cart()
     # Verify if the product is present
     element_2 = self.driver.find_element_by_xpath(ShoppingCartNinja.elem_2)
     elem_2 = element_2.text
     assert elem_1 == elem_2, "ERROR. User cannot view the selected book in the shopping cart."
     # Click "Checkout" button
     shopcart.click_checkout_button()
     # Verify if the site is asking you to login
     element = wait.until(
         EC.presence_of_element_located(
             (By.XPATH,
              ShoppingCartNinja.returning_customer))).is_displayed()
     assert element, "ERROR. The site didn't asked user to login."
     # Enter a valid email address
     shopcart.set_email(self.email_address)
     # Enter a valid password
     shopcart.set_password(self.password)
     # Click "Login" button
     shopcart.click_checkout_login_button()
     # Click "Shopping Cart" link
     shopcart.click_shopping_cart()
     # Verify if the product was added to the shopping cart
     element_2 = wait.until(
         EC.presence_of_element_located(
             (By.XPATH, ShoppingCartNinja.elem_2)))
     elem_2 = element_2.text
     assert elem_1 == elem_2, "ERROR. Logged in user cannot view the selected book in the shopping cart."
Exemplo n.º 3
0
 def test_shopping_cart_04_ninja(self):
     wait = WebDriverWait(self.driver, 10)
     shopcart = ShoppingCartNinja(self.driver)
     # Click on "My Account" link
     shopcart.click_my_account_link()
     # Click on "Login" link
     shopcart.click_login_link()
     # Enter an existing email address
     shopcart.set_email(self.email_address)
     # Enter an existing password
     shopcart.set_password(self.password)
     # Click "Login" button
     shopcart.click_login_button()
     # Go to main page
     shopcart.click_main_page()
     # Randomly select a product and click "Add to Wish List" button
     element_1 = self.driver.find_element_by_xpath(ShoppingCartNinja.elem_1)
     elem_1 = element_1.text
     shopcart.click_wish_list_button()
     # Click on "Wish List" link
     shopcart.click_wish_list_link()
     # Verify if the selected product is in "Wish List"
     element_2 = self.driver.find_element_by_xpath(
         ShoppingCartNinja.wishlist_elem)
     elem_2 = element_2.text
     assert elem_1 == elem_2, "ERROR. User cannot view the selected book in the Wish List."
     # Click on "Remove" button
     shopcart.click_remove_button()
     # Verify if product was deleted
     element_2 = wait.until(
         EC.invisibility_of_element_located(
             (By.XPATH, ShoppingCartNinja.wishlist_elem)))
     assert element_2, "OK. The product was successfully removed from the wish list."
Exemplo n.º 4
0
 def test_shopping_cart_08_ninja(self):
     shopcart = ShoppingCartNinja(self.driver)
     # Click on "My Account" link
     shopcart.click_my_account_link()
     # Click on "Login" link
     shopcart.click_login_link()
     # Enter an existing email address
     shopcart.set_email(self.email_address)
     # Enter an existing password
     shopcart.set_password(self.password)
     # Click "Login" button
     shopcart.click_login_button()
     # Go to main page
     shopcart.click_main_page()
     # Randomly select 2 products and add them to Shopping Cart
     shopcart.click_add_item_1()
     shopcart.click_add_item_2()
     # Save prices
     elem_1 = self.driver.find_elements_by_xpath(
         ShoppingCartNinja.price_item_1)
     for price in elem_1:
         x = price.text
         y = x.replace("Ex Tax: $", "")
         price_1 = float(y)
     elem_2 = self.driver.find_elements_by_xpath(
         ShoppingCartNinja.price_item_2)
     for price in elem_2:
         x = price.text
         y = x.replace("Ex Tax: $", "")
         price_2 = float(y)
     suma = price_1 + price_2
     # Click on "Shopping Cart" link
     shopcart.click_shopping_cart()
     # Verify is total sum is correct
     element = self.driver.find_elements_by_xpath(
         ShoppingCartNinja.total_price)
     for price in element:
         x = price.text
         y = x.replace("$", "")
         total_price = float(y)
     assert suma == total_price, "ERROR. The sum is incorrect."
     # Delete items in "Shopping Cart", it must be empty for the next test cases
     shopcart.click_remove_button()
     self.driver.refresh()
     shopcart.click_remove_button()
Exemplo n.º 5
0
 def test_shopping_cart_09_ninja(self):
     shopcart = ShoppingCartNinja(self.driver)
     # Click on "My Account" link
     shopcart.click_my_account_link()
     # Click on "Login" link
     shopcart.click_login_link()
     # Enter an existing email address
     shopcart.set_email(self.email_address)
     # Enter an existing password
     shopcart.set_password(self.password)
     # Click "Login" button
     shopcart.click_login_button()
     # Go to main page
     shopcart.click_main_page()
     # Randomly select a product and add it to Shopping Cart
     shopcart.click_add_item_1()
     elem_1 = self.driver.find_elements_by_xpath(
         ShoppingCartNinja.price_item_1)
     for price in elem_1:
         x = price.text
         y = x.replace("Ex Tax: $", "")
         z = y.replace(".00", "")
         price_1 = int(z)
     new_price = price_1 * 5
     # Click on "Shopping Cart" link
     shopcart.click_shopping_cart()
     # Change the quantity from 1 to 5
     shopcart.set_quantity(self.quantity)
     # Click on "Update" button
     shopcart.click_update_button()
     # Verify is total sum is correct
     element = self.driver.find_elements_by_xpath(
         ShoppingCartNinja.total_price)
     for price in element:
         x = price.text
         y = x.replace("$", "")
         z = y.replace(".00", "")
         w = z.replace(",", "")
         total_price = int(w)
     assert new_price == total_price, "ERROR. The sum is incorrect."
     # Delete items in "Shopping Cart", it must be empty for the next test cases
     self.driver.refresh()
     shopcart.click_remove_button()
Exemplo n.º 6
0
 def test_shopping_cart_10_ninja(self):
     shopcart = ShoppingCartNinja(self.driver)
     # Click on "My Account" link
     shopcart.click_my_account_link()
     # Click on "Login" link
     shopcart.click_login_link()
     # Enter an existing email address
     shopcart.set_email(self.email_address)
     # Enter an existing password
     shopcart.set_password(self.password)
     # Click "Login" button
     shopcart.click_login_button()
     # Go to main page
     shopcart.click_main_page()
     # Randomly select a product and add it to Shopping Cart
     shopcart.click_add_item_1()
     # Click on "My Account" link
     shopcart.click_my_account_link()
     # Click on "Logout" link
     shopcart.click_top_logout_link()
     # Click on "My Account" link
     shopcart.click_my_account_link()
     # Click on "Login" link
     shopcart.click_login_link()
     # Enter an existing email address
     shopcart.set_email(self.email_address)
     # Enter an existing password
     shopcart.set_password(self.password)
     # Click "Login" button
     shopcart.click_login_button()
     # Click "Shopping Cart" link
     shopcart.click_shopping_cart()
     # Verify if the selected product is still in the "Shopping Cart"
     element = self.driver.find_element_by_xpath(ShoppingCartNinja.verify_product).is_displayed()
     assert element, "ERROR. The product is not in shopping cart."
     # Delete items in "Shopping Cart", it must be empty for the next test cases
     self.driver.refresh()
     shopcart.click_remove_button()
Exemplo n.º 7
0
 def test_shopping_cart_01_ninja(self):
     login = ShoppingCartNinja(self.driver)
     # Click on "My Account" link
     login.click_my_account_link()
     # Click on "Login" link
     login.click_login_link()
     # Enter an existing email address
     login.set_email(self.email_address)
     # Enter an existing password
     login.set_password(self.password)
     # Click "Login" button
     login.click_login_button()
     # Go to main page
     login.click_main_page()
     # Randomly select a product and click "Add to cart" button
     element_1 = self.driver.find_element_by_xpath(ShoppingCartNinja.elem_1)
     elem_1 = element_1.text
     login.click_add_item_1()
     # Click on "Shopping Cart" link
     login.click_shopping_cart()
     # Verify if the selected product is present in shopping cart
     element_2 = self.driver.find_element_by_xpath(ShoppingCartNinja.elem_2)
     elem_2 = element_2.text
     assert elem_1 == elem_2, "ERROR. User cannot view the selected book in the shopping cart."
Exemplo n.º 8
0
 def test_shopping_cart_11_ninja(self):
     shopcart = ShoppingCartNinja(self.driver)
     # Click on "My Account" link
     shopcart.click_my_account_link()
     # Click on "Login" link
     shopcart.click_login_link()
     # Enter an existing email address
     shopcart.set_email(self.email_address)
     # Enter an existing password
     shopcart.set_password(self.password)
     # Click "Login" button
     shopcart.click_login_button()
     # Click "Shopping Cart" link
     shopcart.click_shopping_cart()
     # Verify if a coupon code can be used only if a product is added to shopping cart
     element = self.driver.find_elements_by_xpath(
         ShoppingCartNinja.coupon_code)
     if len(element) > 0:
         sys.exit(
             "ERROR. Coupon code can be used even if a product is not added to shopping cart."
         )
     else:
         print(
             "OK. Coupon code can be used only if a product is added to shopping cart."
         )
     # Verity if a gift certificate can be used only if a product is added to shopping cart
     element = self.driver.find_elements_by_xpath(
         ShoppingCartNinja.gift_certificate)
     if len(element) > 0:
         sys.exit(
             "ERROR. Gift certificate can be used even if a product is not added to shopping cart."
         )
     else:
         print(
             "OK. Gift certificate can be used only if a product is added to shopping cart."
         )