コード例 #1
0
 def test_user_should_be_able_to_delete_item_from_cart(self):
     self.homePage = HomePage(self.driver)
     self.homePage.search()
     self.searchResultsPage = SearchResultsPage(self.homePage.driver)
     self.searchResultsPage.click_search_result()
     self.searchResultsPage.driver.switch_to.window(
         self.searchResultsPage.driver.window_handles[0])
     self.productDetailsPage = ProductDetailsPage(
         self.searchResultsPage.driver)
     self.productDetailsPage.click_add_to_cart_button()
     self.subCartPage = SubCartPage(self.productDetailsPage.driver)
     # click on the Cart's hyperlink to load the cart page
     self.subCartPage.click_cart_link()
     # instantiate an object of Cart Page class
     self.cartPage = CartPage(self.subCartPage.driver)
     # find the cart count before deleting an item from the cart
     cartCountBeforeDeletion = int(
         self.driver.find_element(*Locators.CART_COUNT).text)
     print(cartCountBeforeDeletion)
     # delete an item from cart
     self.cartPage.delete_item()
     # to assert the item was deleted successfully
     self.assertTrue(
         int(self.driver.find_element(
             *Locators.CART_COUNT).text) < cartCountBeforeDeletion)
コード例 #2
0
 def test_user_must_signin_to_checkout(self):
     self.homePage = HomePage(self.driver)
     self.homePage.search()
     self.searchResultsPage = SearchResultsPage(self.homePage.driver)
     self.searchResultsPage.click_search_result()
     self.searchResultsPage.driver.switch_to.window(
         self.searchResultsPage.driver.window_handles[0])
     self.productDetailsPage = ProductDetailsPage(
         self.searchResultsPage.driver)
     self.productDetailsPage.click_add_to_cart_button()
     self.subCartPage = SubCartPage(self.productDetailsPage.driver)
     self.subCartPage.click_cart_link()
     # instantiate an object of Cart Page class
     self.cartPage = CartPage(self.subCartPage.driver)
     # click on Proceed to Checkout button
     self.cartPage.click_proceed_to_checkout_button()
     # instantiate an object of SignIn Page class
     self.signInPage = SignInPage(self.cartPage.driver)
     # to assert we are in indeed on Sign In Page, first we assert the title of the page
     self.assertTrue(TestData.SIGN_IN_PAGE_TITLE,
                     self.signInPage.driver.title)
     # and then we assert for presence of email textbox on the page
     self.assertTrue(
         self.signInPage.is_visible(
             Locators.USER_EMAIL_OR_MOBIL_NO_TEXTBOX))
コード例 #3
0
 def test_3_user_should_be_able_to_add_item_to_cart(self):
     self.homePage = HomePage(self.driver)
     self.homePage.search()
     self.searchResultsPage = SearchResultsPage(self.homePage.driver)
     # click on the first search result
     self.searchResultsPage.click_search_result()
     # instantiate an object of Product Details Page class
     self.productDetailsPage = ProductDetailsPage(
         self.searchResultsPage.driver)
     # click on the Add To Cart button
     self.productDetailsPage.click_add_to_cart_button()
     # instantiate an object of Sub Cart Page class
     self.subCartPage = SubCartPage(self.productDetailsPage.driver)
     # assert if the sub cart page has indeed loaded
     self.assertTrue(self.subCartPage.is_enabled(Locators.SUB_CART_DIV))
     # assert if the product was added to the cart successfully
     self.assertTrue(
         self.searchResultsPage.is_visible(Locators.PROCEED_TO_BUY_BUTTON))
コード例 #4
0
class Test_Amazon_Search(Test_Amazon_Search_Base):
    def setUp(self):
        super().setUp()

    def test_1_home_page_should_load(self):
        # instantiate an object of HomePage class.
        # it opens up the browser and navigates to Home Page of the site under test.
        self.homePage = HomePage(self.driver)
        # assert if the title of Home Page contains Amazon.in
        self.assertIn(TestData.HOME_PAGE_TITLE, self.homePage.driver.title)

    def test_2_user_should_be_able_to_search(self):
        self.homePage = HomePage(self.driver)
        # search for the search term on Home Page.
        # The search term would be picked from TestData.py file
        self.homePage.search()
        # instantiate an object of SearchResultsPage class passing in the driver as parameter.
        # this will allow the newly created object to have access to the browser and perform
        # webdriver operations.
        self.searchResultsPage = SearchResultsPage(self.homePage.driver)
        # assert that the search term indeed return some results.
        self.assertNotIn(TestData.NO_RESULTS_TEXT,
                         self.searchResultsPage.driver.page_source)

    def test_3_user_should_be_able_to_add_item_to_cart(self):
        self.homePage = HomePage(self.driver)
        self.homePage.search()
        self.searchResultsPage = SearchResultsPage(self.homePage.driver)
        # click on the first search result
        self.searchResultsPage.click_search_result()
        # instantiate an object of Product Details Page class
        self.productDetailsPage = ProductDetailsPage(
            self.searchResultsPage.driver)
        # click on the Add To Cart button
        self.productDetailsPage.click_add_to_cart_button()
        # instantiate an object of Sub Cart Page class
        self.subCartPage = SubCartPage(self.productDetailsPage.driver)
        # assert if the sub cart page has indeed loaded
        self.assertTrue(self.subCartPage.is_enabled(Locators.SUB_CART_DIV))
        # assert if the product was added to the cart successfully
        self.assertTrue(
            self.searchResultsPage.is_visible(Locators.PROCEED_TO_BUY_BUTTON))

    def test_4_user_should_be_able_to_delete_item_from_cart(self):
        self.homePage = HomePage(self.driver)
        self.homePage.search()
        self.searchResultsPage = SearchResultsPage(self.homePage.driver)
        self.searchResultsPage.click_search_result()
        self.productDetailsPage = ProductDetailsPage(
            self.searchResultsPage.driver)
        self.productDetailsPage.click_add_to_cart_button()
        self.subCartPage = SubCartPage(self.productDetailsPage.driver)
        # click on the Cart's hyperlink to load the cart page
        self.subCartPage.click_cart_link()
        # instantiate an object of Cart Page class
        self.cartPage = CartPage(self.subCartPage.driver)
        # find the cart count before deleting an item from the cart
        cartCountBeforeDeletion = int(
            self.driver.find_element(*Locators.CART_COUNT).text)
        # delete an item from cart
        self.cartPage.delete_item()
        #to assert the item was deleted successfully
        self.assertTrue(
            int(self.driver.find_element(
                *Locators.CART_COUNT).text) < cartCountBeforeDeletion)
