Sign inSign up

parasoft/selenic

By parasoft

Updated 6 months ago

Parasoft Selenic

Image
0

3.8K

parasoft/selenic repository overview

Quick reference

What is Parasoft Selenic?

Parasoft Selenic reduces the complexity associated with Selenium test creation and maintenance. Selenic analyzes Selenium tests at runtime and if a failure is detected due to a bad locator or wait condition, Selenic will repair the locator so that the test can proceed. Selenic will also recommend new locators that the tester can use to fix the test. Selenic recommendations can be loaded directly into the IDE so that developers can readily update their code. Selenic also ships with the Parasoft Recorder, which is an extension for the Chrome browser that enables you to record UI actions and generate pure Selenium tests that leverage the Page Object Model for increased maintainability.

What is included in this image

This image is based on Red Hat UBI Linux and includes:

  • Selenic (installed into /opt/parasoft/selenic). Parasoft Recorder and IDE integration are not included.
  • OpenJDK 21

How to use this image

Licensing
  • You must accept the Parasoft End User License Agreement (EULA) to use this product. Change ACCEPT_EULA from false to true in the examples below.
  • Be sure Parasoft License Server or Parasoft DTP is deployed in your organization.

To license Selenic, either provide license server information using the environment variables below, or mount a modified selenic.properties at /opt/parasoft/selenic/selenic.properties. Alternatively, for the selenic_analyzer.jar you may specify the path to the selenic.properties file using the -settings command-line argument.

Environment Variables
  • ACCEPT_EULA accepts the End User License Agreement if set to 'true'
  • LICENSE_SERVER_URL configures Selenic to connect to license server at the specified base URL
  • LICENSE_SERVER_AUTH_ENABLED configures Selenic to use basic authentication when connecting to license server
  • LICENSE_SERVER_USERNAME configures Selenic to connect to license server as the specified user
  • LICENSE_SERVER_PASSWORD configures Selenic to connect to license server with the specified password
Basic commands

The following command will run the Selenic Analyzer. It also does the following:

  • Provides a license server URL to license Selenic
  • Mounts a directory from the host to store reports from the Selenic Analyzer
  • Mounts a directory from the host that contains the recorded data for the Selenic Analyzer to process
  • Specifies the directory to output the report
docker run \
-e ACCEPT_EULA=false \
-e LICENSE_SERVER_URL=http://my.example.com/licenseserver \
-v ${HOME}/report:/home/parasoft/report \
-v ${HOME}/parasoft/recorded_data:/home/parasoft/parasoft/recorded_data \
-it --rm \
parasoft/selenic \
java -jar selenic_analyzer.jar -report /home/parasoft/report/

The following example will run the Selenic Analyzer on JUnit tests. It also does the following:

  • Provides a license server URL to license Selenic
  • Mounts a directory from the host that contains the recorded data for the Selenic Analyzer to process
  • Mounts a directory that contains the junit.jar and other project dependencies in order to run JUnit tests
  • Runs Java with the selenic_agent.jar configured to capture DOM information
  • Specifies the location to dependencies. Note that additional dependencies may need to be included for tests to run
