Exemplo n.º 1
0
    def test_Testing(self):
        print("AOS Test")
        chosen_cat = self.data_sheet["C2"].value
        prod1_id = self.data_sheet["C3"].value
        prod1_quan = self.data_sheet["C4"].value

        self.wait.visibility((By.ID, "tabletsImg"))
        Homepage(self.driver).enter_category(chosen_cat)

        category = Categories(self.driver)
        category.enter_product(prod1_id)
        product = Products(self.driver)
        prod1_name = product.product_name()
        product.choose_quantity(prod1_quan)
        product.click_add_to_cart()

        self.wait.visibility(
            (By.XPATH, "//table[@ng-show='cart.productsInCart.length > 0']"))

        self.assertEqual(self.general.popup_cart_name(1)[:27], prod1_name[:27])
        self.assertEqual(self.general.popup_cart_quantity(1),
                         "QTY: " + str(prod1_quan))

        print(prod1_id)
        print(prod1_name)
        print(prod1_quan)
        self.data_sheet["M24"] = "V"
Exemplo n.º 2
0
    def test_aos01(self):
        print("AOS Test 1")
        # Defining products and quantities for the test using the excel data sheet:
        chosen_cat = self.data_sheet["C2"].value
        prod1_id = self.data_sheet["C3"].value
        prod1_quan = self.data_sheet["C4"].value
        prod2_id = self.data_sheet["C6"].value
        prod2_quan = self.data_sheet["C7"].value

        # Enter the category:
        self.wait.visibility(
            (By.ID, "speakersImg"))  # Wait for the homepage to load.
        Homepage(self.driver).enter_category(
            chosen_cat)  # Enter the chosen category.

        # Ordering 1st product:
        category = Categories(
            self.driver)  # Defining a variable for the category page.
        category.enter_product(prod1_id)
        self.wait.visibility(
            (By.ID, "Description"))  # Wait for the product page to be load.
        product = Products(
            self.driver)  # Defining a variable for the product pages.
        product.choose_quantity(prod1_quan)
        product.click_add_to_cart()
        self.driver.back()

        # Ordering 2nd product:
        category.enter_product(prod2_id)
        self.wait.visibility((By.ID, "Description"))
        product.choose_quantity(prod2_quan)
        product.click_add_to_cart()

        # Waiting for the cart pop-up menu to appear before the assertions stage:
        self.wait.clickable((By.ID, "checkOutPopUp"))

        # Printing the result for comparison.
        print(
            f"Product 1 Desired QTY: {prod1_quan}, Actual {self.general.popup_cart_quantity(2)}"
        )
        print(
            f"Product 2 Desired QTY: {prod2_quan}, Actual {self.general.popup_cart_quantity(1)}"
        )
        # Making sure the test passed using the products' quantity variable and a General class function.
        self.assertEqual(str(f"QTY: {prod1_quan}"),
                         self.general.popup_cart_quantity(2))
        self.assertEqual(str(f"QTY: {prod2_quan}"),
                         self.general.popup_cart_quantity(1))

        # Writing the result in the excel sheet:
        self.data_sheet["C24"] = "V"
