Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Selenium roles (standalone, hub, node) #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ selenium_install_chrome: yes
selenium_display_id: "1"
selenium_port: 4444
selenium_xvfb_args: "--server-args='-screen 0, 1920x1080x24'"
selenium_role: "standalone"
selenium_hub:
6 changes: 6 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
# handlers file for selenium
- name: restart selenium
service: name=selenium state=restarted

- name: reload unit
service:
name: selenium
state: restarted
daemon_reload: yes
20 changes: 11 additions & 9 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
package: name=unzip
tags: [configuration, selenium]

- name: Add the user selenium
user:
name: selenium
comment: Selenium User
system: yes

- name: create directory
file: "path={{ selenium_install_dir }}/selenium state=directory recurse=yes"
tags: [configuration, selenium, selenium-create-directory]
Expand Down Expand Up @@ -47,7 +53,7 @@

- name: Install Chrome (if configured, RedHat)
yum:
name: https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
name: google-chrome-stable-75.0.3770.100-1
state: present
when: ansible_os_family == 'RedHat' and selenium_install_chrome
tags: [configuration, selenium, selenium-chrome]
Expand All @@ -62,7 +68,7 @@

- name: Install chromedriver
unarchive:
src: "https://chromedriver.storage.googleapis.com/{{ chromedriver_latest.content | trim }}/chromedriver_linux64.zip"
src: "https://chromedriver.storage.googleapis.com/75.0.3770.90/chromedriver_linux64.zip"
dest: /usr/bin
mode: 0755
copy: no
Expand Down Expand Up @@ -92,15 +98,11 @@
mode: 0755
when: "ansible_service_mgr == 'systemd'"
tags: [configuration, selenium, selenium-install]
notify: reload unit

- name: Register systemd service status (for systemd systems)
shell: 'systemctl status selenium | grep "active (running)"'
when: "ansible_service_mgr == 'systemd'"
register: selenium_running
ignore_errors: yes
changed_when: false
- name: force all notified handlers to run
meta: flush_handlers

- name: Ensure selenium is running
service: name=selenium state=started enabled=yes
tags: [configuration, selenium, selenium-run]
when: selenium_running.failed is defined and selenium_running.failed == true
11 changes: 10 additions & 1 deletion templates/selenium-unit.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ Description=selenium test framework
After=syslog.target network.target

[Service]
ExecStart=/usr/bin/xvfb-run {{ selenium_xvfb_args }} /usr/bin/java -client -jar {{ selenium_install_dir }}/selenium/selenium-server-standalone-{{ selenium_version }}.jar
Environment=DISPLAY={{selenium_display_id}}
PassEnvironment=DISPLAY
User=selenium
{% if selenium_role == "hub" %}
ExecStart=/usr/bin/java -client -jar {{ selenium_install_dir }}/selenium/selenium-server-standalone-{{ selenium_version }}.jar -port {{ selenium_port }} -role hub
{% elif selenium_role == "node" %}
ExecStart=/bin/bash -c "/usr/bin/xvfb-run {{selenium_xvfb_args}} /usr/bin/java -client -jar {{ selenium_install_dir }}/selenium/selenium-server-standalone-{{ selenium_version }}.jar -port {{ selenium_port }} -role node -hub {{selenium_hub}}"
{% else %}
ExecStart=/bin/bash -c "/usr/bin/xvfb-run {{selenium_xvfb_args}} /usr/bin/java -client -jar {{ selenium_install_dir }}/selenium/selenium-server-standalone-{{ selenium_version }}.jar -port {{ selenium_port }}"
{% endif %}
Restart=on-failure
RestartSec=20s

Expand Down