2

I have 2 classes in python and both of them extend the unittest.TestCase class. Hence I have 2 test cases. These test cases (classes) are:

class Test_ID_94017(unittest.TestCase):
    ex = Excel()

    def setUp(self):
        self.driver = Browser().createBrowserDriver()
        self.driver.maximize_window()
        self.driver.implicitly_wait(15)
        self.ex.setUpASheetInExcel('Login')

    def test_CCPD_Regression001_PER_Custom_Check(self):
        ccp = CCPLogin(self.driver)
        loginDetails = self.ex.getLoginDetailsForATestCaseFromExcel('Login', '94017')
        ccp.login(loginDetails[0], loginDetails[1], loginDetails[2])

        wait = WebDriverWait(self.driver, 20)

        wait.until(lambda driver:self.driver.title.startswith('Harland Clarke'))
        self.assertIn("Harland Clarke Checks Online Catalog", self.driver.title, "Failed on CHECKS ONLINE CATALOG PAGE")

        Home().clickOrderButton(self.driver)
        PersonalHurdle().clickProceedWithNoChangeLink(self.driver)
        pc = ProductConfig()
        pc.confirmAddress(self.driver, False)
        pc.clickContinueButton(self.driver)

        wait.until(lambda driver:self.driver.title.startswith('Customize Your Check'))     
        self.assertIn("Customize Your Check", self.driver.title)

        try:
            updateButtonHidden = self.driver.find_element_by_xpath(CustomizeYourCheckPage.UPDATE_BUTTON)
            self.assertIn("hidden", updateButtonHidden.get_attribute('style'))
        except NoSuchElementException:
            assert 0, "Can't find hidden button"

        self.driver.find_element_by_xpath(CustomizeYourCheckPage.SECOND_FONT).click()
        updateButtonVisible = self.driver.find_element_by_xpath(CustomizeYourCheckPage.UPDATE_BUTTON)

        self.assertIn("visible", updateButtonVisible.get_attribute('style'))

        CustomizeYourCheck().clickAddToCartButton(self.driver)
        time.sleep(5)
        OrderExtraTodayPopup().clickNoThanksButton(self.driver)

        wait.until(lambda driver:self.driver.title.startswith('Shopping Cart'))
        assert "Shopping Cart" in self.driver.title

        sc = ShoppingCart()
        sc.selectItemQuantity(self.driver)
        sc.clickProceedToCheckoutButton(self.driver)

        wait.until(lambda driver:self.driver.title.startswith('Checkout'))
        self.assertIn("Checkout", self.driver.title)

        wait.until(lambda driver:self.driver.find_element_by_xpath(CheckoutStep1Page.SELECT_SHIPPING_METHOD_LINK).is_displayed())
        self.driver.find_element_by_xpath(CheckoutStep1Page.SELECT_SHIPPING_METHOD_LINK).click()

        time.sleep(10)

        ShippingMethod().selectAShippingMethod(self.driver)
        cs1 = CheckoutStep1()
        cs1.enterEmailAddress(self.driver, "praveen@email.com")
        cs1.clickProceedToOrderSummary(self.driver)

        wait.until(lambda driver:self.driver.title.startswith('Order Summary'))
        self.assertIn("Order Summary", self.driver.title)

        OrderSummary().clickSubmitOrderButton(self.driver)

        wait.until(lambda driver:self.driver.title.startswith('Order Confirmation'))
        self.assertIn("Order Confirmation", self.driver.title)

        OrderConfirmation().clickLogoutLink(self.driver)

        wait.until(lambda driver:self.driver.find_element_by_css_selector(LogoutPopupWindow.YES_BUTTON).is_displayed())
        self.driver.find_element_by_css_selector(LogoutPopupWindow.YES_BUTTON).click()

    def tearDown(self):
        self.driver.close()

AND

