Example #1
0
    def test_case_search_001(self):
        Conf.CASE_NAME = "test_case_search_001"
        Log.start_test(Conf.CASE_NAME)

        CommonMethod.test_pofs_login_common('EDPRBI', 'test')

        Log.stop_test()
Example #2
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))
 def test_case_001_forget_password(self):
     Conf.CASE_NAME = "test_case_001_forget_password"
     
     Log.start_test(Conf.CASE_NAME)
     
     Element.find_element(self.driver, By.CLASS_NAME, u'pass-fgtpwd').click()
     Log.stop_test()
Example #4
0
    def test_case_login_002(self):
        '''Login page, reset button'''
        Conf.CASE_NAME = "test_case_login_002"
         
        Log.start_test(Conf.CASE_NAME)
        
        self.POFS_USERNAME = Element.find_element(By.NAME, u'userName')
        self.POFS_PASSWORD = Element.find_element(By.NAME, u'password')
        self.POFS_RESET = Element.find_element(By.XPATH, u'//input[@type="reset"][@value="Reset"]')
         
        self.POFS_USERNAME.send_keys("EDPRBI")
        self.POFS_PASSWORD.send_keys("test")
        self.POFS_RESET.click()
        
        username = self.driver.execute_script("var input = document.getElementsByName('userName')[0].value;return input")
        password = self.driver.execute_script("var input = document.getElementById('password').value;return input")
        Assert().assert_equal(username, "")
        Assert().assert_equal(password, "")
        if username == "" and password == "":
            print "pass"
        else:
            print "fail"

#         self.driver.get(Conf.URL)
        Browser.navigate_to(Conf.URL)
        
        Log.stop_test()
Example #5
0
 def test_case_search_002(self):
     Conf.CASE_NAME = "test_case_search_002"
     Log.start_test(Conf.CASE_NAME)
     
     POFS_OVERVIEW_SEARCH = Element.find_element(By.XPATH, u'//a[@id="b"][@href="overview/overview.jsp"]')
     POFS_OVERVIEW_SEARCH.click()
     
     POFS_EXPTYPE = Element.find_elements(By.XPATH, u'//select[@name="exportType"]/option')
     POFS_EXPTYPE_CONTENT = Element.get_spinner_values(By.XPATH, u'//select[@name="exportType"]/option')
     Element.choose_spinner_value(POFS_EXPTYPE, POFS_EXPTYPE_CONTENT, "LCL")
     
     POFS_PO_ISSUE_DATE = Element.find_element(By.XPATH, u'//img[@src="../images/cal.gif"]')
     POFS_PO_ISSUE_DATE.click()
     
     Browser.switch_to_new_window()
     Element.date_picker(31, 1, 2008)
     Browser.switch_to_default_window()
     
     POFS_SEARCH = Element.find_element(By.NAME, u'submit')
     POFS_SEARCH.click()
     
     POFS_DETAIL = Element.find_element(By.XPATH, u'//img[@src="../images/detail.gif"]')
     POFS_DETAIL.click()
     Browser.switch_to_new_window()
     POFS_PONUMBER = Element.find_element(By.XPATH, u'//*[@id="printable"]/table/tbody/tr[1]/td/table/tbody/tr[2]/td[2]')
     Assert().assert_equal(POFS_PONUMBER.text, "0000434")
     Browser.close_window()
     Browser.switch_to_default_window()
     
     Log.stop_test()
Example #6
0
    def test_case_login_002(self):
        '''Login page, reset button'''
        Conf.CASE_NAME = "test_case_login_002"

        Log.start_test(Conf.CASE_NAME)

        self.POFS_USERNAME = Element.find_element(By.NAME, u'userName')
        self.POFS_PASSWORD = Element.find_element(By.NAME, u'password')
        self.POFS_RESET = Element.find_element(
            By.XPATH, u'//input[@type="reset"][@value="Reset"]')

        self.POFS_USERNAME.send_keys("EDPRBI")
        self.POFS_PASSWORD.send_keys("test")
        self.POFS_RESET.click()

        username = self.driver.execute_script(
            "var input = document.getElementsByName('userName')[0].value;return input"
        )
        password = self.driver.execute_script(
            "var input = document.getElementById('password').value;return input"
        )
        Assert().assert_equal(username, "")
        Assert().assert_equal(password, "")
        if username == "" and password == "":
            print "pass"
        else:
            print "fail"


