Exemple #1
0
class test_Browser_Page(TestCase):
    def setUp(self):
        self.headless = False
        self.new_page = True
        self.page = Browser_Page(headless=self.headless,
                                 new_page=self.new_page).setup()
        self.result = None
        self.png_data = None
        self.close_page = True

    def tearDown(self):
        if self.result:
            Dev.pprint(self.result)

        if self.png_data:
            png_file = '/tmp/tmp-jira-screenshot.png'
            with open(png_file, "wb") as fh:
                fh.write(base64.decodebytes(self.png_data.encode()))
            Dev.pprint("Png data with size {0} saved to {1}".format(
                len(self.png_data), png_file))

        if self.close_page:
            self.page.wait(2).close()

    def test_close(self):
        self.result = self.page.close()

    def test_open(self):
        self.result = self.page.open('https://www.google.com')

    def test_url(self):
        self.result = self.page.url()
 def setup(self):
     if self.secrets_id is None:
         raise Exception('in Web_Slack no slack team provided')
     self.page           = Browser_Page(headless = self.headless, new_page=self.new_page).setup()
     self.server_details = Secrets(self.secrets_id).value_from_json_string()
     self.server_url     = self.server_details.get('server')
     return self
Exemple #3
0
 def setUp(self):
     self.headless = False
     self.new_page = True
     self.page = Browser_Page(headless=self.headless,
                              new_page=self.new_page).setup()
     self.result = None
     self.png_data = None
     self.close_page = True
Exemple #4
0
    def setup(self):

        self.page = Browser_Page(headless=self.headless,
                                 new_page=self.new_page).setup()
        self.server_details = Secrets(self.secrets_id).value_from_json_string()
        self.server_url = self.server_details.get('server')

        self.page.on_dialog__always_accept()
        #self.page.on_request__block_these(['glasswall.atlassian.net','jeditor','tinymce'])
        return self
Exemple #5
0
    def test_home_page(self):
        js_code = """$('.inner_main_schedule').height(130);
                    $('.center_heading').height(-50)"""

        url = 'https://opensecsummit.org/schedule/day/mon/'
        from osbot_browser.browser.Browser_Page import Browser_Page
        page = Browser_Page(headless=True, new_page=True).setup()
        page.open(url)
        page.javascript_eval(js_code)
class Site_Base:
    def __init__(self, headless=True):
        self._browser = None
        self._browser_helper = None
        self.server_details = None
        self.login_details = None
        self.server_url = None
        self.secrets_id = 'gw-bot-aws-console'
        self.headless = headless
        self.new_page = headless
        self.page: Browser_Page = None

    def setup(self):
        self.page = Browser_Page(headless=self.headless,
                                 new_page=self.new_page).setup()
        return self

    def js_invoke(self, js_code):
        return self.page.javascript_eval(js_code)

    def open(self, path=None):
        if path is None:
            path = ''
        url = "{0}{1}".format(self.server_url, path)

        return self.page.open(url)

    def wait(self, seconds):
        self.page.wait(seconds)
        return self

    def screenshot(self, width=None):
        if width:
            self.page.width(width)
        return self.page.screenshot()

    def set_browser_size(self, width, height):
        self.page.width(width, height)
        return self