docker run \
-e ACCEPT_EULA=false \
-e LICENSE_SERVER_URL=http://my.example.com/licenseserver \
-v ${HOME}/path/to/host/project:/home/parasoft/myproject \
-v ${HOME}/parasoft/recorded_data:/home/parasoft/parasoft/recorded_data \
-it --rm \
parasoft/selenic \
java -javaagent:/opt/parasoft/selenic/selenic_agent.jar=captureDom=true \
-cp /home/parasoft/myproject/lib/*:/home/parasoft/myproject/path/to/folder/containing/test/classes \
org.junit.platform.console.ConsoleLauncher --select-class com.mypackage.MyTestClass

Note To run browser tests within the docker image you will need to create a custom docker image. See the section on how to install Google Chrome for browser playback.

Alternatively, you can copy out the /opt/parasoft/selenic folder from the docker image and run commands on the host machine.

docker run \
--rm \
-v "${HOME}/destination:/home/parasoft/destination" \
-e ACCEPT_EULA=false \
parasoft/selenic \
cp -R /opt/parasoft/selenic /home/parasoft/destination/.

Image customization

You can customize the Parasoft Selenic image.

This image runs with a pre-defined parasoft user. The user ID and group ID of the parasoft user may not match the user ID and group ID of the user on the host that is attempting to run this image as this can cause problems when mounting directories from the host. Files owned by the user on the host might not be accessible to the parasoft user and vice versa. In particular, the parasoft user may need to read Selenic projects from the host's file system. Similarly, the parasoft user may need to write Selenic report files back to the host's file system. To solve this problem, the user ID and group ID of the parasoft user can be modified to match the user on the host by building a custom image as follows:

FROM parasoft/selenic

# default values, which can be overriden with --build-arg option
ARG HOST_UID=1000
ARG HOST_GID=1000

USER root:root

RUN rm -f /var/log/lastlog /var/log/faillog && \
    ln -s /dev/null /var/log/lastlog && \
    ln -s /dev/null /var/log/faillog && \
    groupmod -g ${HOST_GID} parasoft && \
    usermod -u ${HOST_UID} -g ${HOST_GID} parasoft && \
    chown -h -R ${HOST_UID}:${HOST_GID} /opt/local/parasoft && \
    touch /var/log/lastlog && \
    touch /var/log/faillog

USER parasoft:parasoft

Note: lastlog and faillog are "sparse files" that can be very large in total size. Certain commands like usermod touch those files. They are temporarily linked to /dev/null to prevent them from bloating the image.

Docker build command:

docker build --no-cache --tag selenic-$(id -un) --build-arg HOST_UID=$(id -u) --build-arg HOST_GID=$(id -g) .

The following example shows a Dockerfile for building a Selenic image with Gradle:

FROM parasoft/selenic

ARG GRADLE_VERSION=9.2.1
ENV GRADLE_HOME=/opt/gradle

USER root:root

RUN curl -L -o /tmp/gradle.zip https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip && \
    mkdir -p ${GRADLE_HOME} && \
    unzip -q /tmp/gradle.zip -d /opt && \
    mv /opt/gradle-${GRADLE_VERSION}/* ${GRADLE_HOME} && \
    rm -rf /opt/gradle-${GRADLE_VERSION} /tmp/gradle.zip

USER parasoft:parasoft

ENV PATH=${GRADLE_HOME}/bin:${PATH}

The following example shows a Dockerfile for building a Selenic image with Maven:

FROM parasoft/selenic

USER root:root

ARG USER_HOME_DIR=/home/parasoft
ARG MAVEN_VERSION=3.9.11
ENV MAVEN_HOME=${USER_HOME_DIR}/apache-maven-${MAVEN_VERSION}
ARG BASE_URL=https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/

RUN mkdir -p ${MAVEN_HOME} && \
    curl -L -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz && \
    tar -xzf /tmp/apache-maven.tar.gz -C ${MAVEN_HOME} --strip-components=1 && \
    rm -f /tmp/apache-maven.tar.gz && \
    ln -s ${MAVEN_HOME}/bin/mvn /usr/bin/mvn

ENV PATH="${MAVEN_HOME}/bin:${PATH}"

USER parasoft:parasoft

ENV MAVEN_CONFIG="${USER_HOME_DIR}/.m2"

Consider mounting a host directory as the .m2 directory. This simplifies configuring the .m2/settings.xml file and allows maven dependencies to persist when starting and stopping Selenic docker containers. For example:

docker run \
-e ACCEPT_EULA=false \
-e LICENSE_SERVER_URL=http://my.example.com/licenseserver \
-v ${HOME}/path/to/mavenproject:/home/parasoft/mavenproject \
-v ${HOME}/.m2:/home/parasoft/.m2 \
-v ${HOME}/parasoft/recorded_data:/home/parasoft/parasoft/recorded_data \
-it --rm \
selenic-chrome \
mvn -f /home/parasoft/mavenproject/pom.xml test -DargLine=-javaagent:/opt/parasoft/selenic/selenic_agent.jar=captureDom=true,selfHealing=true

Install Google Chrome for browser playback

This image does not contain any web browsers. Google Chrome can be installed to support running Selenium tests in the container.

Dockerfile:

FROM parasoft/selenic

USER root:root

ARG USER_HOME_DIR=/home/parasoft

RUN rpm -ivh \
        https://mirror.stream.centos.org/10-stream/BaseOS/x86_64/os/Packages/centos-gpg-keys-10.0-12.el10.noarch.rpm \
        https://mirror.stream.centos.org/10-stream/BaseOS/x86_64/os/Packages/centos-stream-repos-10.0-12.el10.noarch.rpm && \
    dnf install -y --nodocs --repo baseos --repo appstream \
        liberation-fonts \
        xdg-utils && \
    rpm -evh \
        centos-stream-repos \
        centos-gpg-keys && \
    rpm --import https://dl.google.com/linux/linux_signing_key.pub && \
    dnf install -y --nodocs \
        https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm && \
    dnf clean all && \
    rm -rf /var/cache/dnf

USER parasoft:parasoft

Note: Selenic uses Red Hat UBI as its base image. Google Chrome requires a few extra dependencies that are not available in Red Hat UBI. The Dockerfile pulls in the missing dependencies from CentOS Stream.

Docker build command:

docker build --no-cache --tag selenic-chrome .

By default, Google Chrome crashes when run in a Docker container. To prevent this from happening, certain Chrome arguments must be enabled, including the argument to enable headless browser playback. When constructing a ChromeDriver, use a ChromeOptions with at least the following arguments defined:

ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-gpu");
driver = new ChromeDriver(options);

If modifying the JUnit tests is not feasible or ideal, you can also modify the docker environment to always include these arguments when running Google Chrome. Do this by modifying the custom docker container to launch a wrapper script when running Google Chrome:

google-chrome-wrapper.sh:

#!/usr/bin/env bash

set -e

exec /usr/bin/google-chrome-stable --headless --no-sandbox --disable-dev-shm-usage --disable-gpu "$@"

Dockerfile:

FROM parasoft/selenic

USER root:root

COPY --chmod=775 google-chrome-wrapper.sh /usr/bin/

ARG USER_HOME_DIR=/home/parasoft

RUN rpm -ivh \
        https://mirror.stream.centos.org/10-stream/BaseOS/x86_64/os/Packages/centos-gpg-keys-10.0-12.el10.noarch.rpm \
        https://mirror.stream.centos.org/10-stream/BaseOS/x86_64/os/Packages/centos-stream-repos-10.0-12.el10.noarch.rpm && \
    dnf install -y --nodocs --repo baseos --repo appstream \
        liberation-fonts \
        xdg-utils && \
    rpm -evh \
        centos-stream-repos \
        centos-gpg-keys && \
    rpm --import https://dl.google.com/linux/linux_signing_key.pub && \
    dnf install -y --nodocs \
        https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm && \
    update-alternatives --install /usr/bin/chrome chrome /usr/bin/google-chrome-wrapper.sh 100 && \
    update-alternatives --install /usr/bin/google-chrome google-chrome /usr/bin/google-chrome-wrapper.sh 100 && \
    update-alternatives --set google-chrome /usr/bin/google-chrome-wrapper.sh && \
    dnf clean all && \
    rm -rf /var/cache/dnf

USER parasoft:parasoft

License

You need to view and agree to the Parasoft End User License Agreement (EULA) for the software contained in this image.

As with all Docker images, these likely also contain other software which may be under other licenses. As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.

Tag summary

Content type

Image

Digest

sha256:73dcd9403

Size

1.6 GB

Last updated

6 months ago

docker pull parasoft/selenic