This commit is contained in:
Mylloon 2023-05-13 12:37:12 +02:00
parent 4caaf7ee16
commit cebb5cb5b0
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 26 additions and 10 deletions

View file

@ -1,17 +1,15 @@
open Pusk.Utils
open Pusk
open Pusk.Net
open Pusk.Drivers
let main pid =
print_endline (fmt "Driver running as %d" pid);
let body = execute_request "http://localhost:4444/session" Json.connection_payload in
let main =
let session_id = get_session in
let body = close_session session_id in
print_endline body
;;
let () =
let driver = prepare (Gecko "0.33.0") in
let driver_process = run_process driver [] in
main (snd driver_process);
main;
stop_process driver_process
;;

View file

@ -50,10 +50,9 @@ let prepare = function
let archive = fmt "./gecko-%s.tar.gz" version_driver in
Lwt_main.run (download_gecko_driver version_driver archive);
(* TODO: Use native version instead of relying on Unix tools *)
let _ = Sys.command (fmt "tar xvzf %s" archive) in
let _ = Sys.command (fmt "mv geckodriver %s" driver) in
let _ = Sys.command (fmt "rm %s" archive) in
());
ignore (Sys.command (fmt "tar xvzf %s" archive));
ignore (Sys.command (fmt "mv geckodriver %s" driver));
ignore (Sys.command (fmt "rm %s" archive)));
driver
;;

View file

@ -1,4 +1,7 @@
open Cohttp_lwt_unix
open Utils
let url = "http://127.0.0.1:4444"
let send_post_request url json =
let uri = Uri.of_string url in
@ -8,7 +11,23 @@ let send_post_request url json =
Cohttp_lwt.Body.to_string body)
;;
let send_delete_request url =
let uri = Uri.of_string url in
Lwt.bind (Client.delete uri) (fun (_response, body) -> Cohttp_lwt.Body.to_string body)
;;
let execute_request url json =
let body = send_post_request url json in
Lwt_main.run body
;;
let get_session =
let body = execute_request (fmt "%s/session" url) Json.connection_payload in
print_endline body;
body
;;
(* match Yojson.Safe.from_string body with
| _ as e -> print_endline e *)
let close_session id = Lwt_main.run (send_delete_request (fmt "%s/session/%s" url id))