class Test_ID_94018(unittest.TestCase):
    ex = Excel()

    def setUp(self):
        self.driver = Browser().createBrowserDriver()
        self.driver.maximize_window()
        self.driver.implicitly_wait(15)
        self.ex.setUpASheetInExcel('Login')

    def test_CCPD_Regression002_PER_Std_Check(self):
        ccp = CCPLogin(self.driver)
        loginDetails = self.ex.getLoginDetailsForATestCaseFromExcel('Login', '94018')
        ccp.login(loginDetails[0], loginDetails[1], loginDetails[2])

        wait = WebDriverWait(self.driver, 15)

        wait.until(lambda driver:self.driver.title.startswith('Harland Clarke'))
        self.assertIn("Harland Clarke Checks Online Catalog", self.driver.title, "Failed on CHECKS ONLINE CATALOG PAGE")

        PersonalHurdle(self.driver).clickProceedWithNoChangeLink()
        pc = ProductConfig(self.driver)
        pc.confirmAddress(False)
        pc.clickContinueButton()

        wait.until(lambda driver:self.driver.title.startswith('Customize Your Check'))     
        self.assertIn("Customize Your Check", CustomizeYourCheckPage)

        CustomizeYourCheck(self.driver).clickAddToCartButton()
        OrderExtraTodayPopup(self.driver).clickNoThanksButton()

        wait.until(lambda driver:self.driver.title.startswith('Shopping Cart'))
        assert "Shopping Cart" in self.driver.title

        sc = ShoppingCart(self.driver)
        sc.selectItemQuantity()
        sc.clickProceedToCheckoutButton()

        wait.until(lambda driver:self.driver.title.startswith('Checkout'))
        self.assertIn("Checkout", self.driver.title)

        wait.until(lambda driver:self.driver.find_element_by_xpath(CheckoutStep1Page.SELECT_SHIPPING_METHOD_LINK).is_displayed())
        self.driver.find_element_by_xpath(CheckoutStep1Page.SELECT_SHIPPING_METHOD_LINK).click()

        time.sleep(10)

        ShippingMethod(self.driver).selectAShippingMethod()
        cs1 = CheckoutStep1(self.driver)
        cs1.enterEmailAddress("praveen@email.com")
        cs1.clickProceedToOrderSummary()

        wait.until(lambda driver:self.driver.title.startswith('Order Summary'))
        self.assertIn("Order Summary", self.driver.title)

        OrderSummary(self.driver).clickSubmitOrderButton()

        wait.until(lambda driver:self.driver.title.startswith('Order Confirmation'))
        self.assertIn("Order Confirmation", self.driver.title)

        OrderConfirmation(self.driver).clickLogoutLink()

        wait.until(lambda driver:self.driver.find_element_by_css_selector(LogoutPopupWindow.YES_BUTTON).is_displayed())
        self.driver.find_element_by_css_selector(LogoutPopupWindow.YES_BUTTON).click()

    def tearDown(self):
        self.driver.close()

Problem is when I try to run it in Eclipse through PyUnit, only the first test case executes, passes and gives me the result. The second test case does not execute at all. I remember, it was executing both the test cases earlier but I'm not sure why is it not executing both of them now. Please advice. Need help here as I am blocked now!

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Praveen Pandey
  • 658
  • 3
  • 16
  • 32
  • How is your code structed? How are you trying to run them? – doctorlove Aug 19 '13 at 10:58
  • To run them, there is a green **Run** button with a drop down in it. From the drop down, I select Run As > Python unit-test. It automatically runs the test cases but now it runs only the first one and not the second one. Don't know why. – Praveen Pandey Aug 19 '13 at 11:07
  • I don't have eclipse so I can't help. I usually run all my tests from a prompt. I would guess it's some eclipse settings: see http://stackoverflow.com/questions/14104404/py-test-silently-skips-tests-with-errors-in-them-using-pydev-eclipse or http://stackoverflow.com/questions/3343205/how-to-use-py-test-from-python. Do they all run ok from a prompt? – doctorlove Aug 20 '13 at 08:55
  • Sorry @doctorlove but would you mind helping me to run my test cases through command prompt? I am not sure how to do that but I would be happy to try it and see if it runs both the test cases. – Praveen Pandey Aug 20 '13 at 10:03
  • python my_test_file.py (provided you have main setup right) – doctorlove Aug 20 '13 at 10:17

0 Answers0