Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created November 5, 2021 16:43
Show Gist options
  • Select an option

  • Save muditlambda/840966b8df6ba1600970ff7ea8bf47ed to your computer and use it in GitHub Desktop.

Select an option

Save muditlambda/840966b8df6ba1600970ff7ea8bf47ed to your computer and use it in GitHub Desktop.
from selenium import webdriver
import smtplib, ssl
port = 587
smtp_server = "smtp.gmail.com"
sender_password = "<YOUR_PASSWORD>"
sender_email = "<YOUR_EMAIL>"
receiver_email = "<EMAIL_WHERE_YOU_WANT_TO_SEND>"
def send_email(message):
context = ssl.create_default_context()
try:
server = smtplib.SMTP(smtp_server,port)
server.ehlo() # Can be omitted
server.starttls(context=context) # Secure the connection
server.ehlo() # Can be omitted
server.login(sender_email, sender_password)
server.sendmail(sender_email, receiver_email, message)
server.close()
except:
print(" failed to send email ")
username = "<YOUR_LAMBDATEST_USERNAME>"
access_key = "<YOUR__LAMBDATEST_ACCESS_KEY>"
class TestClass():
def setup_method(self):
desired_caps = {
"build": "your build name",
"name": "your test name",
"platform": "Windows 10",
"browserName": "Chrome",
"version": "92.0",
"selenium_version": "3.13.0",
"geoLocation": "IN",
"chrome.driver": "91.0",
}
"""
Setup remote driver
-------
username and access_key can be found on lt platform
"""
self.driver = webdriver.Remote(
command_executor="https://{}:{}@hub.lambdatest.com/wd/hub".format(
username, access_key
),
desired_capabilities=desired_caps,
)
# tearDown runs after each test case
def teardown_method(self):
self.driver.quit()
def test_login(self):
"""
this function logins you in lambdatest dashboard
"""
LOGIN_URL = "https://accounts.lambdatest.com/login"
DASHBOARD_URL = "https://accounts.lambdatest.com/dashboard"
self.driver.get(LOGIN_URL)
login_email = self.driver.find_element_by_xpath(
"//input[@id='email']"
)
login_password = self.driver.find_element_by_xpath(
"//input[@id='password']"
)
login_button = self.driver.find_element_by_xpath(
"//button[@id='login-button']"
)
login_email.send_keys(email)
login_password.send_keys(password)
login_button.click()
# if we are on the right page
if self.driver.current_url == DASHBOARD_URL :
assert True
# time to get recent tests
self.get_recent_tests()
else:
print("something went wrong !!")
assert False
def get_recent_tests(self):
titles = self.driver.find_elements_by_class_name("cut-text")
titles_list = []
for i in titles:
titles_list.append(i.text)
message = ' '.join(titles_list[0::2])
send_email(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment