2018-04-06 11:58:07 +00:00
|
|
|
import time, pytest, git, os, shutil, logging
|
2018-04-09 10:07:41 +00:00
|
|
|
from selenium.common.exceptions import TimeoutException
|
|
|
|
from pages.base_element import BaseEditBox, BaseButton, BaseText
|
2017-12-03 15:02:14 +00:00
|
|
|
from pages.base_page import BasePageObject
|
2018-01-24 10:58:58 +00:00
|
|
|
from tests import test_data
|
2018-04-06 11:58:07 +00:00
|
|
|
|
2017-12-03 15:02:14 +00:00
|
|
|
|
|
|
|
class EmailEditbox(BaseEditBox):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(EmailEditbox, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.id('login_field')
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordEditbox(BaseEditBox):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(PasswordEditbox, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.id('password')
|
|
|
|
|
|
|
|
|
|
|
|
class SignInButton(BaseButton):
|
|
|
|
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(SignInButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.name('commit')
|
|
|
|
|
|
|
|
|
|
|
|
class AuthorizeStatusOpenBounty(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(AuthorizeStatusOpenBounty, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector('[data-octo-click="oauth_application_authorization"]')
|
|
|
|
|
|
|
|
def navigate(self):
|
|
|
|
from pages.openbounty.bounties import BountiesPage
|
|
|
|
return BountiesPage(self.driver)
|
|
|
|
|
|
|
|
|
|
|
|
class PermissionTypeText(BaseText):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(PermissionTypeText, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector('.permission-title')
|
|
|
|
|
|
|
|
|
|
|
|
class InstallButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(InstallButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector('.btn-primary')
|
|
|
|
|
|
|
|
|
|
|
|
class OrganizationButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(OrganizationButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector('[alt="@Org4"]')
|
|
|
|
|
|
|
|
|
|
|
|
class AllRepositoriesButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(AllRepositoriesButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.id('install_target_all')
|
|
|
|
|
|
|
|
|
|
|
|
class IntegrationPermissionsGroup(BaseText):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(IntegrationPermissionsGroup, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector('.integrations-permissions-group')
|
|
|
|
|
|
|
|
|
|
|
|
class NewIssueButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(NewIssueButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector(".subnav [role='button']")
|
|
|
|
|
|
|
|
|
|
|
|
class IssueTitleEditBox(BaseEditBox):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(IssueTitleEditBox, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.id("issue_title")
|
|
|
|
|
|
|
|
|
|
|
|
class LabelsButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(LabelsButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector("button[aria-label='Apply labels to this issue']")
|
|
|
|
|
|
|
|
class BountyLabel(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(LabelsButton.BountyLabel, self).__init__(driver)
|
2018-01-22 16:19:05 +00:00
|
|
|
self.locator = self.Locator.css_selector("[data-name='748942015']")
|
2017-12-03 15:02:14 +00:00
|
|
|
|
|
|
|
class CrossButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(LabelsButton.CrossButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector(
|
|
|
|
"//span[text()='Apply labels to this issue']/../*[@aria-label='Close']")
|
|
|
|
|
|
|
|
|
|
|
|
class SubmitNewIssueButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(SubmitNewIssueButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//button[contains(text(), "
|
|
|
|
"'Submit new issue')]")
|
|
|
|
|
|
|
|
|
|
|
|
class ContractBody(BaseText):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ContractBody, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//tbody//p[contains(text(), "
|
|
|
|
"'Current balance: 0.000000 ETH')]")
|
2018-04-09 10:07:41 +00:00
|
|
|
|
|
|
|
|
2018-01-26 18:12:58 +00:00
|
|
|
class IssueId(BaseText):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(IssueId, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector(".gh-header-number")
|
|
|
|
|
2018-04-09 10:07:41 +00:00
|
|
|
|
2018-01-26 18:12:58 +00:00
|
|
|
class ForkButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ForkButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector("[href='#fork-destination-box']")
|
|
|
|
|
2018-04-09 10:07:41 +00:00
|
|
|
|
2018-01-26 18:12:58 +00:00
|
|
|
class HeaderInForkPopup(BaseText):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(HeaderInForkPopup, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector("#facebox-header")
|
|
|
|
|
2018-04-09 10:07:41 +00:00
|
|
|
|
2018-01-26 18:12:58 +00:00
|
|
|
class UserAccountInForkPopup(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(UserAccountInForkPopup, self).__init__(driver)
|
2018-04-09 10:07:41 +00:00
|
|
|
self.locator = self.Locator.css_selector("[value=%s]" % test_data.config['DEV']['gh_username'])
|
2018-01-26 18:12:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ForkedRepoText(BaseText):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ForkedRepoText, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector(".commit-tease")
|
|
|
|
|
2018-04-09 10:07:41 +00:00
|
|
|
|
2018-02-05 14:14:28 +00:00
|
|
|
class DeleteRepo(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(DeleteRepo, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//button[text()[contains(.,' Delete this repository')]]")
|
|
|
|
|
2018-04-09 10:07:41 +00:00
|
|
|
|
2018-02-05 14:14:28 +00:00
|
|
|
class RepoNameBoxInPopup(BaseEditBox):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(RepoNameBoxInPopup, self).__init__(driver)
|
2018-04-09 10:07:41 +00:00
|
|
|
self.locator = self.Locator.css_selector(
|
|
|
|
"input[aria-label='Type in the name of the repository to confirm that you want to delete this repository.']")
|
|
|
|
|
2017-12-03 15:02:14 +00:00
|
|
|
|
2018-02-05 14:14:28 +00:00
|
|
|
class ConfirmDeleteButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(ConfirmDeleteButton, self).__init__(driver)
|
2018-04-09 10:07:41 +00:00
|
|
|
self.locator = self.Locator.xpath_selector(
|
|
|
|
"//button[text()[contains(.,'I understand the consequences, delete')]]")
|
|
|
|
|
2017-12-03 15:02:14 +00:00
|
|
|
|
2018-04-06 11:58:07 +00:00
|
|
|
class CompareAndPullRequest(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(CompareAndPullRequest, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.css_selector(".RecentBranches a")
|
|
|
|
|
2018-04-09 10:07:41 +00:00
|
|
|
|
2018-04-06 11:58:07 +00:00
|
|
|
class PrTitleEditBox(BaseEditBox):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(PrTitleEditBox, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.id("pull_request_body")
|
|
|
|
|
2018-04-09 10:07:41 +00:00
|
|
|
|
2018-04-06 11:58:07 +00:00
|
|
|
class SubmitNewPrButton(BaseButton):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(SubmitNewPrButton, self).__init__(driver)
|
|
|
|
self.locator = self.Locator.xpath_selector("//button[contains(text(), "
|
|
|
|
"'Create pull request')]")
|
|
|
|
|
|
|
|
|
2017-12-03 15:02:14 +00:00
|
|
|
class GithubPage(BasePageObject):
|
|
|
|
def __init__(self, driver):
|
|
|
|
super(GithubPage, self).__init__(driver)
|
|
|
|
|
|
|
|
self.driver = driver
|
|
|
|
|
2018-04-06 11:58:07 +00:00
|
|
|
# sign in and installation related
|
2017-12-03 15:02:14 +00:00
|
|
|
self.email_input = EmailEditbox(self.driver)
|
|
|
|
self.password_input = PasswordEditbox(self.driver)
|
|
|
|
self.sign_in_button = SignInButton(self.driver)
|
|
|
|
self.authorize_sob = AuthorizeStatusOpenBounty(self.driver)
|
|
|
|
self.permission_type = PermissionTypeText(self.driver)
|
|
|
|
self.install_button = InstallButton(self.driver)
|
|
|
|
self.organization_button = OrganizationButton(self.driver)
|
|
|
|
self.all_repositories_button = AllRepositoriesButton(self.driver)
|
|
|
|
self.integration_permissions_group = IntegrationPermissionsGroup(self.driver)
|
|
|
|
|
2018-04-06 11:58:07 +00:00
|
|
|
# issue related
|
2017-12-03 15:02:14 +00:00
|
|
|
self.new_issue_button = NewIssueButton(self.driver)
|
|
|
|
self.issue_title_input = IssueTitleEditBox(self.driver)
|
|
|
|
self.labels_button = LabelsButton(self.driver)
|
|
|
|
self.bounty_label = LabelsButton.BountyLabel(self.driver)
|
|
|
|
self.cross_button = LabelsButton.CrossButton(self.driver)
|
|
|
|
self.submit_new_issue_button = SubmitNewIssueButton(self.driver)
|
|
|
|
self.contract_body = ContractBody(self.driver)
|
2018-01-26 18:12:58 +00:00
|
|
|
self.issue_id = IssueId(self.driver)
|
2018-04-06 11:58:07 +00:00
|
|
|
|
|
|
|
# repo forking
|
2018-01-26 18:12:58 +00:00
|
|
|
self.fork_button = ForkButton(self.driver)
|
|
|
|
self.header_in_fork_popup = HeaderInForkPopup(self.driver)
|
|
|
|
self.user_account_in_fork_popup = UserAccountInForkPopup(self.driver)
|
|
|
|
self.forked_repo_text = ForkedRepoText(self.driver)
|
|
|
|
|
2018-04-06 11:58:07 +00:00
|
|
|
# repo deleting
|
2018-02-05 14:14:28 +00:00
|
|
|
self.delete_repo = DeleteRepo(self.driver)
|
|
|
|
self.repo_name_confirm_delete = RepoNameBoxInPopup(self.driver)
|
|
|
|
self.confirm_delete = ConfirmDeleteButton(self.driver)
|
|
|
|
|
2018-04-06 11:58:07 +00:00
|
|
|
# PR related
|
|
|
|
self.compare_and_pull_request = CompareAndPullRequest(self.driver)
|
|
|
|
self.pr_body = PrTitleEditBox(self.driver)
|
|
|
|
self.submit_new_pr_button = SubmitNewPrButton(self.driver)
|
|
|
|
|
2017-12-03 15:02:14 +00:00
|
|
|
def get_issues_page(self):
|
2018-04-09 10:07:41 +00:00
|
|
|
self.driver.get('%sissues' % test_data.config['ORG']['gh_repo'])
|
2018-01-26 18:12:58 +00:00
|
|
|
|
|
|
|
def get_issue_page(self, issue_id):
|
2018-04-09 10:07:41 +00:00
|
|
|
self.driver.get('%sissues/%s' % (test_data.config['ORG']['gh_repo'], issue_id))
|
2017-12-03 15:02:14 +00:00
|
|
|
|
|
|
|
def get_sob_plugin_page(self):
|
2018-01-26 18:12:58 +00:00
|
|
|
self.driver.get(test_data.config['Common']['sob_test_app'])
|
2017-12-03 15:02:14 +00:00
|
|
|
|
|
|
|
def sign_in(self, email, password):
|
|
|
|
self.email_input.send_keys(email)
|
|
|
|
self.password_input.send_keys(password)
|
|
|
|
self.sign_in_button.click()
|
|
|
|
|
|
|
|
def install_sob_plugin(self):
|
|
|
|
initial_url = self.driver.current_url
|
|
|
|
self.get_sob_plugin_page()
|
|
|
|
self.install_button.click()
|
|
|
|
self.organization_button.click()
|
|
|
|
self.all_repositories_button.click()
|
|
|
|
self.install_button.click()
|
|
|
|
self.driver.get(initial_url)
|
|
|
|
|
|
|
|
def create_new_bounty(self):
|
|
|
|
self.get_issues_page()
|
|
|
|
self.new_issue_button.click()
|
2018-01-24 10:58:58 +00:00
|
|
|
test_data.issue = dict()
|
2018-04-06 11:58:07 +00:00
|
|
|
test_data.issue['title'] = 'auto_test_bounty_%s' % test_data.date_time
|
2018-01-24 10:58:58 +00:00
|
|
|
self.issue_title_input.send_keys(test_data.issue['title'])
|
2017-12-03 15:02:14 +00:00
|
|
|
self.labels_button.click()
|
|
|
|
self.bounty_label.click()
|
|
|
|
self.cross_button.click()
|
|
|
|
self.submit_new_issue_button.click()
|
2018-01-26 18:12:58 +00:00
|
|
|
test_data.issue['id'] = self.issue_id.text[1:]
|
2018-04-09 10:07:41 +00:00
|
|
|
logging.info("Issue title is %s" % test_data.issue['title'])
|
2018-01-26 18:12:58 +00:00
|
|
|
|
|
|
|
def fork_repo(self, initial_repo, wait=60):
|
|
|
|
self.driver.get(initial_repo)
|
|
|
|
self.fork_button.click()
|
|
|
|
if self.header_in_fork_popup.text == 'Where should we fork this repository?':
|
|
|
|
self.user_account_in_fork_popup.click()
|
|
|
|
self.forked_repo_text.wait_for_element(wait)
|
|
|
|
|
|
|
|
def get_login_page(self):
|
|
|
|
self.driver.get(test_data.config['Common']['gh_login'])
|
2017-12-03 15:02:14 +00:00
|
|
|
|
2018-04-25 07:29:36 +00:00
|
|
|
def get_deployed_contract(self, wait=50):
|
2017-12-03 15:02:14 +00:00
|
|
|
for i in range(wait):
|
|
|
|
self.refresh()
|
|
|
|
try:
|
|
|
|
return self.contract_body.text
|
|
|
|
except TimeoutException:
|
|
|
|
time.sleep(10)
|
|
|
|
pass
|
2018-04-25 07:29:36 +00:00
|
|
|
pytest.fail('Contract is not deployed in %s minutes!' % str(wait * 10 / 60))
|
2018-01-26 18:12:58 +00:00
|
|
|
|
2018-04-09 10:07:41 +00:00
|
|
|
# cloning via HTTPS
|
2018-04-06 11:58:07 +00:00
|
|
|
def clone_repo(self, initial_repo=None, username=None, repo_name=None, repo_folder='test_repo'):
|
|
|
|
os.mkdir(repo_folder)
|
|
|
|
os.chdir(repo_folder)
|
|
|
|
self.local_repo_path = os.getcwd()
|
2018-04-18 12:40:57 +00:00
|
|
|
fork = 'https://%s:%s@github.com/%s/%s.git' % (test_data.config['DEV']['gh_username'],
|
2018-04-18 12:09:16 +00:00
|
|
|
test_data.config['DEV']['gh_password'], username, repo_name)
|
2018-04-06 11:58:07 +00:00
|
|
|
logging.info(('Cloning from %s to %s' % (fork, self.local_repo_path)))
|
|
|
|
repo = git.Repo.clone_from(fork, self.local_repo_path)
|
|
|
|
logging.info(('Successefully cloned to: %s' % self.local_repo_path))
|
2018-04-09 10:07:41 +00:00
|
|
|
logging.info('Set upstream to %s' % initial_repo)
|
2018-04-06 11:58:07 +00:00
|
|
|
upstream = repo.create_remote('upstream', initial_repo)
|
2018-01-26 18:12:58 +00:00
|
|
|
upstream.fetch()
|
|
|
|
assert upstream.exists()
|
2018-04-06 11:58:07 +00:00
|
|
|
repo.heads.master.checkout()
|
|
|
|
|
2018-04-09 10:07:41 +00:00
|
|
|
def create_pr_git(self, branch, file_to_modify='test'):
|
2018-04-06 11:58:07 +00:00
|
|
|
repo = git.Repo(self.local_repo_path)
|
|
|
|
logging.info(repo.git.status())
|
|
|
|
logging.info(repo.git.pull('upstream', 'master'))
|
2018-04-23 15:41:25 +00:00
|
|
|
# repo_url = 'https://%s:%s@github.com/%s/%s.git' % (test_data.config['DEV']['gh_username'],
|
|
|
|
# test_data.config['DEV']['gh_password'], test_data.config['DEV']['gh_username'], test_data.config['ORG']['gh_repo_name'])
|
|
|
|
#
|
|
|
|
# logging.info('Pushing to %s' % repo_url)
|
|
|
|
# logging.info(repo.git.push(repo_url))
|
|
|
|
logging.info(repo.git.push('origin', 'master'))
|
2018-04-06 11:58:07 +00:00
|
|
|
logging.info(repo.git.fetch('--all'))
|
2018-04-09 10:07:41 +00:00
|
|
|
repo.git.checkout('-b', branch)
|
2018-04-06 11:58:07 +00:00
|
|
|
file = open(os.path.join(self.local_repo_path, file_to_modify), 'w')
|
|
|
|
file.write("Autotest change: %s \r \n" % test_data.date_time)
|
|
|
|
logging.info(repo.git.add('test'))
|
|
|
|
logging.info(repo.git.commit(m='Aut %s' % test_data.date_time))
|
|
|
|
repo.git.push('origin', branch)
|
|
|
|
|
|
|
|
def open_pr_github(self, keyword_comment):
|
|
|
|
self.get_url(test_data.config['DEV']['gh_forked_repo'])
|
|
|
|
self.compare_and_pull_request.click()
|
2018-04-09 10:07:41 +00:00
|
|
|
self.pr_body.send_keys('%s #%s' % (keyword_comment, test_data.issue['id']))
|
2018-04-06 11:58:07 +00:00
|
|
|
self.submit_new_pr_button.click()
|
2018-01-26 18:12:58 +00:00
|
|
|
|
|
|
|
def clean_repo_local_folder(self):
|
2018-04-06 11:58:07 +00:00
|
|
|
logging.info('Removing %s' % self.local_repo_path)
|
|
|
|
if self.local_repo_path:
|
|
|
|
shutil.rmtree(self.local_repo_path)
|
2018-01-26 18:12:58 +00:00
|
|
|
|
2018-02-05 14:14:28 +00:00
|
|
|
def delete_fork(self):
|
|
|
|
self.get_url(test_data.config['DEV']['gh_forked_repo'] + 'settings')
|
|
|
|
self.delete_repo.click()
|
|
|
|
self.repo_name_confirm_delete.send_keys(test_data.config['ORG']['gh_repo_name'])
|
|
|
|
self.confirm_delete.click()
|