Exemplo n.º 3
0
    def test_aos006(self):
        print("AOS Test 6")
        # Defining products and quantities for the test using the excel sheet:
        chosen_cat = self.data_sheet["H2"].value
        prod1_id = self.data_sheet["H3"].value
        prod1_quan = self.data_sheet["H4"].value
        prod2_id = self.data_sheet["H6"].value
        prod2_quan = self.data_sheet["H7"].value

        # Enter the category:
        self.wait.visibility(
            (By.ID, "laptopsImg"))  # Waiting  for the homepage to load.
        Homepage(self.driver).enter_category(
            chosen_cat)  # Entering the laptops category.

        # Ordering 1st product:
        category = Categories(
            self.driver)  # Defining a variable for the category page.
        category.enter_product(prod1_id)
        self.wait.visibility(
            (By.ID,
             "Description"))  # Wait for the product description to be visible.
        product = Products(
            self.driver)  # Defining a variable for the product pages.
        product.choose_quantity(prod1_quan)
        product.click_add_to_cart()
        self.driver.back()

        # Ordering 2nd product:
        category.enter_product(prod2_id)
        self.wait.visibility((By.ID, "Description"))
        product.choose_quantity(prod2_quan)
        product.click_add_to_cart()

        # Entering the cart page:
        self.general.enter_cart_page()
        # Waiting for the cart page to load:
        self.wait.visibility((By.CLASS_NAME, "fixedTableEdgeCompatibility"))
        cart = Cart(self.driver)  # Defining a variable for the Cart class.

        # Editing the 1st product's quantity:
        cart.cart_click_edit(2)
        self.wait.visibility(
            (By.ID, "Description"))  # Waiting for the product page to load.
        product.choose_quantity(prod1_quan + 1)
        product.click_add_to_cart()

        # Waiting for the cart page to load:
        self.wait.visibility((By.CLASS_NAME, "fixedTableEdgeCompatibility"))

        # Editing the 2nd product's quantity:
        # Waiting for the cart popup menu to disappear:
        self.wait.invisibility(
            (By.CSS_SELECTOR,
             "table[ng-show='cart.productsInCart.length > 0']"))
        cart.cart_click_edit(1)
        self.wait.visibility((By.ID, "Description"))
        product.choose_quantity(prod2_quan + 1)
        product.click_add_to_cart()

        # Waiting for the cart page to load:
        self.wait.visibility((By.CLASS_NAME, "fixedTableEdgeCompatibility"))

        # Printing for comparison:
        print(f"Product 1 desired quantity: {prod1_quan + 1}")
        print(f"Product 1 actual quantity: {cart.cart_quantities(2)}")
        print(f"Product 2 desired quantity: {prod2_quan + 1}")
        print(f"Product 2 actual quantity: {cart.cart_quantities(1)}")
        # Making sure the test passed by comparing the quantity in the cart page to the new wanted quantity:
        self.assertEqual(cart.cart_quantities(2), str(prod1_quan + 1))
        self.assertEqual(cart.cart_quantities(1), str(prod2_quan + 1))

        # Writing the result in the excel sheet:
        self.data_sheet["G24"] = "V"