コード例 #5
0
class TestAMZNSearch(TestAMZNSearchBase):
    def setUp(self):
        super().setUp()

    def test_home_page_loaded_successfully(self):
        # instantiate an object of HomePage class. Remember when the constructor of HomePage class is called
        # it opens up the browser and navigates to Home Page of the site under test.
        self.homePage = HomePage(self.driver)
        # assert if the title of Home Page contains Amazon.in
        self.assertIn(TestData.HOME_PAGE_TITLE, self.homePage.driver.title)

    def test_user_should_be_able_to_search(self):
        self.homePage = HomePage(self.driver)
        # search for the search term on Home Page. The search term would be picked from
        # test data file
        self.homePage.search()
        # instantiate an object of SearchResultsPage class passing in the driver as parameter.
        # this will allow the newly created object to have access to the browser and perform
        # operations further.
        self.searchResultsPage = SearchResultsPage(self.homePage.driver)
        # assert if the search term is present in the title of the Amazon's Search Results Page
        self.assertIn(TestData.SEARCH_TERM,
                      self.searchResultsPage.driver.title)
        # assert that the search term indeed return some results.
        self.assertNotIn(TestData.NO_RESULTS_TEXT,
                         self.searchResultsPage.driver.page_source)

    def test_user_should_be_able_to_add_item_to_cart(self):
        self.homePage = HomePage(self.driver)
        self.homePage.search()
        self.searchResultsPage = SearchResultsPage(self.homePage.driver)
        # click on the first search result
        self.searchResultsPage.click_search_result()
        # since the click on search result loads the product in new tab, switch to new tab
        self.searchResultsPage.driver.switch_to.window(
            self.searchResultsPage.driver.window_handles[0])
        # instantiate an object of Product Details Page class
        self.productDetailsPage = ProductDetailsPage(
            self.searchResultsPage.driver)
        # click on the Add To Cart button
        self.productDetailsPage.click_add_to_cart_button()
        # instantiate an object of Sub Cart Page class
        self.subCartPage = SubCartPage(self.productDetailsPage.driver)
        # assert if the sub cart page has indeed loaded
        self.assertTrue(self.subCartPage.is_enabled(Locators.SUB_CART_DIV))
        # assert if the product was added to the cart successfully
        self.assertTrue(
            self.searchResultsPage.is_visible(Locators.PROCEED_TO_BUY_BUTTON))

    def test_user_should_be_able_to_delete_item_from_cart(self):
        self.homePage = HomePage(self.driver)
        self.homePage.search()
        self.searchResultsPage = SearchResultsPage(self.homePage.driver)
        self.searchResultsPage.click_search_result()
        self.searchResultsPage.driver.switch_to.window(
            self.searchResultsPage.driver.window_handles[0])
        self.productDetailsPage = ProductDetailsPage(
            self.searchResultsPage.driver)
        self.productDetailsPage.click_add_to_cart_button()
        self.subCartPage = SubCartPage(self.productDetailsPage.driver)
        # click on the Cart's hyperlink to load the cart page
        self.subCartPage.click_cart_link()
        # instantiate an object of Cart Page class
        self.cartPage = CartPage(self.subCartPage.driver)
        # find the cart count before deleting an item from the cart
        cartCountBeforeDeletion = int(
            self.driver.find_element(*Locators.CART_COUNT).text)
        print(cartCountBeforeDeletion)
        # delete an item from cart
        self.cartPage.delete_item()
        # to assert the item was deleted successfully
        self.assertTrue(
            int(self.driver.find_element(
                *Locators.CART_COUNT).text) < cartCountBeforeDeletion)

    def test_user_must_signin_to_checkout(self):
        self.homePage = HomePage(self.driver)
        self.homePage.search()
        self.searchResultsPage = SearchResultsPage(self.homePage.driver)
        self.searchResultsPage.click_search_result()
        self.searchResultsPage.driver.switch_to.window(
            self.searchResultsPage.driver.window_handles[0])
        self.productDetailsPage = ProductDetailsPage(
            self.searchResultsPage.driver)
        self.productDetailsPage.click_add_to_cart_button()
        self.subCartPage = SubCartPage(self.productDetailsPage.driver)
        self.subCartPage.click_cart_link()
        # instantiate an object of Cart Page class
        self.cartPage = CartPage(self.subCartPage.driver)
        # click on Proceed to Checkout button
        self.cartPage.click_proceed_to_checkout_button()
        # instantiate an object of SignIn Page class
        self.signInPage = SignInPage(self.cartPage.driver)
        # to assert we are in indeed on Sign In Page, first we assert the title of the page
        self.assertTrue(TestData.SIGN_IN_PAGE_TITLE,
                        self.signInPage.driver.title)
        # and then we assert for presence of email textbox on the page
        self.assertTrue(
            self.signInPage.is_visible(
                Locators.USER_EMAIL_OR_MOBIL_NO_TEXTBOX))