No description
Find a file
みゃみゅ玉子 df2f5d013b
indent miss (#35)
2022-02-01 02:02:53 +09:00
.devcontainer create macros (#34) 2022-02-01 01:58:22 +09:00
.github/workflows add source link on docs (#18) 2021-09-23 00:39:54 +09:00
examples create macros (#34) 2022-02-01 01:58:22 +09:00
src create macros (#34) 2022-02-01 01:58:22 +09:00
tests create macros (#34) 2022-02-01 01:58:22 +09:00
.gitignore write some tests and add test workflow (#8) 2021-09-18 22:52:31 +09:00
docker-compose.yaml change nim version to 1.2.0 (#33) 2021-10-02 01:05:22 +09:00
LICENSE Initial commit 2021-08-31 02:11:28 +09:00
README.adoc indent miss (#35) 2022-02-01 02:02:53 +09:00
selenimum.nimble create macros (#34) 2022-02-01 01:58:22 +09:00
selenium-by-curl.adoc add error case test for browse (#11) 2021-09-19 18:14:38 +09:00
vscode.docker-compose.yaml create macros (#34) 2022-02-01 01:58:22 +09:00
vscode.dockerfile create macros (#34) 2022-02-01 01:58:22 +09:00

:toc: left
:sectnums:

= Selenimum

Selenimum is inspired by https://github.com/dom96/webdriver[dom96/webdriver].

== About

WebDriver for Selenium(selenium-hub) by Nim.

== Usage

=== launch selenium hub

save docker-compose.yaml to your woriking directory. +
and up by docker-compose.

[source,yaml]
----
version: '3'

services:
  selenium-hub:
    image: selenium/hub:3.141.59-20210830
    container_name: selenium-hub
    ports:
    - 4444:4444
    environment:
    - GRID_MAX_SESSION=10

  firefox: &node
    image: selenium/node-firefox:3.141.59-20210830
    container_name: selenium-firefox
    shm_size: 2gb
    depends_on:
    - selenium-hub
    environment:
    - HUB_HOST=selenium-hub
    - HUB_PORT=4444
    - NODE_MAX_SESSION=5

  chrome:
    <<: *node
    image: selenium/node-chrome:3.141.59-20210830
    container_name: selenium-chrome
----

[source,sh]
----
docker-compose up -d --remove-orphans
----

=== control selenium example

[source,nim]
----
import selenimum, strformat

proc main() =
  let
    driver = newSeleniumWebDriver()
    session = driver.newSession()
  defer:
    session.deleteSession()

  try:
    # navigate to Yahoo!JAPAN
    session.navigateTo("https://www.yahoo.co.jp/")
    let title = session.getTitle()
    echo(&"page title:{title}")
    session.saveScreenshot("yahoo-japan.png")
    echo("screenshot saved.")
  except Exception as e:
    echo("ERROR!!", e.getStackTrace())

main()
----

if you want to use firefox.

[source,nim]
----
import selenimum, json

let
  capabilities = %*{
    "desiredCapabilities": {
      "browserName": "firefox"
    },
    "requiredCapabilities": {}
  }
  session = driver.newSession(capabilities=capabilities)
----

=== control selenium example by macro

[source,nim]
----
import selenimum, strformat

proc main() =
  selenium "http://selenium-hub:4444/wd/hub":
    chrome:
      # navigate to Yahoo!JAPAN
      navigateTo "https://www.yahoo.co.jp/" 
      let title = session.getTitle()
      echo(&"page title:{title}")
      session.saveScreenshot("yahoo-japan.png")
      echo("screenshot saved.")

try:
  main()
except Exception as e:
  echo("ERROR!!", e.getStackTrace())
----

if you want to use firefox.

[source,nim]
----
import selenimum, strformat

proc main() =
  selenium "http://selenium-hub:4444/wd/hub":
    firefox:
      # navigate to Yahoo!JAPAN
      navigateTo "https://www.yahoo.co.jp/" 
      let title = session.getTitle()
      echo(&"page title:{title}")
      session.saveScreenshot("yahoo-japan.png")
      echo("screenshot saved.")

try:
  main()
except Exception as e:
  echo("ERROR!!", e.getStackTrace())
----

== Docs

* Latest release version +
https://myamyu.github.io/selenimum/
* Development version +
https://myamyu.github.io/selenimum/develop/