首页 > 其他分享 >网易126邮箱自动化测试

网易126邮箱自动化测试

时间:2024-09-23 17:22:08浏览次数:8  
标签:网易 self driver element sleep 126 邮箱 div find

网易126邮箱自动化测试

项目介绍

项目简介

学习了关于自动化测试后,测试网易126邮箱的主要功能。目的是为了对网易126邮箱的主要功能:登录、退出登录、添加联系人、删除联系人、管理分组、添加星标联系人、取消星标联系人、发送邮件、接收邮件、查看邮件、草稿箱相关功能进行自动化测试。旨在提高测试效率与质量。

测试地址

https://mail.126.com/

项目设计

1.python编程语言设计测试脚本
2.webdriver驱动浏览器并操作页面元素
3.二次封装webdriver 操作方法
4.通过第三方插件pytest-html生成测试报告

设计测试用例

在这里插入图片描述

环境准备与使用工具

工具:

1、windows系统
2、Chrome浏览器(版本:128.0.6613.138)
3、PyCharm

环境:

1、Python 3.11
2、配置安装:Selenium 4.24.0 (pip install selenium)
3、配置安装:Pytest 8.3.3 (pip install pytest)
4、配置安装:Pytest-html 4.1.1 (pip install pytest-html)
5、配置安装:webdriver-manager (pip install webdriver-manager)

目录结构

NewwangyiemailTest
-common
--_init_.py
--head.py
-tests
--_init_.py
--test_01_Login.py
--test_02_Content.py
--test_03_MainPage.py
--test_04_Edit.py

代码实现

common包下的创建Chrome浏览器web驱动对象并进行封装

from selenium import webdriver
from selenium.webdriver.ie.service import Service
from webdriver_manager.chrome import ChromeDriverManager


class WebDriver:
    driver=""
    def __init__(self):
        self.driver=webdriver.Chrome(service=Service(ChromeDriverManager().install()))


wwebdriver=WebDriver()

tests包下的页面功能测试

注册功能手动测试

登录功能

账号正确,密码正确
from enum import auto
from time import sleep

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.expected_conditions import alert_is_present
from selenium.webdriver.support.wait import WebDriverWait

from common.head import wwebdriver

class TestLogin:
    url=""
    driver=""

    @classmethod
    def setup_class(cls):
        cls.driver=wwebdriver.driver
        cls.url="https://mail.126.com/"
        cls.driver.get(cls.url)
    def test_ZhuCeTest03(self):
        self.driver.find_element(By.NAME,"email").clear()
        self.driver.find_element(By.NAME,"password").clear()

        self.driver.find_element(By.NAME,"email").send_keys("gaoyuqi2002")
        self.driver.find_element(By.NAME,"password").send_keys("GYQ20021013gz")
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#dologin").click()
        sleep(2)
可以正常退出登录
    def test_ZhuCeTest08(self):
         self.driver.switch_to.default_content()
         sleep(2)
         hover = self.driver.find_element(By.CSS_SELECTOR, "#_mail_icon_0_0")
         hover.click()
         # 悬停页面ActionChains
         ActionChains(self.driver).move_to_element(hover).perform()
         sleep(3)
         self.driver.find_element(By.XPATH, "//div[starts-with(@id,'_mail_') and text()='退出登录']").click()

         sleep(3)
         txt = self.driver.find_element(By.XPATH, "//*[@id='info']/h1").text
         print(txt)

未注册直接登录
 def test_ZhuCeTest01(self):
        self.driver.maximize_window()
        self.driver.implicitly_wait(3)
        # 定位到框架
        # self.driver.switch_to.frame(self.driver.find_element(By.XPATH,"//iframe[starts-with(@id,'x-URS-iframe')]"))
        self.driver.switch_to.frame(self.driver.find_element(By.CSS_SELECTOR,"iframe"))
        self.driver.find_element(By.NAME,"email").clear()
        self.driver.find_element(By.NAME,"password").clear()
        # 输入账号密码
        self.driver.find_element(By.NAME,"email").send_keys("wangwu2024")
        self.driver.find_element(By.NAME,"password").send_keys(" GYQ20021013gz")
        sleep(1)
        # 找到登录直接点击
        self.driver.find_element(By.CSS_SELECTOR,"#dologin").click()
        print("登录失败")
        sleep(3)