Exemple #7
0
class Web_Jira:
    def __init__(self, headless=True, new_page=False):
        self._browser = None
        self._browser_helper = None
        self.server_details = None
        self.server_url = None
        self.secrets_id = 'gw-bot-jira-web'
        self.headless = headless
        self.new_page = new_page
        self.page: Browser_Page = None

    def setup(self):

        self.page = Browser_Page(headless=self.headless,
                                 new_page=self.new_page).setup()
        self.server_details = Secrets(self.secrets_id).value_from_json_string()
        self.server_url = self.server_details.get('server')

        self.page.on_dialog__always_accept()
        #self.page.on_request__block_these(['glasswall.atlassian.net','jeditor','tinymce'])
        return self

    # def browser(self):
    #     if self._browser is None:
    #         self._browser_helper = Browser_Lamdba_Helper(headless=self.headless).setup()
    #         self._browser        = self._browser_helper.api_browser
    #     return self._browser

    # async def login_async(self):
    #     (server, username, password) = self.server_details().values()
    #     await self.open(server + '/login.jsp')
    #     page = await self.browser().page()
    #     #await page.type('#login-form-username', username)
    #     #await page.type('#login-form-password', password)
    #     #await page.click('#login-form-submit')

    def issue(self, issue_id):
        #(server, username, password) = self.server_details().values()
        path = '/browse/{0}'.format(issue_id)
        self.open(path)

        #self.browser().sync__await_for_element('.jira-help-tip')
        #self.browser().sync__js_execute("$('.jira-help-tip').hide()")

        #self.page.click('#show-more-links-link')
        #self.page.javascript_eval("$('#show-more-links-link').click()")

        return self

    def login(self):
        path = '/login.jsp?os_destination=/rest/helptips/1.0/tips'

        self.open(path)
        page_text = self.page.text()

        if "Log in to your account" in page_text:
            username = self.server_details.get('username')
            password = self.server_details.get('password')
            self.page.javascript_eval(
                f"document.forms[0].username.value='{username}'")
            self.page.click('#login-submit')

            self.page.wait_for_element__id__is_equal_to(
                'login-submit', "Log in")
            self.page.javascript_eval(
                f"document.forms[0].password.value='{password}'")
            self.page.click('#login-submit')

            self.page.wait_for_navigation(
            )  # first redirection to page that says 'Please wait...'
            self.page.wait_for_navigation(
            )  # final redirection to page that shows []

            #return self.page.wait_for_element__id()
            #from time import sleep
            #sleep(2)
            #self.page.click('#login-submit')

            #self.page.wait_for_navigation()
            #sleep(4)

            #self.page.wait_for_element__id('password')
            #self.page.type('#password', self.server_details.get('password'))

            #self.page.javascript_eval('document.forms[0].submit()')

    def logout(self):
        #self.page.browser.sync__open('https://www.google.com')
        self.open('/logout')
        if self.page.exists('#logout-submit'):
            self.page.click('#logout-submit')
            self.page.wait_for_navigation()
        return self

    def open(self, path):
        url = "{0}{1}".format(self.server_url, path)
        return self.page.open(url)

    def screenshot(self, width=None, height=None):
        if width:
            self.page.width(width, height)
        return self.page.screenshot()

    def fix_set_list_view(self):
        self.open('/issues/?filter=-1')
        self.page.javascript_eval("$('.aui-list-item-link').eq(1).click()")
        return self

    def fix_issue_remove_ui_elements(self):
        # js_code =   """
        #                 $('.command-bar'            ).hide();
        #                 $('#header'                 ).hide();
        #                 $('.aui-sidebar'            ).hide()
        #                 $('#viewissuesidebar'       ).hide();
        #                 $('#attachmentmodule'       ).hide();
        #                 $('#addcomment'             ).hide();
        #                 $('#footer'                 ).hide();
        #                 $('.aui-page-header-actions').hide();
        #
        #                 $('#resolution-val'  )      .parent().hide();
        #                 $('#priority-val'    )      .parent().hide();
        #                 $('.remote-link'     ).eq(0).parent().hide();
        #             """
        js_code = """   
                        contains = function (selector, text)   {   var elements = document.querySelectorAll(selector);
                                                                   return [].filter.call(elements, function(element){
                                                                      return RegExp(text).test(element.textContent); });}
                        remove = function(selector,text,index) {
                                                                   target = contains(selector,text)[index]
                                                                   if (target) {target.remove()} }

                        remove('div' , 'updating the issue view', 11)
                        remove('span','Activity' ,0)                            
                        document.querySelector('[data-testid="Navigation"]').remove()
                        document.querySelector('#jira-issue-header').children[0].children[0].children[0].children[0].children[0].children[1].remove()

                        //external share
                        contains('div', 'External Share').pop().parentElement.parentElement.parentElement.remove()
                        """
        self.page.javascript_eval(js_code)
        return self
