14

Tôi đang cố gắng làm theo ý tưởng được đề xuất trong bài nói chuyện hội nghị tự động hóa thử nghiệm của google và ChromeDriver "Performance Log" documentation page để lấy dữ liệu theo dõi mà tôi muốn gửi tới webpagetest để phân tích hiệu suất sau này.Nhận nhật ký hiệu suất chrome và truy tìm

Làm cách nào tôi có thể truy xuất nhật ký hiệu suất bằng cách sử dụng binden selenium python?


Tôi đã cố gắng để in ra log_types sẵn trong trường hợp lái xe

from selenium import webdriver 

driver = webdriver.Chrome() 
driver.get('https://stackoverflow.com') 

print driver.log_types 

driver.close() 

nhưng chỉ

[u'browser', u'driver'] 

Và tôi không thấy có liên quan command-line switch.

Trả lời

17

Nhật ký hiệu suất là bị tắt theo mặc định.

Để kích hoạt nó, sử dụng và cấu hình DesiredCapabilitiesloggingPrefs:

from selenium import webdriver 
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 

caps = DesiredCapabilities.CHROME 
caps['loggingPrefs'] = {'performance': 'ALL'} 
driver = webdriver.Chrome(desired_capabilities=caps) 

driver.get('https://stackoverflow.com') 

for entry in driver.get_log('performance'): 
    print entry 

driver.close() 

Điều này dẫn vào một loạt các truy tìm mục log in trên giao diện điều khiển:

{u'timestamp': 1419487459178, u'message': u'{"message":{"method":"Network.responseReceived","params":{"frameId":"2105.1","loaderId":"2105.2","requestId":"2105.1","response":{"connectionId":0,"connectionReused":false,"encodedDataLength":-1,"fromDiskCache":false,"fromServiceWorker":false,"headers":{"Access-Control-Allow-Origin":"*","Content-Type":"text/plain;charset=US-ASCII"},"mimeType":"text/plain","status":200,"statusText":"OK","url":"data:,"},"timestamp":1419487458.92934,"type":"Document"}},"webview":"2C66E956-A48B-456B-8A4E-1022F699AA92"}', u'level': u'INFO'} 
{u'timestamp': 1419487459178, u'message': u'{"message":{"method":"Network.loadingFinished","params":{"encodedDataLength":0,"requestId":"2105.1","timestamp":1419487458.92936}},"webview":"2C66E956-A48B-456B-8A4E-1022F699AA92"}', u'level': u'INFO'} 
{u'timestamp': 1419487459178, u'message': u'{"message":{"method":"Page.frameNavigated","params":{"frame":{"id":"2105.1","loaderId":"2105.2","mimeType":"text/plain","securityOrigin":"://","url":"data:,"}}},"webview":"2C66E956-A48B-456B-8A4E-1022F699AA92"}', u'level': u'INFO'} 
... 
Các vấn đề liên quan