账号密码都不正确
    def test_ZhuCeTest04(self):
        self.driver.maximize_window()
        self.driver.get("https://mail.126.com/")
        self.driver.switch_to.frame(self.driver.find_element(By.XPATH,"//iframe[starts-with(@id,x-URS-iframe)]"))
        self.driver.find_element(By.NAME,"email").clear()
        self.driver.find_element(By.NAME,"password").clear()
        self.driver.find_element(By.NAME, "email").send_keys("gaoyuqi200")
        self.driver.find_element(By.NAME, "password").send_keys("GYQ20021013g")
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#dologin").click()
        sleep(3)
        print(self.driver.find_element(By.CLASS_NAME,"ferrorhead").text)
账号密码都为空
    def test_ZhuCeTest05(self):
        self.driver.find_element(By.NAME,"email").clear()
        self.driver.find_element(By.NAME,"password").clear()
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#dologin").click()
        sleep(3)
        print(self.driver.find_element(By.CLASS_NAME,"ferrorhead").text)
账号错误,密码正确
    def test_ZhuCeTest06(self):
        self.driver.find_element(By.NAME,"email").clear()
        self.driver.find_element(By.NAME,"password").clear()
        self.driver.find_element(By.NAME, "email").send_keys("gaoyuqi200")
        self.driver.find_element(By.NAME, "password").send_keys("GYQ20021013gz")
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#dologin").click()
        sleep(3)
        print(self.driver.find_element(By.CLASS_NAME,"ferrorhead").text)
账号正确密码错误
 def test_ZhuCeTest07(self):
        self.driver.find_element(By.NAME, "email").clear()
        self.driver.find_element(By.NAME, "password").clear()
        self.driver.find_element(By.NAME, "email").send_keys("gaoyuqi2002")
        self.driver.find_element(By.NAME, "password").send_keys("GYQ20021013")
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#dologin").click()
        sleep(3)
        print(self.driver.find_element(By.CLASS_NAME, "ferrorhead").text)

通讯录功能

增加好友功能
from time import sleep

from selenium.common import NoSuchElementException
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from common.head import wwebdriver

class TestContent:
    driver=""
    url=""
    @classmethod
    def setup_class(cls):
        cls.driver=wwebdriver.driver
        cls.url="https://mail.126.com/"
        cls.driver.get(cls.url)
        
    def test_AddContentTest01(self):
        # 登录
        self.driver.maximize_window()
        self.driver.switch_to.frame(self.driver.find_element(By.CSS_SELECTOR,"iframe"))
        self.driver.find_element(By.NAME, "email").clear()
        self.driver.find_element(By.NAME, "password").clear()

        self.driver.find_element(By.NAME, "email").send_keys("gaoyuqi2002")
        self.driver.find_element(By.NAME, "password").send_keys("GYQ20021013gz")
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#dologin").click()
        # 回到当前页面
        self.driver.switch_to.default_content()
        sleep(3)
        self.driver.find_element(By.XPATH,"//div[starts-with(@id,'_mail_tabitem') and text()='通讯录']").click()
        sleep(3)
        # 点击新建联系人
        self.driver.find_element(By.XPATH,"//span[starts-with(@class,'nui-btn-text') and text()='新建联系人']").click()
        sleep(3)
        # 输入联系人姓名
        name_wait=WebDriverWait(self.driver,3).until(EC.visibility_of_element_located((By.XPATH,"//input[starts-with(@id,'input_N') and @class='nui-ipt-input']")))
        name_wait.send_keys("111")
        sleep(20)
        self.driver.find_element(By.XPATH,"//span[starts-with(@class, 'nui-btn-text') and text()='确 定']").click()
        sleep(5)
        try:
            self.driver.find_element(By.XPATH,"//span[starts-with(@class,'nui-txt nui-txt-normal') and text()='111']")
            print("添加成功")
        except NoSuchElementException as e:
            print(f"没有找到元素:{e}")
        # 回退到首页
        self.driver.back()
        # 刷新页面
        self.driver.refresh()
