W3C Webdriver API, optimized for usage with fp-ts.
The goal is to be compatible with the W3C Recommendation
A webdriver sends requests and returns responses. We send a request to a driver (chromdriver, geckodriver), it opens up an instance of the browser and runs our requests in real time.
Please keep in mind that this is package is experiemental and not enough tests have been written.
# yarn
## peer dependencies
yarn add fp-ts fp-ts-std io-ts monocle-ts newtype-ts
yarn add fp-ts-webdriver
# npm
# peer dependencies
npm install fp-ts fp-ts-std io-ts monocle-ts newtype-ts
npm install fp-ts-webdriver
There are two types of dependencies: WebdriverDeps
and SessionDeps
.
SessionDeps
extends WebdriverDeps
with the sessionId
.
All commands that use this as the dependency require a session.
For this examples to function, you have to turn on your webdriver.
With chromedriver the command is chromedriver --port=4444
.
Checkout the tests on how to set this up automatically with jest.
import { webdriver as WD, readerReaderTaskEither as RRTE } from "fp-ts-webdriver"
import { pipe } from "fp-ts/lib/function"
import { readerTaskEither as RTE } from "fp-ts"
const searchBar = WD.findElement("css selector", "input[name=\"q\"]")
const searchButton = WD.findElement("css selector", "input[value=\"Google Search\"]")
// requires a session
const program = pipe(
WD.navigateTo("https://google.com.au"),
RTE.apSecond(searchBar),
RTE.chainFirst(WD.sendKeys("dogs")),
RTE.apSecond(searchButton)
RTE.chain(WD.elementClick)
)
const dependencies: WD.WebdriverDeps = {
url: "localhost:4444",
capabilities: { alwaysMatch: {} },
requestInit: {}
}
// creates a session and closes it after runnning `program`
const main = WD.bracketed(program)
main(dependencies)().catch(console.error)
Doing commands in an order that makes sense. If there's some you want, make a PR or ask! :)