Webdriver Generates Events Log .txt file, if Run Web driver with following parameters
Code: Select all
run, chromedriver.exe --version --log-path="%filelocation%"
Code: Select all
Chrome := new Rufaydium(,"--port=9515" chr(34) " " chr(34) "--log-path=" a_scriptdir "\Events.txt" chr(34) " " chr(34) "--log-level=ALL")
Some Event takes one line to log and some Event takes more than one line,
it is always more lines when an Event returns with JSON and it is there I am unable to get a complete event log.
Event logs look like
Spoiler
CLogTailer class is a good example of how a callback can be implemented for a specific Event.I tried mimic manual/fake Event logging to test CLogTailer but I am having file read only issue, I even tried multiple ahk processes
but with driver logging CLogTailer class works just for single line event
Code: Select all
SetBatchLines, -1
i := 0
eventfile := A_ScriptDir "\Event.txt"
CLogTailer := A_ScriptDir "\CLogTailer.ahk"
gosub, LoadFakeEvents
FileAppend,, % eventfile
while !FileExist(eventfile)
sleep, 100
FileAppend, % script1 , % CLogTailer
while !FileExist(CLogTailer)
sleep, 100
run, % CLogTailer ; doing this coz log file read only issue / may be multi threading issue
msgbox, This is CLogTailer class setup to read events`n`n press Esc key to appened/log webdrive events one by one`nso CLogTailer will react to event`n Press Ctl+Esc to exit
return
Escape::
++i
if i = 10
i = 1
event := event%i%
FileAppend, % event "`n", % eventfile
if ErrorLevel
{
Err := A_LastError
DllCall("Kernel32.dll\FormatMessage", "Int",0x1100, "Ptr",0, "Int",Err, "Int",0, "PtrP",hMem:=0, "Int",0, "Ptr",0)
ErrMsg := StrGet(hMem)
hMem := DllCall("Kernel32.dll\LocalFree", "Ptr",hMem, "Ptr")
msgbox, % ErrMsg
}
return
^Esc::
FileDelete, % CLogTailer
msgbox, Script will exit press OK
ExitApp
LoadFakeEvents:
script1 =
(
#Persistent
eventfile := A_ScriptDir "\Event.txt"
lt := new CLogTailer(eventfile, Func("NewLine"))
return
NewLine(text){
ToolTip `% "New line added `@ " A_TickCount ": " text
}
class CLogTailer {
__New(logfile, callback){
this.file := FileOpen(logfile, "r")
this.callback := callback
; Move seek to end of file
this.file.Seek(0, 2)
fn := this.WatchLog.Bind(this)
SetTimer, `% fn, 5000
}
WatchLog(){
Loop {
p := this.file.Tell()
l := this.file.Length
line := this.file.ReadLine(), "``r``n"
len := StrLen(line)
if (len){
RegExMatch(line, "[\r\n]+", matches)
if (line == matches)
continue
this.callback.Call(Trim(line, "``r``n"))
}
} until (p == l)
}
}
)
event1 =
(
[1653557731.088][INFO]: Starting ChromeDriver 101.0.4951.41 (93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951@{#904}) on port 9515
)
event2 =
(
[1653557731.088][INFO]: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
)
event3 =
(
[1653557731.462][INFO]: [5cf37ba6ec3b5404e810007ab4e713f4] COMMAND InitSession {
"capabilities": {
"alwaysMatch": {
"browserName": "chrome",
"goog:chromeOptions": {
"excludeSwitches": [ "enable-automation" ],
"w3c": true
},
"platformName": "windows"
},
"firstMatch": [ {
} ]
},
"desiredCapabilities": {
"browserName": "chrome"
}
}
)
event4 =
(
[1653557731.462][INFO]: Populating Preferences file: {
"alternate_error_pages": {
"enabled": false
},
"autofill": {
"enabled": false
},
"browser": {
"check_default_browser": false
},
"distribution": {
"import_bookmarks": false,
"import_history": false,
"import_search_engine": false,
"make_chrome_default_for_user": false,
"skip_first_run_ui": true
},
"dns_prefetching": {
"enabled": false
},
"profile": {
"content_settings": {
"pattern_pairs": {
"https://*,*": {
"media-stream": {
"audio": "Default",
"video": "Default"
}
}
}
},
"default_content_setting_values": {
"geolocation": 1
},
"default_content_settings": {
"geolocation": 1,
"mouselock": 1,
"notifications": 1,
"popups": 1,
"ppapi-broker": 1
},
"password_manager_enabled": false
},
"safebrowsing": {
"enabled": false
},
"search": {
"suggest_enabled": false
},
"translate": {
"enabled": false
}
}
)
event5 =
(
[1653557731.462][INFO]: Populating Local State file: {
"background_mode": {
"enabled": false
},
"ssl": {
"rev_checking": {
"enabled": false
}
}
}
)
event6 =
(
[1653557731.462][INFO]: Launching chrome: "C:\Program Files\Google\Chrome\Application\chrome.exe" --allow-pre-commit-input --disable-background-networking --disable-backgrounding-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-blink-features=ShadowDOMV0 --enable-logging --log-level=0 --no-first-run --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\arbab\AppData\Local\Temp\scoped_dir9512_77327778" data:,
)
event7 =
(
[1653557732.326][DEBUG]: DevTools HTTP Request: http://localhost:58034/json/version
)
event8 =
(
[1653557732.831][DEBUG]: DevTools HTTP Response: {
"Browser": "Chrome/101.0.4951.67",
"Protocol-Version": "1.3",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36",
"V8-Version": "10.1.124.12",
"WebKit-Version": "537.36 (@8888ee7a24e2c36661ddb9536c35b7d4852a3a98)",
"webSocketDebuggerUrl": "ws://localhost:58034/devtools/browser/ab86a2f8-a886-4475-a570-ad41c8130d12"
}
)
event9 =
(
[1653557732.831][DEBUG]: DevTools HTTP Request: http://localhost:58034/json/list
)
return