Exemple #8
0
class Web_Slack:
    def __init__(self, team_id, headless=True, new_page=True):
        self._browser = None
        self._browser_helper = None
        self.server_details = None
        self.server_url = None
        self.team_id = team_id
        self.secrets_id = self.resolve_secret_id()
        self.headless = headless
        self.new_page = new_page
        self.page: Browser_Page = None

    def resolve_secret_id(self):
        if self.team_id == 'T7F3AUXGV': return 'gs_bot_slack_web'
        if self.team_id == 'TAULHPATC': return 'gs_bot_slack_web_oss'

    def setup(self):
        if self.secrets_id is None:
            raise Exception('in Web_Slack no slack team provided')
        self.page = Browser_Page(headless=self.headless,
                                 new_page=self.new_page).setup()
        self.server_details = Secrets(self.secrets_id).value_from_json_string()
        self.server_url = self.server_details.get('server')
        return self

    def channel(self, issue_id):
        raise Exception('to do')
        #return self

    def login(self, wait_for_load=False):
        path = '/'
        self.open(path)

        page_text = self.page.text()

        if "Sign in to" in page_text:
            email = self.server_details.get('email')
            password = self.server_details.get('password')
            js_code = """
                          $('#email').val('{0}');
                          $('#password').val('{1}');
                          $('#signin_btn').click();
            """.format(email, password)
            self.page.javascript_eval(js_code)
            if wait_for_load:
                self.page.wait_for_element__id('msg_input')
                self.page.wait_for_element__id('loading_welcome_msg',
                                               exists=False)

            # misc tests to find optimal elements to wait
            #for i in range(0,3):
            #self.page.wait_for_element__id        ('msg_input'                                         )
            #self.page.wait_for_element__id        ('msg_input'          , max_attempts=4,exists=False )
            #self.page.wait_for_element__id        ('loading_welcome_msg', max_attempts=4, exists=True)
            #self.page.wait_for_element__id        ('loading_welcome_msg', max_attempts=4, exists=False)
            #self.page.wait_for_element__class_name('c-message__body'     , max_attempts=4, exists=True)
            #self.page.wait_for_element__class_name('c-message__body'     , max_attempts=4, exists=False)
            #self.page.wait_for_element__tag_name  ('button'              , max_attempts=4, exists=True)
            #self.page.wait_for_element__tag_name  ('button'              , max_attempts=4, exists=False)

            #print('****')

    def logout(self):
        logout_link_path_1 = "$('.ts_icon_sign_out').parent().parent().find('a').attr('href')"
        logout_link_path_2 = "$('#team_menu_user').click(); $('#logout a').attr('href')"
        logout_link = self.page.javascript_eval(logout_link_path_1)
        if logout_link is None:
            logout_link = self.page.javascript_eval(logout_link_path_2)
        if logout_link and logout_link.startswith('https://slack.com/signout'):
            self.page.open(logout_link)
        else:
            print("didn't find logout link")
        return self

    def open(self, path=None):
        if path is None:
            path = ''
        url = "{0}{1}".format(self.server_url, path)

        page = self.page.open(url)
        self.page.wait_for_element__id('loading_welcome_msg', exists=False)
        return page

    def wait(self, seconds):
        self.page.wait(seconds)
        return self

    def screenshot(self, width=None):
        if width:
            self.page.width(width)
        return self.page.screenshot()

    def fix_set_list_view(self):
        self.open('/issues/?filter=-1')
        self.page.javascript_eval("$('.aui-list-item-link').eq(1).click()")
        return self

    def fix_ui_for_screenshot(self):
        js_code = """
                        $('.client_channels_list_container').hide();
        """
        self.page.javascript_eval(js_code)
        return self
 def setup(self):
     self.page = Browser_Page(headless=self.headless,
                              new_page=self.new_page).setup()
     return self
