Monday, July 8, 2019

Program to Fetch Alert count and Send Email

Program to Fetch Alert count and Send Email

Step used to Fetch alert count and send email to admin user accordingly
1.Open IBM Sterling WMS
2. Login into the System
3. Open Alert console
4. Input Username to search
5. Click Search button
6. Fetch No. of alerts to user
7. If count greater than 0, Send email with number of alerts
8. If count 0, Send email with no alerts

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
import urllib.parse as urlparse
import pyautogui, time
import smtplib

driver = webdriver.Ie()
driver.get("http://localhost:7001/smcfs/console/login.jsp")
time.sleep(0)

# Set value to Username
userName  = driver.find_element_by_name("UserId")
userName.send_keys("testuser")

# Set value to Password
passWord  = driver.find_element_by_name("Password")
passWord.send_keys("testuser")

# Submit the Form
submitForm  = driver.find_element_by_name("btnLogin")
submitForm.click()
time.sleep(1)

#Open Alert Console
adjust="http://localhost:7001/smcfs/console/exception.search"
driver.get(adjust)
time.sleep(1)

#Input - Username to whom the Alerts assigned
driver.find_element_by_name("xml:/Inbox/User/@Loginid").send_keys("mano")
driver.find_element_by_name("btnSearch").click()
time.sleep(1)

#Obtaining value from Retrived records count
records=driver.execute_script("return document.all['TotalNumRecs'].value")
recordCount=int(records)
if recordCount>0:    
    FROM="FROMUSER@gmail.com"
    TO = "TOUSER@gmail.com"
    SUBJECT = "Alert Count"
    TEXT = "Hi Team, \n\nThere are "+records+" alerts to be closed. \n\nRegards\nAutomated Selenium Python Alert Team"
    message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    server.login("USERNAME", "PASSWORD")
    server.sendmail(FROM, TO, message)
    server.quit()
else:
    FROM = "FROMUSER@gmail.com"
    TO = "TOUSER@gmail.com"
    SUBJECT = "Alert Count"
    TEXT = "Hi Team, \n\nThere are no alert right now. \n\nRegards\nAutomated Selenium Python Alert Team"
    message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    server.login("USERNAME", "PASSWORD")
    server.sendmail(FROM, TO, message)
    server.quit()


No comments:

Post a Comment

Popular Posts