2017-12-03 15:02:14 +00:00
|
|
|
import pytest, sys
|
|
|
|
from selenium import webdriver
|
|
|
|
from selenium.common.exceptions import WebDriverException
|
|
|
|
from tests.postconditions import remove_application, remove_installation
|
|
|
|
from os import environ, path
|
|
|
|
from tests import test_data
|
|
|
|
|
|
|
|
|
|
|
|
class BaseTestCase:
|
|
|
|
|
|
|
|
@property
|
|
|
|
def sauce_username(self):
|
|
|
|
return environ.get('SAUCE_USERNAME')
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
def sauce_access_key(self):
|
|
|
|
return environ.get('SAUCE_ACCESS_KEY')
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
def executor_sauce_lab(self):
|
|
|
|
return 'http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % (self.sauce_username, self.sauce_access_key)
|
|
|
|
|
|
|
|
def print_sauce_lab_info(self, driver):
|
|
|
|
sys.stdout = sys.stderr
|
|
|
|
print("SauceOnDemandSessionID=%s job-name=%s" % (driver.session_id,
|
|
|
|
pytest.config.getoption('build')))
|
|
|
|
|
|
|
|
@property
|
|
|
|
def capabilities_sauce_lab(self):
|
|
|
|
|
|
|
|
desired_caps = dict()
|
|
|
|
desired_caps['name'] = test_data.test_name
|
|
|
|
desired_caps['build'] = pytest.config.getoption('build')
|
|
|
|
desired_caps['platform'] = "MAC"
|
|
|
|
desired_caps['browserName'] = 'Chrome'
|
|
|
|
desired_caps['screenResolution'] = '2048x1536'
|
|
|
|
desired_caps['captureHtml'] = False
|
|
|
|
return desired_caps
|
|
|
|
|
2018-01-22 16:19:05 +00:00
|
|
|
@property
|
|
|
|
def environment(self):
|
|
|
|
return pytest.config.getoption('env')
|
|
|
|
|
2017-12-03 15:02:14 +00:00
|
|
|
def setup_method(self):
|
|
|
|
|
|
|
|
self.errors = []
|
2018-01-24 10:58:58 +00:00
|
|
|
self.cleanup = None
|
2017-12-03 15:02:14 +00:00
|
|
|
|
2018-01-22 16:19:05 +00:00
|
|
|
if self.environment == 'local':
|
|
|
|
options = webdriver.ChromeOptions()
|
|
|
|
options.add_argument('--start-fullscreen')
|
2018-01-24 10:58:58 +00:00
|
|
|
options.add_extension(
|
|
|
|
path.abspath(test_data.config['Paths']['tests_absolute'] + 'resources/metamask3_12_0.crx'))
|
|
|
|
# for chromedriver 2.35
|
|
|
|
self.driver = webdriver.Chrome(chrome_options=options)
|
2018-01-22 16:19:05 +00:00
|
|
|
if self.environment == 'sauce':
|
|
|
|
self.driver = webdriver.Remote(self.executor_sauce_lab,
|
|
|
|
desired_capabilities=self.capabilities_sauce_lab)
|
2017-12-03 15:02:14 +00:00
|
|
|
self.driver.implicitly_wait(5)
|
|
|
|
|
2018-01-24 10:58:58 +00:00
|
|
|
|
|
|
|
|
2017-12-03 15:02:14 +00:00
|
|
|
def verify_no_errors(self):
|
|
|
|
if self.errors:
|
|
|
|
msg = ''
|
|
|
|
for error in self.errors:
|
|
|
|
msg += (error + '\n')
|
|
|
|
pytest.fail(msg, pytrace=False)
|
|
|
|
|
|
|
|
def teardown_method(self):
|
2018-01-24 10:58:58 +00:00
|
|
|
if self.cleanup:
|
|
|
|
remove_application(self.driver)
|
|
|
|
remove_installation(self.driver)
|
2017-12-03 15:02:14 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
self.print_sauce_lab_info(self.driver)
|
|
|
|
self.driver.quit()
|
|
|
|
except WebDriverException:
|
|
|
|
pass
|