예제 #1
0
    def choose_spinner_value(cls,
                             element_name,
                             element_value,
                             option_value=None):
        """
        Choose a certain option from a drop_down list
        
        :Args:
         - element_name:     Element of drop_down list, the type is WebElement
         - element_value:    Items(options) of drop_down list, the type is string list
         - option_value:     The item/option which will be clicked for choosing, the type is sting
        
        :Usage: Always used in case execution modules
            POFS_EXPTYPE = Element.find_elements(self.driver, By.XPATH, u'//select[@name="exportType"]/option')
            POFS_EXPTYPE_CONTENT = Element.get_spinner_values(self.driver, By.XPATH, u'//select[@name="exportType"]/option')
            Element.choose_spinner_value(POFS_EXPTYPE, POFS_EXPTYPE_CONTENT, "LCL")
        """

        if isinstance(element_name, list):
            for item in range(len(element_value)):
                if option_value == element_value[item]:
                    element_name[item].click()
                    print "Drop-down list: Element %s is chosen" % (
                        element_name[item].text)
                    Log.step_succ("Drop-down list: Element %s is chosen" %
                                  (element_name[item].text))
                    break
            else:
                print "Drop-down list: Element [ %s ] not found" % (
                    option_value)
                Log.step_fail("Drop-down list: Element [ %s ] not found" %
                              (option_value))
        else:
            print "Drop-down list: %s is not a list" % (element_name)
            Log.step_fail("Drop-down list: %s is not a list" % (element_name))
예제 #2
0
 def choose_spinner_value(cls, element_name, element_value, option_value=None):
     """
     Choose a certain option from a drop_down list
     
     :Args:
      - element_name:     Element of drop_down list, the type is WebElement
      - element_value:    Items(options) of drop_down list, the type is string list
      - option_value:     The item/option which will be clicked for choosing, the type is sting
     
     :Usage: Always used in case execution modules
         POFS_EXPTYPE = Element.find_elements(self.driver, By.XPATH, u'//select[@name="exportType"]/option')
         POFS_EXPTYPE_CONTENT = Element.get_spinner_values(self.driver, By.XPATH, u'//select[@name="exportType"]/option')
         Element.choose_spinner_value(POFS_EXPTYPE, POFS_EXPTYPE_CONTENT, "LCL")
     """
     
     if isinstance(element_name, list):
         for item in range(len(element_value)):
             if option_value == element_value[item]:
                 element_name[item].click()
                 print "Drop-down list: Element %s is chosen" % (element_name[item].text)
                 Log.step_succ("Drop-down list: Element %s is chosen" % (element_name[item].text))
                 break
         else:
             print "Drop-down list: Element [ %s ] not found" % (option_value)
             Log.step_fail("Drop-down list: Element [ %s ] not found" % (option_value))
     else:
         print "Drop-down list: %s is not a list" % (element_name)
         Log.step_fail("Drop-down list: %s is not a list" % (element_name))
예제 #3
0
    def switch_to_default_window(cls):
        """
        :Purpose: Switch to the primary(the last one page) page if system is 
                    focusing on the pop up page(the new page).
                    Function just think about there're two windows(handles)
                    at the same time.
        
        :Args:
         - driver : Instance of webdriver
        
        :Usage:
            Browser.switch_to_default_window(self.driver)
        """
        win_handles_num = cls.get_windows()
        if 1 <= len(win_handles_num) <= 2:
            #             driver.switch_to_window(cls.get_windows(driver)[0])
            Conf.DRIVER.switch_to_window(Conf.DRIVER.window_handles[0])


#             driver.switch_to.default_content()                #do not work
        else:
            print "There are %d windows handles available, 2 handles is valid." % len(
                win_handles_num)
            Log.step_fail(
                "There are %d windows handles available, 2 handles is valid." %
                len(win_handles_num))
