username = "robertredrain@gmail.com"
password = ""
tomailid = "robertredrain@yahoo.com"
emailsubject = "robertredrain@yahoo.com"
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()
I am running this send gmail test by Python Unittest with Selenium. The process is after running on SetUp, it runs the 1st function testLoginEmail, which can successfully log in to my gmail account. Then I want to continue to run the 2nd function testComposeEmail, which should be run after the 1st function, because it needs to click the “Compose” button. But it cannot be run.
Could someone help revise the codes that how to run the 2nd function? Thanks a lot!