コード例 #1
0
def proxy():
    """Фикстура для конфигурирования прокси-сервера"""
    server = Server(
        "03_PageObject/browsermob-proxy-2.1.4/bin/browsermob-proxy")
    server.start()
    client = Client("localhost:8080")
    # print(client.port)
    client.new_har()
    return server, client
コード例 #2
0
class TestTwo(object):
    def setup_method(self, method):
        self.client = Client("http://localhost:8080")

        profile = selenium.webdriver.FirefoxProfile()
        profile.set_proxy(self.client.webdriver_proxy())

        self.driver = selenium.webdriver.Firefox(firefox_profile=profile)

    def teardown_method(self, method):
        self.driver.quit()
        self.client.close()

    @pytest.mark.pycon
    @pytest.mark.deep
    @pytest.mark.blacklist
    def test_one(self):
        self.client.blacklist("http://www\\.google-analytics\\.com/.*", 309)
        self.client.new_har()
        home = HomePage(self.driver).open().wait_until_loaded()
        har = self.client.har
        print(har)
コード例 #3
0
ファイル: test_proxy.py プロジェクト: SamVyazemsky/otus
from browsermobproxy import Server, Client
import pytest
import urllib.parse
from selenium import webdriver

server = Server(r"C:\Tools\browsermob-proxy-2.1.4\bin\browsermob-proxy")
server.start()
client = Client("localhost:8080")
client.port
# proxy = server.create_proxy()
client.new_har()


@pytest.fixture
def chrome_browser(request):

    chrome_options = webdriver.ChromeOptions()
    url = vurllib.parse.urlparse(client.proxy).path
    chrome_options.add_argument('--proxy-server=%s' % url)
    driver = webdriver.Chrome(chrome_options=chrome_options)
    request.addfinalizer(driver.quit)
    return driver


def test_proxy(chrome_browser):
    # print(chrome_browser)
    # driver = chrome_browser['driver']
    chrome_browser.get('https://otus.ru/')
    print(' ')
    print(client.har)
コード例 #4
0
ファイル: use_browsermobproxy.py プロジェクト: kn7072/kn7072
from browsermobproxy import Server, Client
server = Server(r"d:\Python\browsermob-proxy-2.0-beta-9-bin\browsermob-proxy-2.0-beta-9\bin\browsermob-proxy",{"port":9090})
server.start()
client = Client("localhost:9090")
client.port
client.new_har('google')
client.har
コード例 #5
0
from browsermobproxy import Server, Client

server = Server(
    r"C:\Program Files (x86)\browsermob-proxy-2.1.4\bin\browsermob-proxy", )
server.start()
client = Client("localhost:8080")
print(client.port)
print(server.port)
client.new_har('google')
print(client.har)
コード例 #6
0
ファイル: api.py プロジェクト: deepminimal/webpage_size
    def get(self, URL):
        try:
            proxy = Client('im-expservices1.gksm.local:8999')
            chromedriver = './chromedriver'
            os.environ['webdriver.chrome.driver'] = chromedriver
            url = urlparse.urlparse(proxy.proxy).path
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument('--no-sandbox')
            chrome_options.add_argument('--headless')
            chrome_options.add_argument('--disable-dev-shm-usage')
            chrome_options.add_argument('--proxy-server={0}'.format(url))
            driver = webdriver.Chrome(chromedriver,
                                      chrome_options=chrome_options)
            driver.set_window_size(1920, 1080)
            try:
                proxy.new_har(str(URL),
                              options={
                                  'captureHeaders': True,
                                  'captureContent': True,
                                  'captureBinaryContent': True
                              })
                driver.get(URL)
                proxy.wait_for_traffic_to_stop(100, 20000)
            except Exception, err:
                return 'GET ERROR: ' + str(err)
            S = lambda X: \
                driver.execute_script('return document.body.parentNode.scroll'
                     + X)
            driver.set_window_size(S('Width'), S('Height'))

            # har = proxy.har['log']['entries']
            # mimeType = []

            bodySize = []
            download_time = []
            counter = 0
            for entry in proxy.har['log']['entries']:
                counter += 1

                # mimeType.append(entry['response']['content']['mimeType'])

                bodySize.append(int(entry['response']['bodySize']))
                download_time.append(int(entry['time']))

    # example = defaultdict(dict)
    # keys = defaultdict(dict)
    # for i in range(1, len(mimeType)):
    #  for entries in range(1, len(har)):
    #    if (mimeType[i] == har[entries]['response']['content']['mimeType']):
    #      keys[mimeType[i]][entries] = {'bodySize': int(har[entries]['response']['bodySize']),'URL': str(har[entries]['request']['url'])}
    # example['result'] = keys

            driver.quit()
            startDownloadTime = \
                datetime.datetime.strptime(str(proxy.har['log'
                    ]['entries'][0]['startedDateTime']),
                    '%Y-%m-%dT%H:%M:%S.%fZ')
            LastStartDownloadTime = \
                datetime.datetime.strptime(str(proxy.har['log'
                    ]['entries'][counter - 1]['startedDateTime']),
                    '%Y-%m-%dT%H:%M:%S.%fZ')
            proxy.close()
            return {
                'bodySize':
                str(sum(bodySize)),
                'browser_download_time':
                str(sum(download_time)),
                'LastStartDownloadTime':
                str(LastStartDownloadTime),
                'startDownloadTime':
                str(startDownloadTime),
                'total_download_time':
                str((LastStartDownloadTime -
                     startDownloadTime).total_seconds()),
            }