Exemplo n.º 4
0
    def test_aos2(self):
        print("AOS Test 2")
        # Defining products, colors and quantities for the test using the excel data sheet:
        chosen_cat = self.data_sheet["D2"].value
        prod1_id = self.data_sheet["D3"].value
        prod1_quan = self.data_sheet["D4"].value
        prod1_color = self.data_sheet["D5"].value
        prod2_id = self.data_sheet["D6"].value
        prod2_quan = self.data_sheet["D7"].value
        prod2_color = self.data_sheet["D8"].value
        prod3_id = self.data_sheet["D9"].value
        prod3_quan = self.data_sheet["D10"].value
        prod3_color = self.data_sheet["D11"].value

        # Enter the category:
        self.wait.visibility(
            (By.ID, "headphonesImg"))  # Wait for the homepage to load.
        Homepage(self.driver).enter_category(
            chosen_cat)  # Enter the chosen category.

        # Ordering 1st product:
        category = Categories(
            self.driver)  # Defining a variable for the category page.
        category.enter_product(prod1_id)
        self.wait.visibility(
            (By.ID, "Description"))  # Wait for the product page to load.
        product = Products(
            self.driver)  # Defining a variable for the product pages.
        # Creating a variable with the product's name for the testing assertions:
        prod1_name = product.product_name()
        # Creating a variable with the product's unit price for the testing assertions:
        prod1_price = product.product_price()
        product.choose_color(prod1_color)
        product.choose_quantity(prod1_quan)
        product.click_add_to_cart()
        self.driver.back()

        # Ordering 2nd product:
        category.enter_product(prod2_id)
        self.wait.visibility((By.ID, "Description"))
        prod2_name = product.product_name()
        prod2_price = product.product_price()
        product.choose_color(prod2_color)
        product.choose_quantity(prod2_quan)
        product.click_add_to_cart()
        self.driver.back()

        # Ordering 3rd product:
        category.enter_product(prod3_id)
        self.wait.visibility((By.ID, "Description"))
        prod3_name = product.product_name()
        prod3_price = product.product_price()
        product.choose_color(prod3_color)
        product.choose_quantity(prod3_quan)
        product.click_add_to_cart()

        # Waiting for the cart pop-up menu to appear before the assertions stage:
        self.wait.visibility(
            (By.XPATH, "//table[@ng-show='cart.productsInCart.length > 0']"))

        # Printing the test data for compairson:
        print(
            f"Product 1:\n"
            f"Name: Desired - {prod1_name}, Actual - {self.general.popup_cart_name(3)} \n"
            f"Color: Desired - {prod1_color}, Actual - {self.general.popup_cart_color(3)[7:]} \n"
            f"Quantity: Desired - {prod1_quan}, Actual - {self.general.popup_cart_quantity(3)[5:]} \n"
            f"Price: Desired - {prod1_price} * {str(prod1_quan)}, Actual - {self.general.popup_cart_price(3)}"
        )
        print(
            f"Product 2:\n"
            f"Name: Desired - {prod2_name}, Actual - {self.general.popup_cart_name(2)} \n"
            f"Color: Desired - {prod2_color}, Actual - {self.general.popup_cart_color(2)[7:]} \n"
            f"Quantity: Desired - {prod2_quan}, Actual - {self.general.popup_cart_quantity(2)[5:]} \n"
            f"Price: Desired - {prod2_price} * {str(prod2_quan)}, Actual - {self.general.popup_cart_price(2)}"
        )
        print(
            f"Product 3:\n"
            f"Name: Desired - {prod3_name}, Actual - {self.general.popup_cart_name(1)} \n"
            f"Color: Desired - {prod3_color}, Actual - {self.general.popup_cart_color(1)[7:]} \n"
            f"Quantity: Desired - {prod3_quan}, Actual - {self.general.popup_cart_quantity(1)[5:]} \n"
            f"Price: Desired - {prod3_price} * {str(prod3_quan)}, Actual - {self.general.popup_cart_price(1)}"
        )
        # Making sure the test passed using the prod variables and General class functions:

        # Pop-up cart names = Products' names:
        # List with all the prod_name variables sorted according to their order in the cart.
        names_list = [prod3_name, prod2_name, prod1_name]
        for i in names_list:
            # Because the cart pop-up menu shortens product names > 27 letters, the assertion has an IF condition:
            # IF the product name is > 27, only the first 27 letters are used for the assertion.
            if len(i) > 27:
                self.assertEqual(
                    i[0:27],
                    self.general.popup_cart_name(names_list.index(i) +
                                                 1)[0:27])
            else:
                self.assertEqual(
                    i, self.general.popup_cart_name(names_list.index(i) + 1))

        # Pop-up cart colors = Products' colors:
        self.assertEqual(f"Color: {prod1_color}",
                         self.general.popup_cart_color(3))
        self.assertEqual(f"Color: {prod2_color}",
                         self.general.popup_cart_color(2))
        self.assertEqual(f"Color: {prod3_color}",
                         self.general.popup_cart_color(1))

        # Pop-up cart quantity = Products' quantity:
        self.assertEqual(f"QTY: {prod1_quan}",
                         self.general.popup_cart_quantity(3))
        self.assertEqual(f"QTY: {prod2_quan}",
                         self.general.popup_cart_quantity(2))
        self.assertEqual(f"QTY: {prod3_quan}",
                         self.general.popup_cart_quantity(1))

        # Pop-up cart price = Products' price:
        # Every product's unit price is converted to a float and multiplied by the ordered quantity,
        # then it's compared to the pop-up menu's final price (also converted to float and removed the "$").
        self.assertEqual(
            float(prod1_price[1:]) * prod1_quan,
            float(self.general.popup_cart_price(3)[1:]))
        self.assertEqual(
            float(prod2_price[1:]) * prod2_quan,
            float(self.general.popup_cart_price(2)[1:]))
        self.assertEqual(
            float(prod3_price[1:]) * prod3_quan,
            float(self.general.popup_cart_price(1)[1:]))

        # Writing the result in the excel sheet:
        self.data_sheet["D24"] = "V"
