def test_save_as_draft(self): """写信存为草稿测试""" # 快捷登录网页 pl = PageLogin(self.driver) pl.quick_login() # 进行email发送操作 pse = PageSendMail(self.driver) # 进入写信页面 pse.goto_letter() # 定位到“草稿箱”,并获取到初始数字;(测试此项前,草稿箱至少要有草稿;此种验证不可靠可以不采用) text_1 = self.driver.find_element_by_id("folder_4").text num_1 = re.search("\d+", text_1).group() # 切换到iframe表单mainFrame self.driver.switch_to.frame("mainFrame") # 点击“存草稿”按钮 pse.type_save_draft() time.sleep(1) # 第一种验证根据页面提示 # self.driver.switch_to.default_content() # now = time.strftime("%H:%M") # assert(pse.get_message_box(1) == now + " 邮件成功保存到草稿箱"), "未保存成功" # 第二种验证根据左侧导航列表“草稿箱”后面的数字做判断,在添加草稿前就要获取一次然后存为操作后再次获取一次,判断是否增加。此种验证可以用到正则表达式去获取数字 # 再次定位“草稿箱”,并获取数字 self.driver.switch_to.default_content() text_2 = self.driver.find_element_by_id("folder_4").text num_2 = re.search("\d+", text_2).group() assert (num_2 > num_1), "未保存成功"
def test2_write_out(self): """添加了邮件主题或正文,关闭写信页面,且不将改动存为草稿""" # 快捷登录网页 pl = PageLogin(self.driver) pl.quick_login() # 进行email发送操作 pse = PageSendMail(self.driver) # 进入写信页面 pse.goto_letter() # 切换到iframe表单mainFrame self.driver.switch_to.frame("mainFrame") # 添加主题 pse.type_subject("python selenium send email test") # 关闭写信 pse.type_exit() time.sleep(2) # 对提示框进行选择:否 self.driver.switch_to.default_content() pse.select_leave_tip(2) time.sleep(1) # 通过页面的title来验证页面是否跳转了 assert (self.driver.title == "QQ邮箱"), "写信未关闭"
def test1_send_no_receiver(self): """未填写收信人直接点击发送(预期:不能发送)""" # 快捷登录网页 pl = PageLogin(self.driver) pl.quick_login() # 进行email发送操作 pse = PageSendMail(self.driver) # 进入写信页面,直接点击发送按钮 pse.goto_letter() self.driver.switch_to.frame("mainFrame") pse.type_send() # 无法发送,检测提示 self.driver.switch_to.default_content() assert(pse.get_message_box(0) == "请填写收件人后再发送"), "没有请填写收件人的提示" # 再检测页面是否发生了跳转 TODO:这个地方写的对不对,有没有必要 try: self.driver.switch_to.frame("mainFrame") pse.send_success_hint() except: pass
def test1_write_out(self): """未添加任何邮件内容,关闭写信页面""" # 快捷登录网页 pl = PageLogin(self.driver) pl.quick_login() # 进行email发送操作 pse = PageSendMail(self.driver) # 进入写信页面 pse.goto_letter() # 点击关闭 self.driver.switch_to.frame("mainFrame") pse.type_exit() time.sleep(1) # 通过页面的title来验证页面是否跳转了 assert (self.driver.title == "QQ邮箱"), "写信未关闭"
def test_send_mail(self): """发送邮件的最基本流程测试""" # 快捷登录网页 pl = PageLogin(self.driver) pl.quick_login() # 进行email发送操作 pse = PageSendMail(self.driver) # 进入写信页面 pse.goto_letter() # 切换到iframe表单mainFrame self.driver.switch_to.frame("mainFrame") # 添加收信人地址,可以添加多个,请按[email protected];的格式添加 pse.type_receiver("[email protected];", "[email protected];") # 添加主题 pse.type_subject("python selenium send email test subject") # 添加正文 body_text = "hello! this is email test!" \ "thanks" pse.type_mail_body(body_text) # 发送邮件 pse.type_send() sleep(3) # 检测邮件发送或是否成功 get_screenshot(self.driver, "./mail_auto_test/report/img/login_ok.jpg") pse.send_success_hint()
def test3_write_out(self): """添加了邮件主题或正文,关闭写信页面,且将改动存为草稿""" # 快捷登录网页 pl = PageLogin(self.driver) pl.quick_login() # 进行email发送操作 pse = PageSendMail(self.driver) # 进入写信页面 pse.goto_letter() # 切换到iframe表单mainFrame self.driver.switch_to.frame("mainFrame") # 添加主题 pse.type_subject("python selenium send email test") # 关闭写信 pse.type_exit() time.sleep(2) # 对提示框进行选择:是 self.driver.switch_to.default_content() pse.select_leave_tip(1) time.sleep(1) # 是否保存为草稿 now = time.strftime("%H:%M") assert (pse.get_message_box(1) == now + " 邮件成功保存到草稿箱"), "未保存成功" time.sleep(1) # 通过页面的title来验证页面是否跳转了 assert (self.driver.title == "QQ邮箱"), "写信未关闭"
def test_giant_attachment(self): """添加超大附件发送邮件流程测试""" # 快捷登录网页 pl = PageLogin(self.driver) pl.quick_login() # 进行email发送操作 pse = PageSendMail(self.driver) # 进入写信页面 pse.goto_letter() # 切换到iframe表单mainFrame self.driver.switch_to.frame("mainFrame") # 添加收信人地址,可以添加多个,请按[email protected];的格式添加 pse.type_receiver("[email protected];", "[email protected];") # 添加主题 pse.type_subject("python selenium send email test") # 添加附件 pse.upload_attachment3( r"F:\Git_lib\python_selenium\QQ_mail_auto_test\package\result.html" ) # 添加正文 body_text = "hello! this is email test!" \ "upload_giant_attachment" pse.type_mail_body(body_text) # 发送邮件 pse.type_send() sleep(3) # 检测邮件发送或是否成功 get_screenshot(self.driver, "./mail_auto_test/report/img/login_ok.jpg") pse.send_success_hint()
def qtest3_send_no_body(self): """未添加主题点击发送(预期:可以发送)""" # 快捷登录网页 pl = PageLogin(self.driver) pl.quick_login() # 进行email发送操作 pse = PageSendMail(self.driver) # 进入写信页面 pse.goto_letter() self.driver.switch_to.frame("mainFrame") # 添加收信人地址,可以添加多个,请按[email protected];的格式添加 pse.type_receiver("[email protected];", "[email protected];") # 添加主题 pse.type_subject("python selenium send email test subject") # 发送邮件 pse.type_send() sleep(3) # 检测邮件发送或是否成功 pse.send_success_hint()
def qtest2_send_no_subject(self): """未添加主题点击发送(预期:会弹出提示框并确认发送)""" # 快捷登录网页 pl = PageLogin(self.driver) pl.quick_login() # 进行email发送操作 pse = PageSendMail(self.driver) # 进入写信页面,并添加收信人地址 pse.goto_letter() self.driver.switch_to.frame("mainFrame") pse.type_receiver("[email protected];") # 然后直接点击发送按钮 pse.type_send() # 对出现的提示框进行确认 self.driver.switch_to.default_content() pse.prompt_confirmation(0) sleep(3) # 检测邮件是否发送成功 self.driver.switch_to.frame("mainFrame") pse.send_success_hint()