import unittest,imp
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from conf import config
class OpenBrowser(unittest.TestCase):
imp.reload(config)
browser = config.BROWSER
base_url = config.URL
is_mobile = (browser == 'iPhone') or (browser == 'android') or (browser == 'iPad')
is_mobile1 = (browser == 'iPhone') or (browser == 'android')
is_desktop = (browser == 'chrome') or (browser == 'ie') or (browser == 'firefox')
is_preview = "preview" in base_url
is_thrive = 'thrive' in base_url
is_vivabien = 'vivabien' in base_url
if is_thrive:
if is_preview:
cookies = {u'domain': u'preview.thrive.prod.dpaprod.kpwpce.kp-aws-cloud.org', u'secure': False, u'value': u'nca', u'path': u'/', u'httpOnly': False, u'name': u'thriveRegion'}
else:
cookies = {u'domain': u'thrive.kaiserpermanente.org', u'secure': False, u'value': u'nca', u'path': u'/', u'httpOnly': False, u'name': u'thriveRegion'}
else:
if is_preview:
cookies = {u'domain': u'preview.vivabien.prod.dpaprod.kpwpce.kp-aws-cloud.org', u'secure': False, u'value': u'nca', u'path': u'/', u'httpOnly': False, u'name': u'thriveRegion'}
else:
cookies = {u'domain': u'vivabien.kaiserpermanente.org', u'secure': False, u'value': u'nca', u'path': u'/', u'httpOnly': False, u'name': u'thriveRegion'}
print ("start testing site " + base_url + " on browser: " + browser)
@classmethod
def setUpClass(cls):
if cls.browser == 'chrome':
options = webdriver.ChromeOptions()
#options.add_argument("test-type")
options.add_argument("start-maximized")
options.add_argument("--disable-extensions")
options.add_argument("--disable-infobars")
cls.driver = webdriver.Chrome(chrome_options=options)
elif cls.browser == 'ie':
cls.driver = webdriver.Ie()
cls.driver.maximize_window()
elif cls.browser == 'firefox':
binary = FirefoxBinary()
cls.driver = webdriver.Firefox(firefox_binary=binary)
cls.driver.maximize_window()
elif cls.browser == 'android':
WIDTH = 360
HEIGHT = 640
PIXEL_RATIO = 3.0
UA = 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36'
mobileEmulation = {"deviceMetrics": {"width": WIDTH, "height": HEIGHT, "pixelRatio": PIXEL_RATIO}, "userAgent": UA}
options = webdriver.ChromeOptions()
options.add_experimental_option('mobileEmulation', mobileEmulation)
options.add_argument("start-maximized")
options.add_argument("--disable-extensions")
options.add_argument("--disable-infobars")
cls.driver = webdriver.Chrome(chrome_options=options)
elif cls.browser == 'iPhone':
WIDTH = 375
HEIGHT = 640
PIXEL_RATIO = 3.0
UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'
mobileEmulation = {"deviceMetrics": {"width": WIDTH, "height": HEIGHT, "pixelRatio": PIXEL_RATIO}, "userAgent": UA}
options = webdriver.ChromeOptions()
options.add_experimental_option('mobileEmulation', mobileEmulation)
options.add_argument("start-maximized")
options.add_argument("--disable-extensions")
options.add_argument("--disable-infobars")
cls.driver = webdriver.Chrome(chrome_options=options)
elif cls.browser == 'iPad':
WIDTH = 768
HEIGHT = 640
PIXEL_RATIO = 3.0
UA = 'Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'
#UA = 'Mozilla/5.0 (iPad; CPU OS 9_1 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
mobileEmulation = {"deviceMetrics": {"width": WIDTH, "height": HEIGHT, "pixelRatio": PIXEL_RATIO}, "userAgent": UA}
options = webdriver.ChromeOptions()
options.add_experimental_option('mobileEmulation', mobileEmulation)
options.add_argument("start-maximized")
options.add_argument("--disable-extensions")
options.add_argument("--disable-infobars")
cls.driver = webdriver.Chrome(chrome_options=options)
@classmethod
def tearDownClass(cls):
cls.driver.quit()