def __init__(self, driver, project_key=None, repo_slug=None, pull_request_key=None):
     BasePage.__init__(self, driver)
     url_manager = UrlManager(project_key=project_key, repo_slug=repo_slug,
                              pull_request_key=pull_request_key)
     self.page_url = url_manager.pull_request_overview()
     self.diff_url = url_manager.pull_request_diff()
     self.commits_url = url_manager.pull_request_commits()
class RepoPullRequests(BasePage):
    page_loaded_selector = RepoLocators.pull_requests_list

    def __init__(self, driver, project_key, repo_slug):
        BasePage.__init__(self, driver)
        self.url_manager = UrlManager(project_key=project_key,
                                      repo_slug=repo_slug)
        self.page_url = self.url_manager.repo_pull_requests()

    def create_new_pull_request(self, from_branch, to_branch):
        self.go_to_url(url=self.url_manager.create_pull_request_url(
            from_branch=from_branch, to_branch=to_branch))
        self.submit_pull_request()

    def set_pull_request_source_branch(self, source_branch):
        self.wait_until_visible(RepoLocators.pr_source_branch_field).click()
        self.wait_until_visible(RepoLocators.pr_branches_dropdown)
        source_branch_name_field = self.get_element(
            RepoLocators.pr_source_branch_name)
        source_branch_name_field.send_keys(source_branch)
        self.wait_until_invisible(RepoLocators.pr_source_branch_spinner)
        source_branch_name_field.send_keys(Keys.ENTER)
        self.wait_until_invisible(RepoLocators.pr_branches_dropdown)

    def set_pull_request_destination_repo(self):
        self.wait_until_visible(RepoLocators.pr_destination_repo_field).click()
        self.wait_until_visible(
            RepoLocators.pr_destination_first_repo_dropdown).click()

    def set_pull_request_destination_branch(self, destination_branch):
        self.wait_until_visible(RepoLocators.pr_destination_branch_field)
        self.execute_js("document.querySelector('#targetBranch').click()")
        self.wait_until_visible(RepoLocators.pr_destination_branch_dropdown)
        destination_branch_name_field = self.get_element(
            RepoLocators.pr_destination_branch_name)
        destination_branch_name_field.send_keys(destination_branch)
        self.wait_until_invisible(RepoLocators.pr_destination_branch_spinner)
        destination_branch_name_field.send_keys(Keys.ENTER)
        self.wait_until_invisible(RepoLocators.pr_branches_dropdown)
        self.wait_until_clickable(RepoLocators.pr_continue_button)
        self.wait_until_visible(RepoLocators.pr_continue_button).click()

    def submit_pull_request(self):
        self.wait_until_visible(RepoLocators.pr_description_field)
        title = self.get_element(RepoLocators.pr_title_field)
        title.clear()
        title.send_keys('Selenium test pull request')
        self.wait_until_visible(RepoLocators.pr_submit_button).click()
        self.wait_until_visible(
            PullRequestLocator.pull_request_activity_content)
        self.wait_until_clickable(
            PullRequestLocator.pull_request_page_merge_button)
class LoginPage(BasePage):
    page_url = UrlManager().login_url()

    def fill_username(self, username):
        self.get_element(
            LoginPageLocators.username_textfield).send_keys(username)

    def fill_password(self, password):
        self.get_element(
            LoginPageLocators.password_textfield).send_keys(password)

    def submit_login(self):
        self.wait_until_visible(LoginPageLocators.submit_button).click()

    def set_credentials(self, username, password):
        self.fill_username(username)
        self.fill_password(password)

    def get_app_version(self):
        el = self.get_element(LoginPageLocators.application_version)
        return ''.join([i for i in el.text.split('.')[0] if i.isdigit()])

    def get_app_minor_version(self):
        el = self.get_element(LoginPageLocators.application_version)
        return ''.join([i for i in el.text.split('.')[1] if i.isdigit()])
class RepositoryBranches(BasePage):
    page_loaded_selector = BranchesLocator.branches_name

    def __init__(self, driver, project_key, repo_slug):
        BasePage.__init__(self, driver)
        self.url_manager = UrlManager(project_key=project_key,
                                      repo_slug=repo_slug)
        self.page_url = self.url_manager.repo_branches()

    def open_base_branch(self, base_branch_name):
        self.go_to_url(
            f"{self.url_manager.base_branch_url()}{base_branch_name}")
        self.wait_until_visible(BranchesLocator.branches_name)

    def create_branch_fork_rnd_name(self, base_branch_name):
        self.wait_until_visible(BranchesLocator.branches_action).click()
        self.get_element(BranchesLocator.branches_action_create_branch).click()
        self.wait_until_visible(BranchesLocator.new_branch_name_textfield)
        branch_name = f"{base_branch_name}-{self.generate_random_string(5)}".replace(
            ' ', '-')
        self.get_element(
            BranchesLocator.new_branch_name_textfield).send_keys(branch_name)
        self.wait_until_clickable(
            BranchesLocator.new_branch_submit_button).click()
        return branch_name

    def delete_branch(self, branch_name):
        self.wait_until_visible(
            BranchesLocator.search_branch_textfield).send_keys(branch_name)
        self.wait_until_visible(BranchesLocator.branches_name)
        self.wait_until_visible(BranchesLocator.search_branch_action).click()
        self.execute_js("document.querySelector('li>a.delete-branch').click()")
        self.wait_until_clickable(
            BranchesLocator.delete_branch_diaglog_submit).click()
class LoginPage(BasePage):
    page_url = UrlManager().login_url()

    def fill_username(self, username):
        self.get_element(
            LoginPageLocators.username_textfield).send_keys(username)

    def fill_password(self, password):
        self.get_element(
            LoginPageLocators.password_textfield).send_keys(password)

    def submit_login(self):
        self.wait_until_visible(LoginPageLocators.submit_button).click()

    def set_credentials(self, username, password):
        self.fill_username(username)
        self.fill_password(password)

    def get_app_version(self):
        text = self.get_element(LoginPageLocators.application_version).text
        return text.replace('v', '')

    def get_app_major_version(self):
        return self.get_app_version().split('.')[0]

    def get_node_id(self):
        text = self.get_element(LoginPageLocators.node_id).text
        return text.split('\n')[2]

    def is_logged_in(self):
        elements = self.get_elements(GetStartedLocators.user_profile_icon)
        return True if elements else False
 def __init__(self, driver, project_key):
     BasePage.__init__(self, driver)
     self.project_key = project_key
     url_manager = UrlManager(project_key=project_key)
     self.page_url = url_manager.project_url()
 def __init__(self, driver, project_key, repo_slug):
     BasePage.__init__(self, driver)
     url_manager = UrlManager(project_key=project_key, repo_slug=repo_slug)
     self.page_url = url_manager.commits_url()
 def __init__(self, driver, user):
     BasePage.__init__(self, driver)
     url_manager = UrlManager(user=user)
     self.page_url = url_manager.user_settings_url()
 def __init__(self, driver, user, repo_slug):
     BasePage.__init__(self, driver)
     url_manager = UrlManager(user=user, repo_slug=repo_slug)
     self.page_url = url_manager.fork_repo_url()
 def __init__(self, driver, project_key, repo_slug):
     BasePage.__init__(self, driver)
     self.url_manager = UrlManager(project_key=project_key,
                                   repo_slug=repo_slug)
     self.page_url = self.url_manager.repo_branches()