예제 #1
0
 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, auto_close=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)
예제 #2
0
    async def setUp(self):
        self.browser = API_Browser()
        #await self.browser.browser_connect(None, False)
        self.url = 'http://localhost:1313/visjs/just-visjs/'
        #self.url = 'http://visjs.org/examples/network/basicUsage.html'

        if self.url != await self.browser.url():
            await self.browser.open(self.url)
예제 #3
0
 def __init__(self, headless=True):
     self.web_page = '/vis-js/simple.html'
     self.web_root = Files.path_combine(Files.parent_folder(__file__),
                                        '../web_root')
     self.api_browser = API_Browser(
         headless=headless, auto_close=headless).sync__setup_browser()
     self.render_page = Render_Page(api_browser=self.api_browser,
                                    web_root=self.web_root)
예제 #4
0
 def setup(self):
     login_details = json.loads(Secrets(self.aws_secrets_id).value())
     self.username = login_details.get('username')
     self.password = login_details.get('password')
     self.server_url = login_details.get('server_url')
     if self._browser is None:
         self._browser = API_Browser(
             headless=self.headless,
             auto_close=self.auto_close).sync__setup_browser()
     return self._browser
 def __init__(self):
     self.web_page = '/google_charts/simple.html'
     self.web_root = Files.path_combine(Files.parent_folder(__file__),
                                        '../web_root')
     self.api_browser = API_Browser().sync__setup_browser()
     self.render_page = Render_Page(api_browser=self.api_browser,
                                    web_root=self.web_root)
     self.table_width = '100%'
     self.columns_defs = None
     self.table_title = None
예제 #6
0
 def __init__(self):
     self.web_page = '/gs/risk/risks-dashboard.html'
     self.web_root = Files.path_combine(Files.parent_folder(__file__),
                                        '../web_root')
     self.headless = False
     self.api_browser = API_Browser(self.headless,
                                    self.headless).sync__setup_browser()
     self.render_page = Render_Page(api_browser=self.api_browser,
                                    web_root=self.web_root)
     self.graph_name = None
     self.jira_key = None
예제 #7
0
 def __init__(self,
              api_browser=None,
              headless=True,
              auto_close=True,
              web_root=None,
              web_server=None):
     if web_server:
         self.web_server = web_server
     else:
         self.web_server = Web_Server(web_root)
     if api_browser:
         self.api_browser = api_browser
     else:
         self.api_browser = API_Browser(headless, auto_close)
    def setup(self):

        if os.getenv('AWS_REGION'):
            load_dependency('syncer')
            load_dependency('requests')
            #self.setup_AWS()
        # else:
        #     self.setup_local()

        from browser.API_Browser import API_Browser
        from browser.Render_Page import Render_Page
        self.api_browser = API_Browser(
            headless=self.headless,
            auto_close=self.auto_close).sync__setup_browser()
        self.render_page = Render_Page(api_browser=self.api_browser,
                                       web_root=self.web_root())

        return self
예제 #9
0
 def setUp(self):
     self.api = API_Browser(headless=False, auto_close=False)
예제 #10
0
class Test_API_Browser(TestCase):
    def setUp(self):
        self.api = API_Browser(headless=False, auto_close=False)

    @sync
    async def test_browser_connect(self):
        browser = await self.api.browser_connect()
        assert WS_is_open(browser.wsEndpoint)

    def test_get_set_last_chrome_session(self):
        self.api.file_tmp_last_chrome_session = Files.temp_file()
        data = {
            'chrome_devtools':
            'ws://127.0.0.1:64979/devtools/browser/75fbaab9-33eb-41ee-afd9-4aed65166791'
        }
        self.api.set_last_chrome_session(data)
        assert self.api.get_last_chrome_session() == data
        Files.delete(self.api.file_tmp_last_chrome_session)

    @sync
    async def test_js_eval(self):
        markdown = """
# some title "with double quotes"
some text  and 'single quotes'
"""
        encoded_text = base64.b64encode(markdown.encode()).decode()
        js_script = "convert(atob('{0}'))".format(encoded_text)

        result = await self.api.js_eval(js_script)
        Dev.pprint(result)

    @sync
    async def test_invoke_js_function(self):
        markdown = """
# changed title "via js function"
some text  and 'single quotes'
"""
        result = await self.api.js_invoke_function('convert', markdown)
        Dev.pprint(result)

    @sync
    async def test_html(self):
        await self.api.open('https://www.google.com')
        content = await self.api.html()
        assert len(content.html()) > 100

    @sync
    async def test_open(self):
        (headers, status, url,
         browser) = await self.api.open('https://www.google.com')
        assert headers['x-frame-options'] == 'SAMEORIGIN'
        assert status == 200
        assert url == 'https://www.google.com/'

    @sync
    async def test_page(self):
        page = await self.api.page()
        assert "http" in page.url

    @sync
    async def test_screenshot(self):
        await self.api.open('https://news.bbc.co.uk')
        file = await self.api.screenshot()
        assert Files.exists(file)
예제 #11
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, auto_close=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):
        self.browser().sync__browser_width(value)
        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 = {'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):
        png_file = self.create_dashboard_screenshot()
        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 = 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)
예제 #12
0
 def __init__(self):
     self.browser = API_Browser()