Exemple #10
0
class Web_Slack:
    def __init__(self, team_id, headless=True, new_page=True):
        self._browser               = None
        self._browser_helper        = None
        self.scroll_split           = 1500
        self.server_details         = None
        self.server_url             = None
        self.team_id                = team_id
        self.secrets_id             = self.resolve_secret_id()
        self.headless               = headless
        self.new_page               = new_page
        self.page : Browser_Page    = None


    def resolve_secret_id(self):
        if self.team_id == 'T7F3AUXGV' : return 'gs_bot_slack_web'
        if self.team_id == 'TAULHPATC' : return 'gs_bot_slack_web_oss'

    def setup(self):
        if self.secrets_id is None:
            raise Exception('in Web_Slack no slack team provided')
        self.page           = Browser_Page(headless = self.headless, new_page=self.new_page).setup()
        self.server_details = Secrets(self.secrets_id).value_from_json_string()
        self.server_url     = self.server_details.get('server')
        return self

    def js_invoke(self,js_code):
        return self.page.javascript_eval(js_code)

    def login(self,wait_for_load=False):
        path = '/'
        self.open(path)

        page_text = self.page.text()

        if "Sign in to" in page_text:
            email = self.server_details.get('email')
            password = self.server_details.get('password')
            js_code = """
                          $('#email').val('{0}');
                          $('#password').val('{1}');
                          $('#signin_btn').click();
            """.format(email,password)
            self.page.javascript_eval(js_code)
            if wait_for_load:
                self.page.wait_for_element__id('msg_input')
                self.page.wait_for_element__id('loading_welcome_msg', exists=False)


            # misc tests to find optimal elements to wait
            #for i in range(0,3):
                #self.page.wait_for_element__id        ('msg_input'                                         )
                #self.page.wait_for_element__id        ('msg_input'          , max_attempts=4,exists=False )
                #self.page.wait_for_element__id        ('loading_welcome_msg', max_attempts=4, exists=True)
                #self.page.wait_for_element__id        ('loading_welcome_msg', max_attempts=4, exists=False)
                #self.page.wait_for_element__class_name('c-message__body'     , max_attempts=4, exists=True)
                #self.page.wait_for_element__class_name('c-message__body'     , max_attempts=4, exists=False)
                #self.page.wait_for_element__tag_name  ('button'              , max_attempts=4, exists=True)
                #self.page.wait_for_element__tag_name  ('button'              , max_attempts=4, exists=False)

                #print('****')



    def logout(self):
        logout_link_path_1 = "$('.ts_icon_sign_out').parent().parent().find('a').attr('href')"
        logout_link_path_2 = "$('#team_menu_user').click(); $('#logout a').attr('href')"
        logout_link      = self.page.javascript_eval(logout_link_path_1)
        if logout_link is None:
            logout_link = self.page.javascript_eval(logout_link_path_2)
        if logout_link and logout_link.startswith('https://slack.com/signout'):
            self.page.open(logout_link)
        else:
            print("didn't find logout link")
        return self

    def open(self, path=None):
        if path is None:
            path = ''
        url = "{0}{1}".format(self.server_url, path)

        page = self.page.open(url)
        self.page.wait_for_element__id('loading_welcome_msg', exists=False)
        return page

    def wait(self,seconds):
        self.page.wait(seconds)
        return self

    def screenshot(self,width=None):
        if width:
            self.page.width(width)
        return self.page.screenshot()

    def set_browser_size(self,width, height):
        self.page.width(width, height)
        return self

    def fix_set_list_view(self):
        self.open('/issues/?filter=-1')
        self.page.javascript_eval("$('.aui-list-item-link').eq(1).click()")
        return self

    def fix_ui_for_screenshot(self):
        js_code = """
                        $('.client_channels_list_container').hide();
        """
        self.page.javascript_eval(js_code)
        return self

    def scroll_messages_by(self,value):
        value = Misc.to_int(value)
        if value:
            # split the scroll in chunks since it was not working as expected when the
            # scroll amount was bigger than the current browser page window height
            while value > 0:
                if value < self.scroll_split:
                    scroll_by = value
                else:
                    scroll_by = self.scroll_split
                value -= scroll_by
                js_code = """value = $('.c-scrollbar__hider').eq(1).scrollTop() - {0} ;
                             $('.c-scrollbar__hider').eq(1).scrollTop(value);""".format(scroll_by)
                self.js_invoke(js_code)
                self.wait(0.25)             # wait a little bit before sending the next scroll event (this needs a better solution)

        return self