删除通讯录好友
    def test_AddContentTest02(self):
        # self.driver.maximize_window()
        self.driver.find_element(By.XPATH,"//div[starts-with(@id,'_mail_tabitem') and text()='通讯录']").click()
        sleep(1)
        # # 需要删除的联系人---
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/div/div/div/section[1]/div/table/tbody/tr[3]/td[2]/span/span/b").click()
        sleep(1)
        # 点击删除
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/div/header/div/div[2]/div[3]/span").click()
        sleep(1)
        # 点击确定
        self.driver.find_element(By.XPATH,"//span[text()='确 定']").click()
        sleep(3)
        print("删除成功")
        # 回退到首页
        self.driver.back()
        # 刷新页面
        self.driver.refresh()
管理分组–通过复制到组新建分组并移入联系人
    def test_AddContentTest03(self):
        self.driver.find_element(By.XPATH, "//div[starts-with(@id,'_mail_tabitem') and text()='通讯录']").click()
        sleep(3)
        # 选择一个联系人---222
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/div/div/div/section[1]/div/table/tbody/tr[2]/td[2]/span/span/b").click()
        # 点击复制到组
        self.driver.find_element(By.XPATH, "//span[text()='复制到组']").click()
        sleep(3)
        # 点击新建分组并复制
        self.driver.find_element(By.XPATH, "//span[text()='新建分组并复制']").click()
        sleep(10)

        # 手动测试
        # # 输入新建组的名字
        # 回退到首页
        self.driver.back()
        # 刷新页面
        self.driver.refresh()

首页功能

添加星标联系人
from time import sleep

from selenium.webdriver.common.by import By

from common.head import wwebdriver

class TestMainPage:
    driver=""
    url=""

    @classmethod
    def setup_class(cls):
        cls.driver = wwebdriver.driver
        cls.url = "https://mail.126.com/"
        cls.driver.get(cls.url)

    #添加星标联系人
    def test_AddStartContent(self):
        sleep(2)
        # 点击进入通讯录
        self.driver.find_element(By.XPATH, "//div[starts-with(@id,'_mail_tabitem') and text()='通讯录']").click()
        sleep(2)
        # 点击222联系人的星星图标
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/div/div/div/section[1]/div/table/tbody/tr[2]/td[3]/div[1]/b").click()
        sleep(2)
        # 点击111联系人的星星图标
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/div/div/div/section[1]/div/table/tbody/tr[1]/td[3]/div[1]/b").click()
        #您已成功编辑联系人
        print(self.driver.find_element(By.XPATH,"//span[text()='您已成功编辑联系人']").text)
        # 回退到首页
        self.driver.back()
        # 刷新页面
        self.driver.refresh()

取消星标联系人

    def test_DelStartContent(self):
        sleep(1)
        # 点击进入通讯录
        self.driver.find_element(By.XPATH, "//div[starts-with(@id,'_mail_tabitem') and text()='通讯录']").click()
        sleep(2)
        # 点击222联系人的星星图标
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/div/div/div/section[1]/div/table/tbody/tr[2]/td[3]/div[1]/b").click()
        sleep(2)
        self.driver.find_element(By.XPATH,"//span[text()='确 定']").click()
        # 您已成功编辑联系人
        self.driver.refresh()
        print("取消成功")
        # 回退到首页
        self.driver.back()
        # 刷新页面
        self.driver.refresh()
发邮件–收件人为空
    def test_SendEmail01(self):
        self.driver.implicitly_wait(10)
        # 点击写信
        self.driver.find_element(By.XPATH,"/html/body/div[1]/nav/div[1]/ul/li[2]").click()
        # # 输入主题----手动输入
        sleep(10)
        # 输入内容
        sleep(2)
        # 查找输入框
        self.driver.find_element(By.XPATH,"/html/body")
        # 定位到框架
        self.driver.switch_to.frame(self.driver.find_element(By.XPATH,"//iframe[starts-with(@class,'APP-editor-iframe')]"))
        self.driver.find_element(By.CLASS_NAME,"nui-scroll").send_keys("自动化测试")
        # 回到当前页面
        self.driver.switch_to.default_content()
        sleep(3)
        self.driver.find_element(By.XPATH,"//span[text()='发送']").click()
        sleep(3)
        print(self.driver.find_element(By.XPATH,"//span[text()='请填写收件人地址后再发送']").text)
        # 回退到首页
        self.driver.back()
        # 刷新页面
        self.driver.refresh()