예제 #4
0
 def open_connection(cls, database_type):
     if database_type is "mysql":
         try:
             conn = MySQLdb.connect(Conf.DB_IP, Conf.DB_USERNAME, Conf.DB_PASSWORD, Conf.DB_NAME, charset = Conf.DB_CHARSET)
             print "Create connection of MySQL successfully."
             Log.step_succ("Create connection of MySQL successfully.")
         except Exception  as e:
             print "Create connection of MySQL failed."
             Log.step_fail("Create connection of MySQL failed.")
         return conn
     elif database_type is "oracle":
         pass
     elif database_type is "sqlite":
         pass
     else:
         print "Database Error : Undefined database type."
         Log.step_fail("Undefined database type.")
         return None
예제 #5
0
    def switch_to_default_window(cls):
        """
        :Purpose: Switch to the primary(the last one page) page if system is 
                    focusing on the pop up page(the new page).
                    Function just think about there're two windows(handles)
                    at the same time.
        
        :Args:
         - driver : Instance of webdriver
        
        :Usage:
            Browser.switch_to_default_window(self.driver)
        """
        win_handles_num = cls.get_windows()
        if 1 <= len(win_handles_num) <= 2:
#             driver.switch_to_window(cls.get_windows(driver)[0])
            Conf.DRIVER.switch_to_window(Conf.DRIVER.window_handles[0])
#             driver.switch_to.default_content()                #do not work
        else:
            print "There are %d windows handles available, 2 handles is valid." % len(win_handles_num)
            Log.step_fail("There are %d windows handles available, 2 handles is valid." % len(win_handles_num))
예제 #6
0
    def switch_to_new_window(cls):
        """
        :Purpose: Switch to the new (the pop-up page) page if system is 
                    focusing on the current page(the primary page).
                    Function just think about there're two windows(handles)
                    at the same time.
        
        :Args:
         - driver : Instance of webdriver
        
        :Usage:
            Browser.switch_to_new_window(self.driver)
        """
        win_handles_num = cls.get_windows()
        if len(win_handles_num) == 2:
            #Cause "get_windows" is set as : @property, so use cls.window_handles
#             driver.switch_to_window(cls.get_windows(driver)[-1])
            Conf.DRIVER.switch_to_window(Conf.DRIVER.window_handles[-1])
        else:
            print "There are %d windows handles available, 2 handles is valid." % len(win_handles_num)
            Log.step_fail("There are %d windows handles available, 2 handles is valid." % len(win_handles_num))    
예제 #7
0
 def switch_to_new_window(cls):
     """
     :Purpose: Switch to the new (the pop-up page) page if system is 
                 focusing on the current page(the primary page).
                 Function just think about there're two windows(handles)
                 at the same time.
     
     :Args:
      - driver : Instance of webdriver
     
     :Usage:
         Browser.switch_to_new_window(self.driver)
     """
     win_handles_num = cls.get_windows()
     if len(win_handles_num) == 2:
         #Cause "get_windows" is set as : @property, so use cls.window_handles
         #             driver.switch_to_window(cls.get_windows(driver)[-1])
         Conf.DRIVER.switch_to_window(Conf.DRIVER.window_handles[-1])
     else:
         print "There are %d windows handles available, 2 handles is valid." % len(
             win_handles_num)
         Log.step_fail(
             "There are %d windows handles available, 2 handles is valid." %
             len(win_handles_num))
예제 #8
0
    def test_tour_order_flight_001(self):
        u"""This is comment of test_case_login_001 shown in report"""
        Conf.CASE_NAME = "test_tour_order_flight_001"
         
        Log.start_test(Conf.CASE_NAME)
        