Exemple #11
0
class Web_Jira:
    def __init__(self, headless=True, new_page=True):
        self._browser = None
        self._browser_helper = None
        self.server_details = None
        self.server_url = None
        self.secrets_id = 'GS_BOT_GS_JIRA'
        self.headless = headless
        self.new_page = new_page
        self.page: Browser_Page = None

    def setup(self):
        self.page = Browser_Page(headless=self.headless,
                                 new_page=self.new_page).setup()
        self.server_details = Secrets(self.secrets_id).value_from_json_string()
        self.server_url = self.server_details.get('server')

        self.page.on_dialog__always_accept()
        self.page.on_request__block_these(
            ['jira.photobox.com', 'jeditor', 'tinymce'])
        return self

    # def browser(self):
    #     if self._browser is None:
    #         self._browser_helper = Browser_Lamdba_Helper(headless=self.headless).setup()
    #         self._browser        = self._browser_helper.api_browser
    #     return self._browser

    # async def login_async(self):
    #     (server, username, password) = self.server_details().values()
    #     await self.open(server + '/login.jsp')
    #     page = await self.browser().page()
    #     #await page.type('#login-form-username', username)
    #     #await page.type('#login-form-password', password)
    #     #await page.click('#login-form-submit')

    def issue(self, issue_id):
        #(server, username, password) = self.server_details().values()
        path = '/browse/{0}?filter=-1'.format(issue_id)
        self.open(path)
        #self.browser().sync__await_for_element('.jira-help-tip')
        #self.browser().sync__js_execute("$('.jira-help-tip').hide()")

        #self.page.click('#show-more-links-link')
        self.page.javascript_eval("$('#show-more-links-link').click()")

        return self

    def login(self):
        path = '/login.jsp?os_destination=/rest/helptips/1.0/tips'
        self.open(path)
        page_text = self.page.text()

        if "Username" in page_text:
            self.page.type('#login-form-username',
                           self.server_details.get('username'))
            self.page.type('#login-form-password',
                           self.server_details.get('password'))
            self.page.javascript_eval('document.forms[1].submit()')
            self.page.wait_for_navigation()

    def logout(self):
        self.open('/logout')
        if self.page.exists('#confirm-logout-submit'):
            self.page.click('#confirm-logout-submit')
        return self

    def open(self, path):
        url = "{0}{1}".format(self.server_url, path)
        return self.page.open(url)

    def screenshot(self, width=None, height=None):
        if width:
            self.page.width(width, height)
        return self.page.screenshot()

    def fix_set_list_view(self):
        self.open('/issues/?filter=-1')
        self.page.javascript_eval("$('.aui-list-item-link').eq(1).click()")
        return self

    def fix_issue_remove_ui_elements(self):
        js_code = """
                        $('.command-bar'            ).hide();
                        $('#header'                 ).hide();
                        $('.aui-sidebar'            ).hide()
                        $('#viewissuesidebar'       ).hide();
                        $('#attachmentmodule'       ).hide();
                        $('#addcomment'             ).hide();                        
                        $('#footer'                 ).hide();
                        $('.aui-page-header-actions').hide();                        
                                             
                        $('#resolution-val'  )      .parent().hide();
                        $('#priority-val'    )      .parent().hide();
                        $('.remote-link'     ).eq(0).parent().hide();
                    """
        self.page.javascript_eval(js_code)
        return self