open-bounty/test/end-to-end/tests/basetestcase.py

142 lines
5.3 KiB
Python
Raw Normal View History

2018-04-06 11:58:07 +00:00
import pytest, sys, os
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from tests.postconditions import remove_application, remove_installation
2018-04-09 10:07:41 +00:00
from os import environ
from tests import test_data
from pages.thirdparty.github import GithubPage
from pages.openbounty.landing import LandingPage
2018-04-09 10:07:41 +00:00
class BaseTestCase:
def print_sauce_lab_info(self, driver):
sys.stdout = sys.stderr
print("SauceOnDemandSessionID=%s job-name=%s" % (driver.session_id,
pytest.config.getoption('build')))
2018-04-09 10:07:41 +00:00
def get_remote_caps(self):
sauce_lab_cap = dict()
sauce_lab_cap['name'] = test_data.test_name
sauce_lab_cap['build'] = pytest.config.getoption('build')
2018-03-13 08:21:30 +00:00
sauce_lab_cap['idleTimeout'] = 900
sauce_lab_cap['commandTimeout'] = 500
sauce_lab_cap['platform'] = "MAC"
sauce_lab_cap['browserName'] = 'Chrome'
sauce_lab_cap['screenResolution'] = '2048x1536'
sauce_lab_cap['captureHtml'] = False
return sauce_lab_cap
def verify_no_errors(self):
if self.errors:
msg = ''
for error in self.errors:
msg += (error + '\n')
pytest.fail(msg, pytrace=False)
@classmethod
def setup_class(cls):
cls.errors = []
2018-04-09 10:07:41 +00:00
cls.environment = pytest.config.getoption('env')
2018-04-09 10:07:41 +00:00
################################################################################################################
######### Drivers setup
################################################################################################################
#
# Dev Chrome options
#
cls.capabilities_dev = webdriver.ChromeOptions()
cls.capabilities_dev.add_argument('--start-fullscreen')
2018-01-22 16:19:05 +00:00
#
# Org Chrome options
#
cls.capabilities_org = webdriver.ChromeOptions()
2018-04-09 10:07:41 +00:00
cls.capabilities_org.add_extension(
os.path.join(test_data.tests_path, os.pardir, 'resources', 'metamask3_12_0.crx'))
#
# SauceLab capabilities
2018-03-13 08:41:36 +00:00
#
cls.executor_sauce_lab = 'http://%s:%s@ondemand.saucelabs.com:80/wd/hub' % (
2018-04-09 10:07:41 +00:00
environ.get('SAUCE_USERNAME'), environ.get('SAUCE_ACCESS_KEY'))
2018-03-30 21:19:12 +00:00
cls.drivers = []
if cls.environment == 'local':
for caps in cls.capabilities_dev, cls.capabilities_org:
driver = webdriver.Chrome(chrome_options=caps)
2018-03-30 21:19:12 +00:00
cls.drivers.append(driver)
if cls.environment == 'sauce':
for caps in cls.capabilities_dev, cls.capabilities_org:
2018-03-13 08:21:30 +00:00
remote = cls.get_remote_caps(cls)
new_caps = caps.to_capabilities()
2018-03-13 08:21:30 +00:00
new_caps.update(remote)
driver = webdriver.Remote(cls.executor_sauce_lab,
desired_capabilities=new_caps)
2018-03-30 21:19:12 +00:00
cls.drivers.append(driver)
2018-03-30 21:19:12 +00:00
cls.driver_dev = cls.drivers[0]
cls.driver_org = cls.drivers[1]
2018-03-30 21:19:12 +00:00
for driver in cls.drivers:
2018-04-09 10:07:41 +00:00
driver.implicitly_wait(10)
2018-03-30 21:19:12 +00:00
2018-04-09 10:07:41 +00:00
################################################################################################################
######### Actions for each driver before class
################################################################################################################
######ORG
landing = LandingPage(cls.driver_org)
landing.get_landing_page()
2018-04-09 10:07:41 +00:00
# Sign Up to SOB
cls.github_org = landing.login_button.click()
cls.github_org.sign_in(test_data.config['ORG']['gh_login'],
2018-04-09 10:07:41 +00:00
test_data.config['ORG']['gh_password'])
assert cls.github_org.permission_type.text == 'Personal user data'
bounties_page = cls.github_org.authorize_sob.click()
# SOB Plugin installation and navigate to "Open bounties"
cls.github_org.install_sob_plugin()
assert bounties_page.bounties_header.text == 'Bounties'
assert bounties_page.top_hunters_header.text == 'Top 5 hunters'
######DEV
cls.github_dev = GithubPage(cls.driver_dev)
# Sign In to GH as Developer
cls.github_dev.get_login_page()
cls.github_dev.sign_in(test_data.config['DEV']['gh_login'],
2018-04-09 10:07:41 +00:00
test_data.config['DEV']['gh_password'])
2018-04-09 10:07:41 +00:00
# Fork repo as Developer from Organization
cls.github_dev.fork_repo(test_data.config['ORG']['gh_repo'])
2018-04-09 10:07:41 +00:00
# Cloning repo to local git as Developer and set upstream to Organization (via HTTPS)
cls.github_dev.clone_repo(test_data.config['ORG']['gh_repo'],
2018-04-06 11:58:07 +00:00
test_data.config['DEV']['gh_username'],
test_data.config['ORG']['gh_repo_name'])
cls.verify_no_errors(cls)
@classmethod
def teardown_class(cls):
######ORG
# SOB Plugin remove installation
remove_application(cls.driver_org)
remove_installation(cls.driver_org)
######DEV
cls.github_dev.clean_repo_local_folder()
2018-03-13 08:21:30 +00:00
cls.github_dev.delete_fork()
try:
2018-03-30 21:19:12 +00:00
for driver in cls.drivers:
cls.print_sauce_lab_info(cls, driver)
driver.quit()
except WebDriverException:
pass