• Stars
    star
    47
  • Rank 604,252 (Top 12 %)
  • Language
    Scala
  • License
    BSD 3-Clause "New...
  • Created almost 9 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Scala.js environment

scalajs-env-selenium

Scala.js

Usage

Simply add the following line to your project/plugins.sbt (note that this line must be placed before addSbtPlugin("org.scala-js" % "sbt-scalajs" % <scalajs-version>); otherwise you may get errors such as java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState when you run tests):

// For Scala.js 0.6.x
libraryDependencies += "org.scala-js" %% "scalajs-env-selenium" % "0.3.0"

// For Scala.js 1.x
libraryDependencies += "org.scala-js" %% "scalajs-env-selenium" % "1.1.1"

and the following line to your sbt settings:

// Apply to the 'run' command
jsEnv := new org.scalajs.jsenv.selenium.SeleniumJSEnv(capabilities)

// Apply to tests
jsEnv in Test := new org.scalajs.jsenv.selenium.SeleniumJSEnv(capabilities)

where capabilities is one of the members of org.openqa.selenium.remote.DesiredCapabilities.

For example for Firefox:

jsEnv := new org.scalajs.jsenv.selenium.SeleniumJSEnv(
    new org.openqa.selenium.firefox.FirefoxOptions())

You are responsible for installing the drivers needed for the browsers you request.

When executing the program with run a new browser window will be created, the code will be executed in it and finally the browser will close itself. All the console outputs will appear in SBT as usual. Executing test will open several browser windows and close them all before the end of the tests.

In browser debugging

If you wish to keep the browser window opened after the execution has terminated simply add the option withKeepAlive on the environment:

new SeleniumJSEnv(capabilities, SeleniumJSEnv.Config().withKeepAlive(true))

It is recommend to use this with a run and not test because the latter tends to leave too many browser windows open.

Debugging tests on a single window

By default tests are executed in their own window for parallelism. When debugging tests with withKeepAlive it is possible to disable this option using the sbt setting parallelExecution in Test := false.

Headless Usage

It is often desirable to run Selenium headlessly. This could be to run tests on a server without graphics, or to just prevent browser windows popping up when running locally.

xvfb

A common approach on Linux and Mac OSX, is to use xvfb, "X Virtual FrameBuffer". It starts an X server headlessly, without the need for a graphics driver.

Once you have xvfb installed, usage here with SBT is as simple as:

Xvfb :1 &
DISPLAY=:1 sbt

The :1 indicates the X display-number, which is a means to uniquely identify an X server on a host. The 1 is completely arbitraryโ€”you can choose any number so long as there isn't another X server running that's already associated with it.

License

scalajs-env-selenium is distributed under the BSD 3-Clause license.

Contributing

Follow the contributing guide.

More Repositories

1

scala-js

Scala.js, the Scala to JavaScript compiler
Scala
4,484
star
2

scala-js-dom

Statically typed DOM API for Scala.js
Scala
302
star
3

scala-js-website

Source for https://www.scala-js.org/
JavaScript
257
star
4

scala-js-java-time

Scala.js implementation for java.time in JDK8
Scala
87
star
5

scalajs-tutorial

Source code accompanying the Scala.js tutorial
Scala
66
star
6

scalajs-cross-compile-example

A small example project on how to cross compile Scala.js and Scala JVM
Scala
41
star
7

vite-plugin-scalajs

Vite plugin for integration of Scala.js
TypeScript
34
star
8

scala-js-macrotask-executor

Scala
33
star
9

vite.g8

Template for Scala.js with Vite
Scala
18
star
10

jsdependencies

An sbt plugin to manage JS dependencies in Scala.js, in the good old script style
Scala
11
star
11

scala-js-java-logging

Scala.js implementation for java.logging
Scala
10
star
12

scala-js-stubs

Stubs to use Scala.js annotations in cross-platform codebases
Scala
9
star
13

scala-js-env-jsdom-nodejs

Node.js with jsdom environment for Scala.js
Scala
8
star
14

scala-js-java-securerandom

Implementation of java.security.SecureRandom for Scala.js in browsers and Node.js
Scala
6
star
15

scala-js-cli

Command Line Interface for the Scala.js compiler and linker
Scala
5
star
16

scala-js-test-scala-nightly

Builds Scala.js against the nightly builds of Scala
Shell
3
star
17

scala-js-weakreferences

Implementation of java.lang.ref.{WeakReference,ReferenceQueue} for Scala.js
Scala
3
star
18

scala-js-env-phantomjs

PhantomJS environment for Scala.js
Scala
2
star
19

scala-js-logging

Tiny logging API for use by the Scala.js linker and JS envs.
Scala
1
star