Exemplo n.º 5
0
    def test_aos005(self):
        print("AOS Test 5")
        # Defining products and quantities for the test using the excel sheet:
        chosen_cat = self.data_sheet["G2"].value
        prod1_id = self.data_sheet["G3"].value
        prod1_quan = self.data_sheet["G4"].value
        prod2_id = self.data_sheet["G6"].value
        prod2_quan = self.data_sheet["G7"].value
        prod3_id = self.data_sheet["G9"].value
        prod3_quan = self.data_sheet["G10"].value

        # Enter the category:
        self.wait.visibility(
            (By.ID, "laptopsImg"))  # Wait for the homepage to load.
        Homepage(self.driver).enter_category(
            chosen_cat)  # Entering the chosen category.

        # Ordering 1st product:
        category = Categories(
            self.driver)  # Defining a variable for the category page.
        category.enter_product(prod1_id)
        self.wait.visibility(
            (By.ID,
             "Description"))  # Wait for the product description to be visible.
        product = Products(
            self.driver)  # Defining a variable for the product pages.
        product.choose_quantity(prod1_quan)
        prod1_name = product.product_name(
        )  # Defining a variable with the product's name for the assertions.
        prod1_price = product.product_price(
        )  # Defining a variable with the product's price for the assertions.
        product.click_add_to_cart()
        self.driver.back()

        # Ordering 2nd product:
        category.enter_product(prod2_id)
        self.wait.visibility((By.ID, "Description"))
        product.choose_quantity(prod2_quan)
        prod2_name = product.product_name()
        prod2_price = product.product_price()
        product.click_add_to_cart()
        self.driver.back()

        # Ordering 3rd product:
        category.enter_product(prod3_id)
        self.wait.visibility((By.ID, "Description"))
        product.choose_quantity(prod3_quan)
        prod3_name = product.product_name()
        prod3_price = product.product_price()
        product.click_add_to_cart()

        # Entering the cart page:
        self.general.enter_cart_page()
        # Waiting for the cart page to load:
        self.wait.visibility((By.CLASS_NAME, "fixedTableEdgeCompatibility"))
        cart = Cart(self.driver)  # Defining a variable for the Cart class.

        # Making sure the test passed by comparing the data in the cart table to the products' info:
        # Products' quantities:
        self.assertEqual(str(prod1_quan), cart.cart_quantities(3))
        self.assertEqual(str(prod2_quan), cart.cart_quantities(2))
        self.assertEqual(str(prod3_quan), cart.cart_quantities(1))

        # Products' prices:
        # Creating a variable for every product's final price to check the site made the right calculations:
        prod1_final_price = float(prod1_price[1:]) * prod1_quan
        prod2_final_price = float(prod2_price[1:]) * prod2_quan
        prod3_final_price = float(prod3_price[1:]) * prod3_quan

        # Using a list and an IF condition for the final price test.
        # IF the price > 999, the STR needs an additional "," for the assertions to pass.
        # The list's indexes are matching the cart order.
        final_prices = [
            prod3_final_price, prod2_final_price, prod1_final_price
        ]
        for i in final_prices:
            if i > 999:
                final_price_str = str(i)[0] + "," + str(i)[1:]
                self.assertEqual(f"${final_price_str}",
                                 cart.cart_prices(final_prices.index(i) + 1))
            else:
                self.assertEqual(f"${i}",
                                 cart.cart_prices(final_prices.index(i) + 1))

        # Printing the products' details for comparison:
        print(f"1st product: {prod1_name} \n   "
              f"Quantity: {prod1_quan} \n   "
              f"Price: {prod1_price} \n   "
              f"Final Price: {prod1_final_price}")
        print(f"2nd product: {prod2_name} \n   "
              f"Quantity: {prod2_quan} \n   "
              f"Price: {prod2_price} \n   "
              f"Final Price: {prod2_final_price}")
        print(f"3rd product: {prod3_name} \n   "
              f"Quantity: {prod3_quan} \n   "
              f"Price: {prod3_price} \n   "
              f"Final Price: {prod3_final_price}")

        # Writing the result in the excel sheet:
        self.data_sheet["G24"] = "V"