def test_activateproduct(self): u'''激活产品(使用不存在的文件名)''' def _action_on_trigger_element(_element): _element.click() logging.info("Test wrong lic file. Expect the the wrong file can be prompted" " proper error with ") driver = self.driver lic_file_path = 'abcdef123456' logging.info("Input the file: " + lic_file_path) select_file_btn_elm = driver.find_element(By.XPATH, '//*[@id="uploadform"]/div/p[3]/input') #select_file_btn_elm.click() th = threading.Thread(target = _action_on_trigger_element, args =[ select_file_btn_elm]) th.start() time.sleep(1) # Call WindowFinder Class upload_file_dialog_title = u"文件上传" enter_str = "{ENTER}" win = WindowFinder() #win.find_window_wildcard(upload_file_dialog_title) win.find_dialog_wildcard(upload_file_dialog_title) win.set_foreground() result_status = True #try: logging.debug("Try to sendkeys") #win.SendMessage(lic_file_path) SendKeys.SendKeys(lic_file_path) time.sleep(2) SendKeys.SendKeys(enter_str) time.sleep(2) assert(not th.isAlive()) #except: # logging.debug("catch in sendkeys exception") # result_status = False # 检查点 # 不存在的文件,会提示“xxxx文件不存在”,使用程序期待这样的弹出窗口 win.expect_the_specific_dialog(win.get_current_dialog()) time.sleep(2) # 有窗口弹出,该“不存在文件名测试”即成功 self.failUnless(win.get_expect_sec_window())
def activate_product_with_licfile(self, reg_type, licfile): ''' Use a lic file to activate the product :licfile: refer to a lic file ''' def _action_on_trigger_element(_element): _element.click() logging.info("Test wrong lic file. Expect the the wrong file can be prompted" " proper error with ") driver = self.driver registerLicUI = RegisterLicUI.RegisterLicUI(driver) lic_file_path = licfile #lic_file_path = 'abcdef123456' logging.info("Input the file: " + lic_file_path) select_file_btn_elm = registerLicUI.get_select_file_btn_elm() select_file_btn_elm.click() th = threading.Thread(target = _action_on_trigger_element, args =[ select_file_btn_elm]) th.start() time.sleep(1) # Call WindowFinder Class upload_file_dialog_title = u"文件上传" enter_str = "{ENTER}" win = WindowFinder() #win.find_window_wildcard(upload_file_dialog_title) win.find_dialog_wildcard(upload_file_dialog_title) win.set_foreground() #try: logging.debug("Try to sendkeys") #win.SendMessage(lic_file_path) time.sleep(1) SendKeys.SendKeys(lic_file_path) time.sleep(2) SendKeys.SendKeys(enter_str) time.sleep(2) assert(not th.isAlive()) #except: # logging.debug("catch in sendkeys exception") # result_status = False # 检查点 if ActivateProduction.LICFILE_NOT_EXISTED_CASE == reg_type: # 不存在的文件,会提示“xxxx文件不存在”,使用程序期待这样的弹出窗口 win.expect_the_specific_dialog(win.get_current_dialog()) time.sleep(2) # 有窗口弹出,该“不存在文件名测试”即成功, # 文件存在则跳过该检查步骤,到下一检查点 self.failUnless(win.get_expect_sec_window()) elif ActivateProduction.LICFILE_NOT_VALID == reg_type: # Licfile文件存在,点击“上传按钮”后, # 有返回消息“上传的License文件无效!”返回 registerLicUI.get_submit_btn().click() time.sleep(2) # 等待时间不能太短 #response_msg_elm = driver.find_element_by_id('msg') #import pdb; pdb.set_trace() expectmsg = u"上传的License文件无效!".strip() respmsg = registerLicUI.get_response_msg_elm() #response_msg_elm.strip() #.encode('utf-8') respmsg = unicode(respmsg.strip()) logging.info("Got the msg is " + respmsg) self.assertEqual(respmsg, expectmsg) elif ActivateProduction.LICFILE_VALID == reg_type: registerLicUI.get_submit_btn().click() time.sleep(3) # 等待时间不能太短 # wait to alert dialog pops up expectmsg = u'License验证成功,转到登录界面!' respmsg = registerLicUI.get_alert_text() respmsg = unicode(respmsg.strip()) logging.info("Step info: " + "Got the response message, " + respmsg ) self.assertEqual(expectmsg, respmsg) #driver.refresh() time.sleep(2)