pyleniumio icon indicating copy to clipboard operation
pyleniumio copied to clipboard

Example Dockerfile with Pylenium

Open ElSnoMan opened this issue 4 years ago • 2 comments

Description

Like the name suggests, we need to create some Dockerfile documentation. Users have requested that we add documentation for "What does a Dockerfile look like for my repo that uses Pylenium?"

This will be helpful for Users looking to containerize their Test Automation Solution 😄

We could probably just add it to the TESTING or GUIDES section of the documentation found here:

https://elsnoman.gitbook.io/pylenium/

ElSnoMan avatar May 11 '20 16:05 ElSnoMan

I propose an example Dockerfile like this:

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND="teletype" \
    DEBIAN_FRONTEND=noninteractive \
    INITRD=no \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    PIP_NO_CACHE_DIR=1

RUN echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen && \
    apt-get -y update && \
    apt-get dist-upgrade -y --no-install-recommends -o Dpkg::Options::="--force-confold" && \
    apt-get -y install \
        language-pack-en \
        firefox-geckodriver tigervnc-standalone-server python3 python3-dev python3-pip && \
    locale-gen en_US && update-locale LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

ENV LANG="en_US.UTF-8" \
    LANGUAGE="en_US:en" \
    LC_ALL="en_US.UTF-8"

RUN pip3 install --upgrade pip setuptools wheel && \
    pip3 install --upgrade pyleniumio pyvirtualdisplay && \
    rm -rf /root/.cache

and an example script for running inside it:

#!/usr/bin/env python3

import contextlib
import logging

import pylenium.config  # `pip install pyleniumio`
import pylenium.driver
import pyvirtualdisplay


@contextlib.contextmanager
def manage_pylenium():
    manage_display = pyvirtualdisplay.Display(
        backend="xvnc",
        rfbport=5910,
        size=(1920, 1080),
        visible=False,
    )
    pylenium_cfg = pylenium.config.PyleniumConfig(
        driver=dict(
            browser="firefox",
        ),
        viewport=dict(width=1920, height=1080),
    )
    with manage_display:  # sets `os.environ["DISPLAY"]`
        pyle = pylenium.driver.Pylenium(pylenium_cfg)
        pyle.init_webdriver()
        yield pyle


def main() -> None:
    logging.basicConfig(level=logging.DEBUG)
    with manage_pylenium() as pyle:
        pyle.visit('https://example.com')
        page_html = pyle.webdriver.page_source
    print("Page size:", len(page_html))


if __name__ == '__main__':
    main()

HoverHell avatar Aug 19 '21 07:08 HoverHell

Here's mine:

FROM python:3.9.10-slim-bullseye

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /app

RUN apt-get update && apt-get upgrade -y && apt-get install -y gcc

COPY conf/pip.conf /etc/pip.conf
COPY requirements.txt .

RUN python -m pip install --upgrade pip
RUN python -m pip install -r requirements.txt
RUN adduser --disabled-password simpleuser
RUN chown simpleuser:simpleuser /app

COPY --chown=simpleuser:simpleuser . .
USER qauser

RUN mkdir test_artifacts

eformo avatar May 31 '22 06:05 eformo