Interacting with Selenium from Common Lisp


#+TITLE: Web Automation with CL & Selenium
#+AUTHOR: Jason S. Robinson
#+DATE: Sun Aug 28 01:16:50 AM EST 2022

* Introduction

Learning how to interact with Selenium from Common Lisp

** Prerequisites

1. Chrome or Firefox webdriver
2. Selenium Server (At the time of this file, v4.4.0)
3. CL-WEBDRIVER-CLIENT package (At this time, works with Selenium 4)

** Environment

[[][Selenium Easy Demos]] were used for the test website.
Initial testing was done on GNU Guix with ungoogled-chrome Clozure CL & GNU Clisp.
Found to work best with CCL.
Both the Selenium Server and Clisp were run in their own `guix shell` virtual

If interested in recreating the environments:

*** Start the Selenium Server:

In a virtual environment:
#+BEGIN_SRC shell
abduco -n wd-server guix shell openjdk -- java -jar ~/selenium/selenium-server-4.4.0.jar standalone --port 4444 --log ~/selenium/log

*** Start A Lisp

**** GNU Clisp

Also in its own virtual environment, or you can choose to run it locally:
#+BEGIN_SRC shell
$ abduco -c wd-client guix shell cl-cl+ssl cl-slynk clisp -- clisp

Then in the REPL:
#+BEGIN_SRC lisp
(require "asdf")

#+BEGIN_SRC lisp
(require "slynk")

#+BEGIN_SRC lisp
(slynk:create-server :port 4004 :dont-close t)

This step can be done before or after disconnecting from the session.
Load the Quicklisp package
#+BEGIN_SRC lisp
(load #P"~/quicklisp/setup.lisp")

Then disconnect from the abduco session with Ctrl+\ and use Emacs to interact with the
Clisp session.

Of course this can be done with any Lisp implementation of choice and the Lisp expressions
can be passed on startup without the need to manually enter the REPL.

**** Start Clozure CL

#+BEGIN_SRC shell
abduco -n wd-client guix shell cl-cl+ssl cl-slynk ccl -- ccl  -e '(require "slynk") \
-e '(require "slynk") \
-e '(slynk:create-server :port 4004 :dont-close t)' \
-e '(load #P"~/quicklisp/setup.lisp")'