发邮件–内容为空
    def test_SendEmail02(self):
        self.driver.implicitly_wait(10)
        # 点击写信
        self.driver.find_element(By.XPATH, "/html/body/div[1]/nav/div[1]/ul/li[2]").click()
        sleep(2)

        # # 输入联系人和主题----手动输入
        sleep(20)

        # 输入内容
        # 定位到框架
        self.driver.switch_to.frame(self.driver.find_element(By.XPATH,"//iframe[starts-with(@class,'APP-editor-iframe')]"))
        self.driver.find_element(By.CLASS_NAME,"nui-scroll").send_keys(" ")
        sleep(5)
        # 回到当前页面
        self.driver.switch_to.default_content()
        #点击发送
        self.driver.find_element(By.XPATH,"//span[text()='发送']").click()
        # 回退到首页
        self.driver.back()
        # 刷新页面
        self.driver.refresh()
收信—点击收信查看
 def test_AccpectEmail01(self):
        self.driver.implicitly_wait(10)
        # 点击收 信
        self.driver.find_element(By.XPATH,"//span[text()='收 信']").click()
        sleep(2)
        # 点击需要查看的信件
        self.driver.find_element(By.XPATH,"//span[text()='高泽']").click()
        sleep(10)
        # 回退到主页
        self.driver.back()
        sleep(3)
        self.driver.back()
        # 刷新页面
        self.driver.refresh()

草稿箱编辑功能

写信编辑一半
    def test_HalfEdit01(self):
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.XPATH, "/html/body/div[1]/nav/div[1]/ul/li[2]").click()
        sleep(2)
        #定位到iframe
        self.driver.switch_to.frame(self.driver.find_element(By.XPATH, "//iframe[starts-with(@class,'APP-editor-iframe')]"))
        self.driver.find_element(By.CLASS_NAME, "nui-scroll").send_keys("自动化测试")
        # 回到当前标签
        self.driver.switch_to.default_content()
        # 点击保存草稿
        self.driver.find_element(By.XPATH,"//span[text()='存草稿']").click()
        print("成功保存")
        # 回退到首页
        self.driver.back()
        # 刷新页面
        self.driver.refresh()
写信编辑一半,回到首页
    def test_HalfEdit02(self):
        self.driver.implicitly_wait(10)
        # 点击写信
        self.driver.find_element(By.XPATH, "/html/body/div[1]/nav/div[1]/ul/li[2]").click()
        sleep(2)
        # 定位到iframe
        self.driver.switch_to.frame(self.driver.find_element(By.XPATH, "//iframe[starts-with(@class,'APP-editor-iframe')]"))
        self.driver.find_element(By.CLASS_NAME, "nui-scroll").send_keys("自动化测试")
        # 回到当前标签
        self.driver.switch_to.default_content()
        # 点击首页
        self.driver.find_element(By.XPATH,"/html/body/header/nav/div[1]/ul/li[1]").click()
        sleep(3)
        print("成功保存至邮箱")
        # # 回退到首页
        # self.driver.back()
        # 刷新页面
        self.driver.refresh()
删除草稿箱邮件
    def test_HalfEdit03(self):
        self.driver.implicitly_wait(10)
        #点击草稿箱
        self.driver.find_element(By.XPATH,"//span[text()='草稿箱']").click()
        sleep(2)

        # 选择邮件 ---
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/div/div/div/div/div[4]/div[2]/div/div[1]/label/span/b").click()
        sleep(3)

        # 点击删除草稿
        self.driver.find_element(By.XPATH,"//span[text()='删除草稿']").click()
        sleep(3)
        print("草稿删除成功")
        # 回退到首页
        self.driver.back()
        # 刷新页面
        self.driver.refresh()

