selenium项目实战--126邮箱的登录和发送邮件

import unittest
from selenium import webdriver
import time
from ddt import ddt, data, unpack


@ddt
class EmailTest(unittest.TestCase):
    @classmethod
    def setUpClass(self) -> None:
        self.driver = webdriver.Chrome()
        self.driver.get('https://mail.126.com/')
        self.driver.implicitly_wait(10)

    @classmethod
    def tearDownClass(self) -> None:
        self.driver.quit()

    @data(('126账号', '126密码'))
    @unpack
    def test_1_login_email(self, user, pwd):
        iframe = self.driver.find_element_by_xpath('//iframe[starts-with(@id,"x-URS-iframe")]')
        self.driver.switch_to.frame(iframe)
        self.driver.find_elements_by_xpath('//input[starts-with(@id, "auto-id-")]')[0].send_keys(user)
        self.driver.find_elements_by_xpath('//input[starts-with(@id, "auto-id-")]')[1].send_keys(pwd)
        self.driver.find_element_by_css_selector('#un-login').click()
        time.sleep(2)
        self.driver.find_element_by_css_selector('#dologin').click()
        time.sleep(2)

    @data(('目标邮箱', 'python测试用例', '这是一条测试用例'))
    @unpack
    def test_2_write_letter(self, receiver, title, content):
        self.driver.find_element_by_xpath('//*[@id="_mail_component_132_132"]').click()
        time.sleep(2)
        self.driver.find_element_by_xpath('//*[starts-with(@id, "_mail_emailtips_")]').click()
        time.sleep(1)
        self.driver.find_element_by_xpath('//input[@class="nui-editableAddr-ipt"]').send_keys(receiver)
        self.driver.find_element_by_xpath('//*[contains(@id, "_subjectInput")]').send_keys(title)
        iframe = self.driver.find_element_by_xpath('//*[starts-with(@id, "_mail_editor")]/div[1]/div[2]/iframe')
        self.driver.switch_to.frame(iframe)
        self.driver.find_element_by_css_selector('body').send_keys(content)
        time.sleep(2)
        self.driver.switch_to.default_content()
        self.driver.find_element_by_xpath('//footer/div[1]/span[2]').click()
        time.sleep(2)


if __name__ == '__main__':
    unittest.main()

猜你喜欢

转载自blog.csdn.net/hide_in_darkness/article/details/108414638