-1
username = "[email protected]"
password = ""
tomailid = "[email protected]"
emailsubject = "[email protected]"
mailbody = "Great! you sent email:-)" + "\n" + "Regards," + "\n" + "Robert"
class send_email(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.baseUrl = "http://mail.google.com/intl/en/mail/help/about.html"
def tearDown(self):
self.driver.close();
def testLoginEmail(self):
self.driver.get(self.baseUrl)
self.driver.maximize_window()
self.driver.find_element_by_id("gmail-sign-in").click()
self.driver.find_element_by_id("Email").clear()
self.driver.find_element_by_id("Email").send_keys(username)
self.driver.find_element_by_id("next").click()
time.sleep(5)
self.driver.find_element_by_id("Passwd").clear()
self.driver.find_element_by_id("Passwd").send_keys(password)
self.driver.find_element_by_id("signIn").click()
#Verify login
if "Gmail" in self.driver.title:
print("Logged in sucessfully !!!" + self.driver.title)
else:
print("Unable to loggin :-(" + self.driver.title)
time.sleep(5)
def testComposeEmail(self):
self.driver.find_element_by_xpath("//div[text()='COMPOSE']").click()
time.sleep(5)
self.driver.find_element_by_class_name("vO").send_keys(tomailid)
self.driver.find_element_by_class_name("aoT").send_keys(emailsubject)
self.driver.find_element_by_class_name("Am").clear()
self.driver.find_element_by_class_name("Am").send_keys(mailbody)
self.driver.find_element_by_xpath("//div[text()='Send']").click()
if __name__ == '__main__':
unittest.main()
我正在使用Selenium运行此Python发送gmail测试。该过程在SetUp上运行后,运行第一个函数testLoginEmail,它可以成功登录到我的Gmail帐户。然后我想继续运行第二个函数testComposeEmail,它应该在第一个函数之后运行,因为它需要点击“Compose”按钮。但它不能运行。如何使用Unittest中的第一个函数运行第二个函数Python
有人可以帮助修改如何运行第二功能的代码?非常感谢!
你有什么错误? – tinySandy
通常订购测试的需求尖叫不好的测试设计,但是如果您知道自己在做什么,可以按字母顺序对其进行命名,或者使用与[在此答案中所述]相同的功能(http://stackoverflow.com /问题/ 4005695 /改变阶的单元的测试功能于蟒) –