#         self.driver.get(Conf.URL)
        Browser.navigate_to(Conf.URL)

        Log.stop_test()
Example #7
0
 def test_case_search_001(self):
     Conf.CASE_NAME = "test_case_search_001"
     Log.start_test(Conf.CASE_NAME)
     
     CommonMethod.test_pofs_login_common('EDPRBI', 'test')
     
     Log.stop_test()
Example #8
0
    def test_case_login_003(self):
        u"""This is comment of test_case_login_003 shown in report"""
        
        Conf.CASE_NAME = "test_case_login_003"
        
        Log.start_test(Conf.CASE_NAME)

        excel = Datadriver.ExcelSheet(r"Employee.xlsx", "Sheet1")
        
        for i in range(1, excel.nrows()):
            employeeID = excel.cell(i, "Empoyee_ID")
            password = excel.cell(i, "Password")
            expect = excel.cell(i, "Expect")
            
            if employeeID !="":
                Element.find_element(self.driver, By.ID, u'TANGRAM__PSP_4__userName').send_keys(employeeID)
            if password != "":
                Element.find_element(self.driver, By.ID, u'TANGRAM__PSP_4__password').send_keys(password)
            Element.find_element(self.driver, By.ID, u'TANGRAM__PSP_4__submit').click()
            print Element.find_element(self.driver, By.ID, u'TANGRAM__PSP_4__error').text
            if expect == "expect_result_1":
                # Maybe the element should be asserted is the same one.
                # Change it in every iteration.
                Assert().assert_equal(Element.find_element(self.driver, By.ID, u'TANGRAM__PSP_4__error').text, expect)
            elif expect == "expect_result_2":
                Assert().assert_equal(Element.find_element(self.driver, By.ID, u'TANGRAM__PSP_4__error').text, expect)
            elif expect == "expect_result_3":
                Assert().assert_equal(Element.find_element(self.driver, By.ID, u'TANGRAM__PSP_4__error').text, expect)
            else:
                return None
#             self.driver.get(Conf.URL)
            Browser.navigate_to(self.driver, Conf.URL)
        
        Log.stop_test()
Example #9
0
def send_mail(attachment_file_name):
    print attachment_file_name
    #     attach_name = attachment_file_name.split('\\')[4].split('.')[0]
    attach_name = attachment_file_name.split('\\')[4]

    sender = Conf.MAIL_SENDER
    receiver = Conf.MAIL_RECEIEVER
    subject = Conf.MAIL_SUBJECT
    smtpserver = Conf.MAIL_SMTPSERVER
    username = Conf.MAIL_USERNAME
    password = Conf.MAIL_PASSWORD

    msgRoot = MIMEMultipart('related')
    msgRoot['Subject'] = subject

    # Construct the attachment
    att = MIMEText(open(attachment_file_name, 'rb').read(), 'base64', 'utf-8')
    att["Content-Type"] = 'application/octet-stream'
    att["Content-Disposition"] = 'attachment; filename=%s' % attach_name
    msgRoot.attach(att)

    smtp = smtplib.SMTP()
    smtp.connect(smtpserver)
    smtp.login(username, password)
    smtp.sendmail(sender, receiver, msgRoot.as_string())
    smtp.quit()
    print "Mail sended successfully"
    Log.init_env_record("Mail sended successfully")
Example #10
0
    def test_case_001_register(self):
        Conf.CASE_NAME = "test_case_001_register"

        Log.start_test(Conf.CASE_NAME)

        PAN_C = Element.find_element(self.driver, By.ID, u'login-create')
        print PAN_C.text
        Log.stop_test()
