Skip to content

Commit

Permalink
Update scripts versions
Browse files Browse the repository at this point in the history
  • Loading branch information
carogomezt committed Feb 9, 2019
1 parent 3799eb7 commit fb89ef3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
12 changes: 8 additions & 4 deletions fb-post-automation/facebook_group_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from time import sleep
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Expand All @@ -16,8 +17,8 @@ def driver_initialize(url):
:param url: URL to load once the driver starts
"""
options = webdriver.FirefoxOptions()
# options.add_argument('--headless')
options = Options()
# options.headless = True
options.set_preference('dom.webnotifications.enabled', False)
driver = webdriver.Firefox(options=options)
driver.get(url)
Expand All @@ -32,6 +33,7 @@ def login_fb(driver, user, password):
:param user: Facebook username
:param password: Facebook password
"""
print('Logging on Facebook')
elem = driver.find_element_by_id('email')
elem.send_keys(user)
elem = driver.find_element_by_id('pass')
Expand All @@ -49,6 +51,7 @@ def post_fb_group(message, group_links):
"""
user = os.environ['FB_USR']
password = os.environ['FB_PWD']
print('Open Facebook page')
driver = driver_initialize('https://www.facebook.com/')
login_fb(driver, user, password)
for group in group_links:
Expand All @@ -58,15 +61,16 @@ def post_fb_group(message, group_links):
WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, xpath)))
post_box = driver.find_element_by_xpath(xpath)
# Enter the text we want to post to Facebook
print('Enter the text we want to post to Facebook')
post_box.send_keys(message)
sleep(10)
# Get the 'Post' button and click on it
print('Get the "Post" button and click on it')
submit_button_xpath = '//*[@data-testid="react-composer-post-button"]'
WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, submit_button_xpath)))
post_button = driver.find_element_by_xpath(submit_button_xpath)
post_button.click()
print('Post published')
sleep(5)
driver.close()

Expand Down
1 change: 1 addition & 0 deletions selenium-grid/node_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_selenium_version(self):
'package-header__name')
print(package_name.text)
package_version = package_name.text.split(' ')[1]
time.sleep(3)
self.assertEqual(package_version, '3.141.0')

def tearDown(self):
Expand Down
9 changes: 7 additions & 2 deletions tw-post-automation/twitter_post_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from time import sleep
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Expand All @@ -16,8 +17,8 @@ def driver_initialize(url):
:param url: URL to load once the driver starts
"""
options = webdriver.FirefoxOptions()
# options.add_argument('--headless')
options = Options()
# options.headless = True
options.set_preference('dom.webnotifications.enabled', False)
driver = webdriver.Firefox(options=options)
driver.get(url)
Expand All @@ -32,6 +33,7 @@ def login_tw(driver, user, password):
:param user: Twitter username
:param password: Twitter password
"""
print('Logging on Twitter')
login_button = driver.find_element_by_link_text('Log in')
login_button.click()
elem = driver.find_element_by_class_name('js-username-field')
Expand All @@ -50,8 +52,10 @@ def post_twitter(message):
"""
user = os.environ['TW_USR']
password = os.environ['TW_PWD']
print('Open Facebook page')
driver = driver_initialize('https://www.twitter.com')
login_tw(driver, user, password)
print('Enter the text we want to post to Twitter')
post_box = driver.find_element_by_id('tweet-box-home-timeline')
post_box.send_keys(message)
submit_button_xpath = '//form/div[3]/div[2]/button'
Expand All @@ -60,6 +64,7 @@ def post_twitter(message):
post_button = driver.find_element_by_xpath(submit_button_xpath)
post_button.click()
sleep(5)
print('Post published')
driver.close()


Expand Down
43 changes: 26 additions & 17 deletions unittest-automation/unittest_automation_script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import time
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Expand All @@ -9,39 +10,47 @@
class SearchVersion(unittest.TestCase):

def setUp(self):
options = webdriver.FirefoxOptions()
options.add_argument('--headless')
options = Options()
# options.headless = True
options.set_preference('dom.webnotifications.enabled', False)
self.driver = webdriver.Firefox(options=options)

def test_search_by_text(self):
def search_page(self):
self.driver.get('https://www.google.com/')
self.search_field = self.driver.find_element_by_name('q')
self.search_field.send_keys('Selenium pip')
self.search_field.submit()
search_field = self.driver.find_element_by_name('q')
search_field.send_keys('Selenium pip')
search_field.submit()
result_xpath = '//div[1]/a[1]/div/cite'
WebDriverWait(self.driver, 20).until(
EC.presence_of_element_located((By.XPATH, result_xpath)))
self.page_url = self.driver.find_element_by_xpath(result_xpath)
page_url_text = self.page_url.text
page_url = self.driver.find_element_by_xpath(result_xpath)
return page_url

def test_search_by_text(self):
page_url = self.search_page()
page_url_text = page_url.text
time.sleep(3)
self.assertEqual(page_url_text, 'https://pypi.org/project/selenium/')

def test_selenium_last_release(self):
page_url = self.search_page()
page_url.click()
package_name = self.driver.find_element_by_class_name(
'-js-relative-time')
package_version = package_name.text
time.sleep(3)
self.assertIn('2019', package_version)

def test_selenium_version(self):
self.driver.get('https://www.google.com/')
self.search_field = self.driver.find_element_by_name('q')
self.search_field.send_keys('Selenium pip')
self.search_field.submit()
result_xpath = '//div[1]/a[1]/div/cite'
WebDriverWait(self.driver, 20).until(
EC.presence_of_element_located((By.XPATH, result_xpath)))
self.page_url = self.driver.find_element_by_xpath(result_xpath)
self.page_url.click()
page_url = self.search_page()
page_url.click()
package_name = self.driver.find_element_by_class_name(
'package-header__name')
curr_time = str(time.time()).split('.')[0]
file_name = 'selenium-version{date}.png'.format(date=curr_time)
self.driver.save_screenshot(file_name)
package_version = package_name.text.split(' ')[1]
time.sleep(3)
self.assertEqual(package_version, '3.141.0')

def tearDown(self):
Expand Down

0 comments on commit fb89ef3

Please sign in to comment.