测试输出报告

自动生成html格式报告,其中报告里面附带用例执行日志明细
通过pytest --html=report.html自动生成测试报告

标签:网易,self,driver,element,sleep,126,邮箱,div,find
From: https://blog.csdn.net/weixin_72294661/article/details/142445503

相关文章

  • 南沙C++信奥老师解一本通题 1260:【例9.4】拦截导弹(Noip1999)
    ​【题目描述】某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统。但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度。某天,雷达捕捉到敌国的导弹来袭。由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦......
  • Tomcat CVE-2017-12615 靶场攻略
    漏洞描述当Tomcat运⾏在Windows操作系统时,且启⽤了HTTPPUT请求⽅法(例如,将readonly初始化参数由默认值设置为false),攻击者将有可能可通过精⼼构造的攻击请求数据包向服务器上传包含任意代的JSP⽂件,JSP⽂件中的恶意代码将能被服务器执⾏。导致服务器上的数据泄露或获取服务......
  • 网易云JS逆向分析
    网易云JS逆向分析前言本文章中所有内容仅供学习交流,严禁用于商业用途和非法用途,否则由此产生的一切后果均与文章作者无关,若有侵权,请联系我立即删除!阅读本篇文章,需要一定的爬虫基础,和js逆向思维,否则无法继续首先找到一个歌单找到这个api接口api传参为这两个找到启动器......
  • Windows 10 使用SMTP向QQ邮箱发送邮件
    一、QQ邮箱开启SMTP服务登录QQ邮箱网页版:https://mail.qq.com。进入设置:右上角点击“设置”图标(齿轮图标)。在下拉菜单中选择“账户”。开启SMTP服务:在“账户设置”页面下,找到“POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务”。点击“开启”旁边的“POP3/SMTP......
  • 31263 / 32004 Game Development
    31263/32004GameDevelopmentLabWeek6GettingStarted1.Downloadthecorrespondingweek’szipfilefromthisweek’smoduleonCanvas.2.UnziptheprojectfolderandopenitinUnity.Ifthereareanywarningsaboutdifferenceinversions,justconti......
  • springboot二手书交易系统-计算机毕业设计源码81264
    目录1绪论1.1选题背景与意义1.2国内外研究现状1.3论文结构与章节安排2系统分析2.1可行性分析2.2 系统功能分析2.2.1功能性分析2.2.2非功能性分析2.3 系统用例分析2.4 系统流程分析2.4.1 数据流程2.4.2 业务流程2.5本章小结3 系统总体......
  • [语言月赛 202408] 蓝色的网易云
    [语言月赛202408]蓝色的网易云题目背景你也在听吗落单的孩子啊别害怕别害怕黑夜不会太长悬崖上的花让我为你摘下数一瓣落一瓣就少一朵忧伤题目描述风的歌单中共有nn......
  • 【网易低代码】第3课,页面表格删除功能
    你好!这是一个新课程CodeWave网易低代码通过自然语言交互式智能编程,同时利用机器学习,帮助低代码开发者进一步降低使用门槛、提高应用开发效率【网易低代码】第3课,页面表格删除功能1.拖拽组件link链接到表格中,修改文安为删除2.绑定按钮事件3.绑定删除功能下期课程预......
  • 网易低代码大赛开营!欢迎各路开发者们来玩~
     开发者们,2024网易低代码大赛已经正式上线,赛事的第一枪已经打响了!!!——“事”不可挡本届赛事对比前几届,在多个赛道&玩法、激励等上都进行了创新,除了带给大家一定的参赛丰富度,也包含了很多趣味性的体验。——大不一“YOUNG”为了帮助大家更清晰、更全面地掌握赛事重点,做到充分......
  • SpringBoot+Vue3项目邮箱验证码注册详细教程
    引言该篇文章是以SpringBoot+Vue3技术栈搭建的项目的邮箱注册登录流程,注册用户使用邮箱校验,使用qq邮箱发送验证码,并且把验证码存入Redis以备校验使用的详细介绍干货部分1.在SpringBoot项目的application.yaml文件中配置qq邮箱spring:#mail邮箱mail:#SMTP......