#         Element.find_element(By.NAME, u'userName').send_keys("a")
#         Element.find_element(By.NAME, u'password').send_keys("a")
#         Element.find_element(By.NAME, u'login').click()
        
        CommonMethod.test_tour_login_common()
        
        
        
        login_flag = Element.find_element(By.XPATH, u'//img[@src="/images/masts/mast_flightfinder.gif"]')
        if login_flag is not None:
            print "Login system successfully."
            Log.step_succ("Login system successfully.")
        else:
            print "Login system failed."
            Log.step_fail("Login system failed.")
            return None
        #### Flight Details
        Element.find_element(By.XPATH, u'//input[@value="oneway"]').click()
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="passCount"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="passCount"]/option'),
                                                  "4")
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="fromPort"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="fromPort"]/option'),
                                                  "Paris")
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="fromMonth"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="fromMonth"]/option'),
                                                  "September")
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="fromDay"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="fromDay"]/option'),
                                                  "9")
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="toPort"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="toPort"]/option'),
                                                  "London")
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="toMonth"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="fromMonth"]/option'),
                                                  "October")
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="toDay"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="fromDay"]/option'),
                                                  "19")
        
        #### Preferences
        Element.find_element(By.XPATH, u'//input[@value="Business"]').click()
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="airline"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="airline"]/option'),
                                                  "Unified Airlines")
        Element.find_element(By.NAME, "findFlights").click()
        
        #### DEPART
        if "DEPART" in Element.find_element(By.XPATH, u'//font[@color="#FF9900"][text()="DEPART"]').text:
            print "Navigate success, please choosing departure item."
            Log.step_succ("Navigate success, please choosing departure item.")
        else:
            print "Navigate failed, please check info in FLIGHT FINDER."
            Log.step_fail("Navigate failed, please check info in FLIGHT FINDER.")
            return None
        
        Element.find_element(By.XPATH, u'//input[@value="Pangea Airlines$362$274$9:17"][@name="outFlight"]').click()
        #### RETURN
        Element.find_element(By.XPATH, u'//input[@value="Blue Skies Airlines$631$273$14:30"][@name="inFlight"]').click()
        Element.find_element(By.NAME, u'reserveFlights').click()
        
        #### BOOK A FLIGHT
        book_flight = Element.find_element(By.XPATH, u'//img[@src="/images/masts/mast_book.gif"]')
        if book_flight is not None:
            print "Navigate success, please complete the form to book the flight online."
            Log.step_succ("Navigate success, please complete the form to book the flight online.")
        else:
            print "Navigate failed, please check DEPART/RETURN info in SELECT FLIGHT."
            Log.step_fail("Navigate failed, please check DEPART/RETURN info in SELECT FLIGHT.")
            return None
        
        Element.find_element(By.NAME, u'passFirst0').send_keys("Jiefeng")
        Element.find_element(By.NAME, u'passLast0').send_keys("Gao")
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="pass.0.meal"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="pass.0.meal"]/option'),
                                                  "Diabetic")
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="creditCard"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="creditCard"]/option'),
                                                  "Discover")
        Element.find_element(By.NAME, u'creditnumber').send_keys("0000000000000000000")
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="cc_exp_dt_mn"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="cc_exp_dt_mn"]/option'),
                                                  "06")
        Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="cc_exp_dt_yr"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="cc_exp_dt_yr"]/option'),
                                                  "2008")
        Element.find_element(By.NAME, u'cc_frst_name').send_keys("Gao")
        Element.find_element(By.NAME, u'cc_mid_name').send_keys("Jie")
        Element.find_element(By.NAME, u'cc_last_name').send_keys("feng")
        Element.find_element(By.NAME, u'ticketLess').click()
        
        Element.checkbox_all(Element.find_elements(By.NAME, u'ticketLess'))
        
        Element.find_element(By.NAME, u'buyFlights').click()
        
        #### FLIGHT CONFIRMATION
        confirmation_message = Element.find_element(By.XPATH, u'//img[@src="/images/masts/mast_confirmation.gif"]')
        if confirmation_message is not None:
            print "Book a flight successfully."
            Log.step_succ("Book a flight successfully.")
        else:
            print "Book a flight failed."
            Log.step_fail("Book a flight failed.")
        
        Element.find_element(By.XPATH, u'//img[@ src="/images/forms/home.gif"]').click()
        
        """Here's something should do calculate :
                Total Taxes:      $44 USD
                Total Price (including taxes):      $584 USD
        """
        
        Browser.navigate_to(Conf.URL)
        Log.stop_test()
예제 #9
0
    def test_tour_register_001(self):
        u"""This is comment of test_case_login_001 shown in report"""
        Conf.CASE_NAME = "test_tour_register_001"
        register_text = "000To create your account, we'll need some basic information about you. This information will be used to send reservation confirmation emails, mail tickets when needed and contact you if your travel arrangements change. Please fill in the form completely."
         
        Log.start_test(Conf.CASE_NAME)
        
        Element.find_element(By.LINK_TEXT, u'REGISTER').click()
        time.sleep(2)
        register_desc = Element.find_element(By.XPATH, u'html/body/div[1]/table/tbody/tr/td[2]/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[3]/td/p/font').text
        if "To create your account" in register_desc:
            Log.step_succ("Navigate to register page successfully.")
            Assert().assert_equal(register_text, register_desc)
            
            excel = Datadriver.ExcelSheet(r"Employee.xlsx", "Sheet2")
            
            for i in range(1, excel.nrows()):
                first_name       = excel.cell(i, "first")
                last_name        = excel.cell(i, "last")
                phone            = excel.cell(i, "phone")
                email            = excel.cell(i, "email")
                address1         = excel.cell(i, "address1")
                address2         = excel.cell(i, "address2")
                city             = excel.cell(i, "city")
                state            = excel.cell(i, "state")
                postal           = excel.cell(i, "postal")
                country          = excel.cell(i, "country")
                username         = excel.cell(i, "username")
                password         = excel.cell(i, "password")
                confirm_password = excel.cell(i, "confirm_password")
                
                if first_name !="":
                    Element.find_element(By.NAME, u'firstName').send_keys(first_name)
                if last_name != "":
                    Element.find_element(By.NAME, u'lastName').send_keys(last_name)
                if phone !="":
                    Element.find_element(By.NAME, u'phone').send_keys(phone)
                if email !="":
                    Element.find_element(By.NAME, u'userName').send_keys(email)
                if address1 !="":
                    Element.find_element(By.NAME, u'address1').send_keys(address1)
                if address2 !="":
                    Element.find_element(By.NAME, u'address2').send_keys(address2)
                if city !="":
                    Element.find_element(By.NAME, u'city').send_keys(city)
                if state !="":
                    Element.find_element(By.NAME, u'state').send_keys(state)
                if postal !="":
                    Element.find_element(By.NAME, u'postalCode').send_keys(postal)
                if country != "":
                    Element.choose_spinner_value(Element.find_elements(By.XPATH, u'//select[@name="country"]/option'),
                                                  Element.get_spinner_values(By.XPATH, u'//select[@name="country"]/option'),
                                                  "ANGOLA")
                if username != "":
                    Element.find_element(By.NAME, u'email').send_keys(username)
                if password != "":
                    Element.find_element(By.NAME, u'password').send_keys(password)
                if confirm_password != "":
                    Element.find_element(By.NAME, u'confirmPassword').send_keys(confirm_password)
                Element.find_element(By.NAME, u'register').click()
        else:
            Log.step_fail("Navigate to register page failed.")
        
        register_succ_desc = Element.find_element(By.XPATH, u'html/body/div[1]/table/tbody/tr/td[2]/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[3]/td/p[1]/font/b').text
        if "Dear" in register_succ_desc:
            Log.step_succ("Register for user %s successfully." % username)
        else:
            Log.step_fail("Register for user %s failed." % username)
        
#         Browser.navigate_to( Conf.URL)
        Log.stop_test()