def logOut(self): logInfo("Gmail_Compose : logOut()") self.profilePic.click() time.sleep(3) # visible only after click() self.driver.find_element_by_link_text("Sign out").click()
def composeGmail(driver, mailto, subject, content): c = Gmail_Compose(driver) c.sendEmail(mailto, subject, content) logInfo("Sleep for few seconds") time.sleep(3) c.logOut()
def signinGmail(driver, userid, password): logInfo("siginGmail() ") g = Gmail_SigninUserID(driver, userid) g.submitUserID() logInfo("Sleep for few seconds") time.sleep(3) g1 = Gmail_SigninPassword(driver, password) g1.submitPassword()
def getUserLogin(): logInfo("initSetup()") logInfo("Retrieve userid/password from excel") f = "C:\\2018\\edureka\\selenium\\INPUT\\gmail_input.xlsx" sh = ReadExcel(f, 'Sheet1') userid = sh.get_data('A1') password = sh.get_data('B1') #logInfo("userid : " + userid + " password : " + password) return (userid, password)
def sendEmail(self, mailto, subject, content): logInfo("Gmail_Compose : sendEmail()") self.composeBtn.click() time.sleep(10) # visible only after click() self.driver.find_element_by_name("to").send_keys(mailto) self.driver.find_element_by_name("subjectbox").send_keys(subject) self.driver.find_element_by_xpath("//*[@id=\":nk\"]").send_keys( content) self.driver.find_element_by_xpath("//*[@id=\":m5\"]").click()
def main(): userdata = getUserLogin() print(userdata) driver = startChromeBrowser() logInfo("Test-1 : siginGmail() ") signinGmail(driver, userdata[0], userdata[1]) logInfo("Sleep for few seconds") time.sleep(10) logInfo("Test-2 : composeGmail() and logOut() ") mailto = "*****@*****.**" subject = "Automated Gmail test" content = "This is an email sent via Selenium." composeGmail(driver, mailto, subject, content) browserClose(driver) logInfo("DONE!")
def browserClose(driver): logInfo("browserClose()") logInfo("Close browser") driver.close()
def browserSetup(driverPath, url): logInfo("browserSetup()") logInfo("Start Chrome webdriver") driver = webdriver.Chrome(executable_path=driverPath) logInfo("Set Page load timeout 30 sec") driver.set_page_load_timeout(30) logInfo("Set Implicitly Wait timeout 15 sec") driver.implicitly_wait(15) logInfo("Navigate to URL : " + url) driver.get(url) logInfo("Maximize Window") driver.maximize_window() return driver
def main(): logInfo("Retrieve userid/password from excel") f = "C:\\2018\\edureka\\selenium\\INPUT\\gmail_input.xlsx" sh = ReadExcel(f, 'Sheet1') userid = sh.get_data('A1') password = sh.get_data('B1') logInfo("userid : " + userid + " password : "******"C:\\2018\\Python\\selenium\\chromedriver.exe" url = "https://www.gmail.com/" driver = browserSetup(driverPath, url) g = Gmail_SigninUserID(driver, userid) g.submitUserID() logInfo("Sleep for few seconds") time.sleep(3) g1 = Gmail_SigninPassword(driver, password) g1.submitPassword() logInfo("Sleep for few seconds") time.sleep(10) mailto = "*****@*****.**" subject = "Automated Gmail test" content = "This is an email sent via Selenium." c = Gmail_Compose(driver) c.sendEmail(mailto, subject, content) logInfo("Sleep for few seconds") time.sleep(3) c.logOut() logInfo("DONE!")
def submitPassword(self): logInfo("Gmail_SigninPassword : submitPassword()") self.passWORD.send_keys(self.password) self.nextBtn.click()
def submitUserID(self): logInfo("Gmail_SigninUserID : submitUserID()") self.userID.send_keys(self.userid) self.nextBtn.click()