如何使用python自动从selenium webdriver向收件人发送电子邮件测试报告。我目前正在使用pycharmide来自动化测试用例。 当这个测试用例由我运行时,我想给某人发电子邮件。邮件应该有成功和失败的计数。我试图找到解决办法但是失败了。这个是我的测试用例。请给我答案。在
from selenium import webdriver
from generic_functions.FindElement import HandyWrappers
from generic_functions.takescreenshots import Screenshot
from generic_functions.error_handle import CatchExceptions
import os
import time
import unittest
class TestHome(unittest.TestCase):
driverLocation = "C:\\Users\\Sales\\Desktop\\Automation\\ABCD\\libs\\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = driverLocation
driver = webdriver.Chrome(driverLocation)
driver.maximize_window()
driver.implicitly_wait(10)
def test_home(self):
try:
baseURL = "https://portal.abcd.com"
driver = self.driver
driver.get(baseURL)
hw = HandyWrappers(driver)
# regionLogin
username = hw.getElement(".//form[@id='login-form']/fieldset/section[1]/label[2]/input[@name='email']",
locatorType="xpath")
username.send_keys("abcd@live.com")
time.sleep(2)
password = hw.getElement(".//form[@id='login-form']/fieldset/section[2]/label[2]/input[@name='password']",
locatorType="xpath")
password.send_keys("abcd")
signIn = hw.getElement(".//form[@id='login-form']/footer/button[contains(text(),'Sign in')]",
locatorType="xpath")
signIn.click()
Screenshot.takeScreenshot(driver)
# endregion
time.sleep(2)
driver.execute_script("window.scrollBy(0,300);")
time.sleep(1)
# Switch to Iframe from main page
driver.switch_to.frame("ifrmClaimSummary")
# regionScrolling Right and left
driver.execute_script("window.scrollBy(100,0);")
time.sleep(1)
driver.execute_script("window.scrollBy(100,0);")
time.sleep(1)
driver.execute_script("window.scrollBy(100,0);")
time.sleep(1)
# Scrolling Left
driver.execute_script("window.scrollBy(-100,0);")
time.sleep(1)
driver.execute_script("window.scrollBy(-100,0);")
time.sleep(1)
driver.execute_script("window.scrollBy(-100,0);")
time.sleep(1)
# endregion
driver.switch_to.default_content()
driver.execute_script("window.scrollBy(0,-300);")
time.sleep(2)
driver.quit()
except Exception:
CatchExceptions.PrintException()
Screenshot.takeScreenshot(driver)
if __name__ == '__main__':
unittest.main()
根据您的意见,您可以遵循以下方法来完成测试报告和电子邮件结果:
考虑利用
unittest
进行测试报告—Selenium的文档中有an example of this。在然后,您可以使用} with Gmail 。在
smtplib
发送电子邮件。这方面有很多资源;这里是one tutorial on ^{简而言之:
unittest
设置测试套件unittest
的API访问测试结果smtplib
发送它相关问题 更多 >
编程相关推荐