class WlanConnect(unittest.TestCase): @classmethod def setUpClass(cls): browser = BrowserEngine(cls) cls.driver = browser.open_browser(cls) @classmethod def tearDownClass(cls): cls.driver.close() def test_wlan_login_fail(self): wlan_dict={#"miss_username":['','19911992'], "miss_password":['*****@*****.**',''], "incorrect_username":['weix.b.sun.com','19911992'], "incorrect_password":['*****@*****.**','12345678']} self.initbase = BasePage(self.driver) for key in wlan_dict: self.driver.get('https://gia-captiveportal.intel.com/guest/guest_hello_c.php?mac=84:3a:4b:c8:a8:f0&_browser=1') self.initbase.type('s => input#ID_form80308bd3_weblogin_username',wlan_dict[key][0]) self.initbase.type('s => input#ID_form80308bd3_weblogin_password',wlan_dict[key][1]) js_bottom = "var q=document.documentElement.scrollTop=10000" self.driver.execute_script(js_bottom) time.sleep(1) self.initbase.click('s => input#ID_form80308bd3_weblogin_visitor_accept_terms') self.initbase.click('s => input#ID_form80308bd3_weblogin_submit') self.initbase.get_windows_screen() try: if key.find("username"): self.assertTrue('Invalid username' in self.initbase.find_element("ERROR_form39b008c_weblogin_username").text) else: self.assertTrue('enter a value' in self.initbase.find_element("ERROR_form39b008c_weblogin_password").text) except Exception as e: logger.error("No error message was printed: %s" %e) def test_wlan_login_pass(self): username="******" password="******" self.initbase = BasePage(self.driver) self.driver.get('https://gia-captiveportal.intel.com/guest/guest_hello_c.php?mac=84:3a:4b:c8:a8:f0&_browser=1') self.initbase.type('s => input#ID_form80308bd3_weblogin_username',username) self.initbase.type('s => input#ID_form80308bd3_weblogin_password',password) js_bottom = "var q=document.documentElement.scrollTop=10000" self.driver.execute_script(js_bottom) time.sleep(1) self.initbase.click('s => input#ID_form80308bd3_weblogin_visitor_accept_terms') self.initbase.click('s => input#ID_form80308bd3_weblogin_submit') self.initbase.get_windows_screen() try: self.assertTrue('Logging in' in self.initbase.find_element("s => div#content-marker > p").text) except Exception as e: logger.error("No logging message was printed: %s" %e) self.initbase.get_windows_screen()
def test_case_run(self): basepage = BasePage(self.driver) ts = TestSuites() #excel表内关键字列表 [('type', 'id=>kw', '输入搜索'), (), ()] action_list = KeyCases().key_case_list_all() test_step_dict = TestSteps().do_teststep_id() print action_list for i in range(len(action_list)): if action_list[i][0] == 'type': basepage.type(action_list[i][1], 'selenium') time.sleep(3) print 'selenium %d' %i print action_list[i][2] x = int(ts.get_key(test_step_dict, action_list[i][2])) print 'x:',x rb = open_workbook(r"D:\je_workspace\PythonCase\src\excel\testcase.xls") wb = copy(rb) sheet = wb.get_sheet(3) sheet.write(x+1, 5, 'pass') os.remove(r"D:\je_workspace\PythonCase\src\excel\testcase.xls") wb.save(r"D:\je_workspace\PythonCase\src\excel\testcase.xls") time.sleep(3) elif action_list[i][0] == 'search': basepage.click(action_list[i][1]) time.sleep(3) print 'search' x = int(ts.get_key(test_step_dict, action_list[i][2])) print 'x:',x rb = open_workbook(r"D:\je_workspace\PythonCase\src\excel\testcase.xls") wb = copy(rb) sheet = wb.get_sheet(3) sheet.write(x+1, 5, 'pass') os.remove(r"D:\je_workspace\PythonCase\src\excel\testcase.xls") wb.save(r"D:\je_workspace\PythonCase\src\excel\testcase.xls") time.sleep(3) else: raise NameError ('invalid method')