Example #11
0
    def test_case_001_forget_password(self):
        Conf.CASE_NAME = "test_case_001_forget_password"

        Log.start_test(Conf.CASE_NAME)

        Element.find_element(self.driver, By.CLASS_NAME,
                             u'pass-fgtpwd').click()
        Log.stop_test()
Example #12
0
 def test_case_001_register(self):
     Conf.CASE_NAME = "test_case_001_register"
     
     Log.start_test(Conf.CASE_NAME)
           
     PAN_C = Element.find_element(self.driver, By.ID, u'login-create')
     print PAN_C.text
     Log.stop_test()
Example #13
0
 def assert_not_in(self, member, container, msg=None):
     try:
         self.assertNotIn(member, container, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file("%s\\screenshots\\%s__%s.png" % (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(member)
Example #14
0
 def find_elements(cls, by, value=None):
     '''Return the elements by find_elements()
     '''
     try:
         elename_name = Conf.DRIVER.find_elements(by, value)
     except NoSuchElementException:
         Log.handle_error(Conf.DRIVER)
         
     return elename_name
Example #15
0
 def assert_multi_line_equal(self, first, second, msg=None):
     try:
         self.assertMultiLineEqual(first, second, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file("%s\\screenshots\\%s__%s.png" % (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(second)
Example #16
0
 def assert_not_is_instance(self, obj, cls, msg=None):
     try:
         self.assertNotIsInstance(obj, cls, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file("%s\\screenshots\\%s__%s.png" % (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log("Please change this successful message")
Example #17
0
 def assert_dict_equal(self, d1, d2, msg=None):
     try:
         self.assertDictEqual(d1, d2, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file("%s\\screenshots\\%s__%s.png" % (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(d2)
Example #18
0
    def find_elements(cls, by, value=None):
        '''Return the elements by find_elements()
        '''
        try:
            elename_name = Conf.DRIVER.find_elements(by, value)
        except NoSuchElementException:
            Log.handle_error(Conf.DRIVER)

        return elename_name
Example #19
0
 def assert_tuple_equal(self, tuple1, expr, msg=None):
     try:
         self.assertTupleEqual(tuple1, expr, msg)
     except AssertionError as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file("%s\\screenshots\\%s__%s.png" % (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(expr)
Example #20
0
    def test_case_login_001(self):
        '''Login page, write username and password'''
        Conf.CASE_NAME = "test_case_login_001"

        Log.start_test(Conf.CASE_NAME)

        CommonMethod.test_pofs_login_common("EDPRBI", "test")

        Browser.navigate_to(Conf.URL)
        Log.stop_test()
Example #21
0
 def assert_not_equal(self, first, second, msg = None):
     try:
         self.assertNotEqual(first, second)
     except AssertionError as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             ## Screenshot function causes HtmlUnit execution error, let it go...
             Conf.DRIVER.get_screenshot_as_file("%s\\screenshots\\%s__%s.png" % (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(first)
Example #22
0
 def test_case_login_001(self):
     '''Login page, write username and password'''
     Conf.CASE_NAME = "test_case_login_001"
      
     Log.start_test(Conf.CASE_NAME)
     
     CommonMethod.test_pofs_login_common("EDPRBI", "test")
     
     Browser.navigate_to(Conf.URL)
     Log.stop_test()
Example #23
0
 def assert_multi_line_equal(self, first, second, msg=None):
     try:
         self.assertMultiLineEqual(first, second, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file(
                 "%s\\screenshots\\%s__%s.png" %
                 (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(second)
Example #24
0
 def assert_dict_equal(self, d1, d2, msg=None):
     try:
         self.assertDictEqual(d1, d2, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file(
                 "%s\\screenshots\\%s__%s.png" %
                 (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(d2)
Example #25
0
 def assert_not_in(self, member, container, msg=None):
     try:
         self.assertNotIn(member, container, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file(
                 "%s\\screenshots\\%s__%s.png" %
                 (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(member)
Example #26
0
 def assert_list_equal(self, list1, expr, msg=None):
     try:
         self.assertListEqual(list1, expr, msg)
     except AssertionError as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file(
                 "%s\\screenshots\\%s__%s.png" %
                 (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(expr)
Example #27
0
    def test_case_login_001(self):
        Conf.CASE_NAME = "testCase001_Login"

        # Start to execute case and record the starting time
        Log.start_test(Conf.CASE_NAME)

        Csdn = import_module_dynamic("Csdn")
        Csdn.Profile.CSDN_USERNAME.send_keys("jiefenggao")
        Csdn.Profile.CSDN_PASSWORD.send_keys("gaojiefeng")
        Csdn.Profile.CSDN_SUBMIT.click()

        Log.stop_test()
Example #28
0
 def test_case_login_001(self):
     Conf.CASE_NAME = "testCase001_Login"
     
     # Start to execute case and record the starting time
     Log.start_test(Conf.CASE_NAME)
     
     Csdn = import_module_dynamic("Csdn")
     Csdn.Profile.CSDN_USERNAME.send_keys("jiefenggao")
     Csdn.Profile.CSDN_PASSWORD.send_keys("gaojiefeng")
     Csdn.Profile.CSDN_SUBMIT.click()
     
     Log.stop_test()
Example #29
0
 def assert_not_is_instance(self, obj, cls, msg=None):
     try:
         self.assertNotIsInstance(obj, cls, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file(
                 "%s\\screenshots\\%s__%s.png" %
                 (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(
             "Please change this successful message")
Example #30
0
 def assert_not_equal(self, first, second, msg=None):
     try:
         self.assertNotEqual(first, second)
     except AssertionError as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             ## Screenshot function causes HtmlUnit execution error, let it go...
             Conf.DRIVER.get_screenshot_as_file(
                 "%s\\screenshots\\%s__%s.png" %
                 (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(first)
Example #31
0
 def test_tour_login_001(self):
     u"""This is comment of test_case_login_001 shown in report"""
     Conf.CASE_NAME = "test_tour_login_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()
     
     Browser.navigate_to(Conf.URL)
     Log.stop_test()
Example #32
0
 def test_case_login_002(self):
     u"""This is comment of test_case_login_002 shown in report"""
     Conf.CASE_NAME = "test_case_login_002"
     
     Log.start_test(Conf.CASE_NAME)
     
     Element.find_element(self.driver, By.ID, u'TANGRAM__PSP_4__userName').send_keys("jiefenggaoa")
     Element.find_element(self.driver, By.ID, u'TANGRAM__PSP_4__password').send_keys("P@ssw0rd")
     Element.find_element(self.driver, By.ID, u'TANGRAM__PSP_4__submit').click()
     
     Browser.navigate_to(self.driver, Conf.URL)
     Log.stop_test()
Example #33
0
    def testCase001_Login(self):
        '''This always is the 1st case for automation'''
        Conf.CASE_NAME = "testCase001_Login"

        #Start to execute case and record the starting time
        Log.start_test(Conf.CASE_NAME)

        #Which page you want to import, use name of this page as a parameter.
        Login = import_module_dynamic("Login")
        Login.Profile.POFS_USERNAME.send_keys(Conf.USERNAME)
        Login.Profile.POFS_PASSWORD.send_keys(Conf.PASSWORD)
        Login.Profile.POFS_SUBMIT.click()
        time.sleep(1)
Example #34
0
    def test_case_login_003(self):
        u"""This is comment of test_case_login_003 shown in report"""

        Conf.CASE_NAME = "test_case_login_003"

        Log.start_test(Conf.CASE_NAME)

        excel = Datadriver.ExcelSheet(r"Employee.xlsx", "Sheet1")

        for i in range(1, excel.nrows()):
            employeeID = excel.cell(i, "Empoyee_ID")
            password = excel.cell(i, "Password")
            expect = excel.cell(i, "Expect")

            if employeeID != "":
                Element.find_element(
                    self.driver, By.ID,
                    u'TANGRAM__PSP_4__userName').send_keys(employeeID)
            if password != "":
                Element.find_element(
                    self.driver, By.ID,
                    u'TANGRAM__PSP_4__password').send_keys(password)
            Element.find_element(self.driver, By.ID,
                                 u'TANGRAM__PSP_4__submit').click()
            print Element.find_element(self.driver, By.ID,
                                       u'TANGRAM__PSP_4__error').text
            if expect == "expect_result_1":
                # Maybe the element should be asserted is the same one.
                # Change it in every iteration.
                Assert().assert_equal(
                    Element.find_element(self.driver, By.ID,
                                         u'TANGRAM__PSP_4__error').text,
                    expect)
            elif expect == "expect_result_2":
                Assert().assert_equal(
                    Element.find_element(self.driver, By.ID,
                                         u'TANGRAM__PSP_4__error').text,
                    expect)
            elif expect == "expect_result_3":
                Assert().assert_equal(
                    Element.find_element(self.driver, By.ID,
                                         u'TANGRAM__PSP_4__error').text,
                    expect)
            else:
                return None


#             self.driver.get(Conf.URL)
            Browser.navigate_to(self.driver, Conf.URL)

        Log.stop_test()
Example #35
0
 def assert_set_equal(self, set1, expr, msg=None):
     '''
     s1 = set([1,2,3,4])
     s2 = set([1,2,3,4,5])
     Assert().assert_set_equal(s1, s2)
     '''
     try:
         self.assertSetEqual(set1, expr, msg)
     except AssertionError as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file("%s\\screenshots\\%s__%s.png" % (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(expr)
Example #36
0
    def test_case_login_003(self):
        '''Login page, wrong username and correct password'''
        
        Conf.CASE_NAME = "test_case_login_003"
        Log.start_test(Conf.CASE_NAME)
        
        CommonMethod.test_pofs_login_common("EDPRBIa", "test")
        error_message = Element.find_element(By.XPATH, u'//td[@class="subhead"][@align="center"]').text
        Assert().assert_equal(error_message, "Invalid UserID or Password. Attempt 1 of 6.")
        
#         self.driver.get(Conf.URL)
        Browser.navigate_to(Conf.URL)
        
        Log.stop_test()
Example #37
0
 def assert_dict_contains_subset(self, expected, actual, msg=None):
     '''
     d1 = {'b': 1, 'e': 2, 'f': 3}
     d2 = {'b': 1, 'e': 2, 'f': 3, 't':4}
     Assert().assert_dict_contains_subset(d2, d1)
     '''
     try:
         self.assertDictContainsSubset(expected, actual, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file("%s\\screenshots\\%s__%s.png" % (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(expected)
Example #38
0
 def assert_items_equal(self, expected_seq, actual_seq, msg=None):
     '''
     Asserts that each element has the same count in both sequences.
     Example:
         - [0, 1, 1] and [1, 0, 1] compare equal.
         - [0, 0, 1] and [0, 1] compare unequal.
     '''
     try:
         self.assertItemsEqual(expected_seq, actual_seq, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file("%s\\screenshots\\%s__%s.png" % (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(expected_seq)
Example #39
0
 def testCase001_Login(self):
     '''This always is the 1st case for automation'''
     Conf.CASE_NAME = "testCase001_Login"
     
     # Start to execute case and record the starting time
     Log.start_test(Conf.CASE_NAME)
     
     # Which page you want to import, use name of this page as a parameter.
     Login = import_module_dynamic("Login")
     Login.Profile.POFS_USERNAME.send_keys(Conf.USERNAME)
     Login.Profile.POFS_PASSWORD.send_keys(Conf.PASSWORD)
     Login.Profile.POFS_SUBMIT.click()
     time.sleep(1)
     
     Log.stop_test()
Example #40
0
 def assert_set_equal(self, set1, expr, msg=None):
     '''
     s1 = set([1,2,3,4])
     s2 = set([1,2,3,4,5])
     Assert().assert_set_equal(s1, s2)
     '''
     try:
         self.assertSetEqual(set1, expr, msg)
     except AssertionError as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file(
                 "%s\\screenshots\\%s__%s.png" %
                 (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(expr)
Example #41
0
    def test_case_login_002(self):
        u"""This is comment of test_case_login_002 shown in report"""
        Conf.CASE_NAME = "test_case_login_002"

        Log.start_test(Conf.CASE_NAME)

        Element.find_element(
            self.driver, By.ID,
            u'TANGRAM__PSP_4__userName').send_keys("jiefenggaoa")
        Element.find_element(self.driver, By.ID,
                             u'TANGRAM__PSP_4__password').send_keys("P@ssw0rd")
        Element.find_element(self.driver, By.ID,
                             u'TANGRAM__PSP_4__submit').click()

        Browser.navigate_to(self.driver, Conf.URL)
        Log.stop_test()
Example #42
0
 def assert_dict_contains_subset(self, expected, actual, msg=None):
     '''
     d1 = {'b': 1, 'e': 2, 'f': 3}
     d2 = {'b': 1, 'e': 2, 'f': 3, 't':4}
     Assert().assert_dict_contains_subset(d2, d1)
     '''
     try:
         self.assertDictContainsSubset(expected, actual, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file(
                 "%s\\screenshots\\%s__%s.png" %
                 (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(expected)
Example #43
0
    def test_case_login_003(self):
        '''Login page, wrong username and correct password'''

        Conf.CASE_NAME = "test_case_login_003"
        Log.start_test(Conf.CASE_NAME)

        CommonMethod.test_pofs_login_common("EDPRBIa", "test")
        error_message = Element.find_element(
            By.XPATH, u'//td[@class="subhead"][@align="center"]').text
        Assert().assert_equal(error_message,
                              "Invalid UserID or Password. Attempt 1 of 6.")

        #         self.driver.get(Conf.URL)
        Browser.navigate_to(Conf.URL)

        Log.stop_test()
Example #44
0
 def assert_items_equal(self, expected_seq, actual_seq, msg=None):
     '''
     Asserts that each element has the same count in both sequences.
     Example:
         - [0, 1, 1] and [1, 0, 1] compare equal.
         - [0, 0, 1] and [0, 1] compare unequal.
     '''
     try:
         self.assertItemsEqual(expected_seq, actual_seq, msg)
     except Exception as e:
         if Conf.BROWSER.upper() != "HTMLUNIT":
             Conf.DRIVER.get_screenshot_as_file(
                 "%s\\screenshots\\%s__%s.png" %
                 (Conf.RESULT_PATH, Conf.CASE_NAME, stamp_datetime_co()))
         Log.write_assert_fail_log(str(e))
     else:
         Log.write_assert_success_log(expected_seq)
Example #45
0
    def testCase002_Search(self):
        '''testCase002_Search is dependent on testCase001_Login'''
        Conf.CASE_NAME = "testCase002_Search"

        Home = import_module_dynamic("Home")
        Assert().assert_equal(Home.Profile.POFS_TITLE.text,
                              "P.O. Tracking Application0")
        Assert().assert_equal(Home.Profile.POFS_HEADER.text,
                              "Application Main Menu")
        Assert().assert_equal(Home.Profile.POFS_LOGOUT.text, "Log Out")
        Home.Profile.POFS_OVERVIEW_SEARCH.click()

        OverviewSearch = import_module_dynamic("OverviewSearch")
        #         OverviewSearch.Profile.POFS_PONO.send_keys("0000434")
        #         OverviewSearch.Profile.POFS_EXPTYPE[1].click()

        Assert().assert_equal_spinder(
            OverviewSearch.Profile.POFS_EXPTYPE_CONTENT,
            ["LCLa", "FCL", "Select", "AIR", "TRUCK"])
        choose_spinner_value(OverviewSearch.Profile.POFS_EXPTYPE,
                             OverviewSearch.Profile.POFS_EXPTYPE_CONTENT,
                             "LCL")

        OverviewSearch.Profile.POFS_PO_ISSUE_DATE.click()

        switch_to_new_window()
        import_module_dynamic("OverviewSearchDatePicker")
        switch_to_default_window()

        OverviewSearch.Profile.POFS_SEARCH.click()

        OverviewSearchResult = import_module_dynamic("OverviewSearchResult")
        OverviewSearchResult.Profile.POFS_DETAIL.click()
        time.sleep(2)
        switch_to_new_window()
        OverviewSearchResultDetail = import_module_dynamic(
            "OverviewSearchResultDetail")
        Assert().assert_equal(
            OverviewSearchResultDetail.Profile.POFS_PONUMBER.text, "0000434")
        close_window()
        switch_to_default_window()

        time.sleep(2)

        #Stop and  case and record the starting time
        Log.stop_test()
Example #46
0
 def test_case_logout_001(self):
     '''Login page, write username and password'''
     Conf.CASE_NAME = "test_case_logout_001"
      
     Log.start_test(Conf.CASE_NAME)
     
     #Login
     CommonMethod.test_pofs_login_common()
     
     #Logout
     self.POFS_LOGOUT = Element.find_element(By.XPATH, u'//a[@href="login/logout.jsp"]')
     Assert().assert_equal(self.POFS_LOGOUT.text, "Log Out")
     self.POFS_LOGOUT.click()
     
     self.POFS_LOGOUT_MESSAGE = Element.find_element(By.XPATH, u'//td[@align="right"][@style=" color: red;"]').text
     print self.POFS_LOGOUT_MESSAGE
     Assert().assert_equal(self.POFS_LOGOUT_MESSAGE, "You are successfully logged out")
     
     Log.stop_test()
Example #47
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))
Example #48
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))    
Example #49
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))
Example #50
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))
Example #51
0
    def test_case_search_002(self):
        Conf.CASE_NAME = "test_case_search_002"
        Log.start_test(Conf.CASE_NAME)

        POFS_OVERVIEW_SEARCH = Element.find_element(
            By.XPATH, u'//a[@id="b"][@href="overview/overview.jsp"]')
        POFS_OVERVIEW_SEARCH.click()

        POFS_EXPTYPE = Element.find_elements(
            By.XPATH, u'//select[@name="exportType"]/option')
        POFS_EXPTYPE_CONTENT = Element.get_spinner_values(
            By.XPATH, u'//select[@name="exportType"]/option')
        Element.choose_spinner_value(POFS_EXPTYPE, POFS_EXPTYPE_CONTENT, "LCL")

        POFS_PO_ISSUE_DATE = Element.find_element(
            By.XPATH, u'//img[@src="../images/cal.gif"]')
        POFS_PO_ISSUE_DATE.click()

        Browser.switch_to_new_window()
        Element.date_picker(31, 1, 2008)
        Browser.switch_to_default_window()

        POFS_SEARCH = Element.find_element(By.NAME, u'submit')
        POFS_SEARCH.click()

        POFS_DETAIL = Element.find_element(
            By.XPATH, u'//img[@src="../images/detail.gif"]')
        POFS_DETAIL.click()
        Browser.switch_to_new_window()
        POFS_PONUMBER = Element.find_element(
            By.XPATH,
            u'//*[@id="printable"]/table/tbody/tr[1]/td/table/tbody/tr[2]/td[2]'
        )
        Assert().assert_equal(POFS_PONUMBER.text, "0000434")
        Browser.close_window()
        Browser.switch_to_default_window()

        Log.stop_test()
Example #52
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))
Example #53
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
Example #54
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()
    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()
Example #56
0
 def find_element(cls, by, value=None):
     try:
         elename_name = Conf.DRIVER.find_element(by, value)
     except NoSuchElementException:
         print Log.handle_error(Conf.DRIVER)
     return elename_name
Example #57
0
 def find_element(cls, by, value=None):
     try:
         elename_name = Conf.DRIVER.find_element(by, value)
     except NoSuchElementException:
         print Log.handle_error(Conf.DRIVER)
     return elename_name