Пример #1
0
class test_workflows_API_Browser(TestCase):
    def setUp(self):
        self.api = API_Browser(headless=False)
        self.png_file = '/tmp/tmp-jira-screenshot.png'

    def test_open_jira_slack(self):
        #url = 'https://os-summit.slack.com/messages/DJ8UA0RFT/'
        url = 'https://os-summit.slack.com/messages/CK475UCJY/'
        self.api.sync__open(url)
        email = '*****@*****.**'
        password = "******"
        js_code = """$('#email').val('{0}')
                     $('#password').val('{1}')
                     $('#signin_btn').click()
                  """.format(email, password)

        self.api.sync__js_execute(js_code)

        #await self.api.screenshot(file_screenshot=self.png_file)

    @sync
    async def test_open_jira_page(self):
        from osbot_aws.apis.Secrets import Secrets
        self.api = API_Browser(headless=False)

        login_needed = False
        self.secrets_id = 'GS_BOT_GS_JIRA'

        (server, username, password) = Secrets(
            self.secrets_id).value_from_json_string().values()

        if login_needed:
            Dev.pprint(server, username, password)
            await self.api.open(server + '/login.jsp')
            page = await self.api.page()
            await page.type('#login-form-username', username)
            await page.type('#login-form-password', password)
            await page.click('#login-form-submit')

        #await self.api.open(server + '/browse/GSP-95')
        #page = await self.api.page()
        #await self.api.js_execute("$('#show-more-links-link').click()")
        #from time import sleep
        #sleep(1)
        await self.api.page_size(2000, 3000)

        await self.api.screenshot(
            file_screenshot='/tmp/tmp-jira-screenshot.png', full_page=True)
Пример #2
0
class Base_View_Helpers:
    def __init__(self, web_page, headless=True):
        self.web_page = web_page
        self.title = 'browser view'
        self.web_root = Files.path_combine(Files.parent_folder(__file__),
                                           '../web_root')
        self.api_browser = API_Browser(headless=headless).sync__setup_browser()
        self.web_server = Web_Server(self.web_root)
        self.render_page = Render_Page(api_browser=self.api_browser,
                                       web_server=self.web_server)

    # common methods (move to base class)
    def browser(self):
        return self.api_browser

    def browser_width(self, value, height=None):
        self.browser().sync__browser_width(value, height)
        return self

    def load_page(self, reload=False):
        if reload or self.web_page not in self.browser().sync__url():
            self.render_page.open_file_in_browser(self.web_page)
        return self

    def create_dashboard_screenshot(self, clip=None):
        #clip = {'x': 1, 'y': 1, 'width': 945, 'height': 465}
        #clip = None
        return self.browser().sync__screenshot(clip=clip)

    def send_screenshot_to_slack(self, team_id=None, channel=None, clip=None):
        png_file = self.create_dashboard_screenshot(clip)
        return Browser_Lamdba_Helper().send_png_file_to_slack(
            team_id, channel, self.title, png_file)

    def get_graph_data(self, graph_name):
        params = {'params': ['raw_data', graph_name, 'details'], 'data': {}}
        data = Lambda('lambdas.gsbot.gsbot_graph').invoke(params)
        if type(data) is str:
            s3_key = data
            s3_bucket = 'gs-lambda-tests'
            tmp_file = S3().file_download_and_delete(s3_bucket, s3_key)
            data = Json.load_json_and_delete(tmp_file)
            return data
        return data

    def exec_js(self, js_code):
        return self.browser().sync__js_execute(js_code)

    def invoke_js(self, name, params):
        return self.browser().sync_js_invoke_function(name, params)

    def assign_variable_js(self, variable, data):
        return self.browser().sync_js_assign_variable(variable, data)

    def set_browser_width_based_on_nodes(self, nodes):
        if len(nodes) < 30: self.browser().sync__browser_width(800)
        elif len(nodes) < 100: self.browser().sync__browser_width(1500)
        elif len(nodes) < 200: self.browser().sync__browser_width(2000)
        else: self.browser().sync__browser_width(3000)

    def render(self,
               nodes,
               edges,
               js_code=None,
               options=None,
               team_id=None,
               channel=None,
               sleep_for=None,
               width=None):
        if len(nodes) > 0:

            if width:
                self.browser().sync__browser_width(width)
            else:
                self.set_browser_width_based_on_nodes(nodes)
                # if          len(nodes) < 50 :                                            sleep_for = 2
                # elif  50 <  len(nodes) < 100: self.browser().sync__browser_width(1000) ; sleep_for = 3
                # elif 100 <  len(nodes) < 200: self.browser().sync__browser_width(2000) ; sleep_for = 5
                # elif        len(nodes) > 200: self.browser().sync__browser_width(3000) ; sleep_for = 10

            self.create_graph(nodes, edges, options)
            self.api_browser.sync__js_execute(js_code)

            if sleep_for: sleep(sleep_for)

            return self.send_screenshot_to_slack(team_id, channel)