├── .editorconfig ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── Vagrantfile ├── ansible.cfg ├── library └── selenium ├── meta └── main.yml ├── tests ├── inventory ├── test-selenium-hub.yml ├── test-selenium-memory.yml ├── test-selenium-node.yml ├── test-selenium-standalone.yml └── test.yml └── vagrant-libs ├── bootstrap.centos.sh └── bootstrap.ubuntu.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_style = space 3 | indent_size = 2 4 | # We recommend you to keep these unchanged 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | 9 | [{*.py,selenium}] 10 | indent_style = space 11 | indent_size = 4 12 | 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/python,intellij 3 | 4 | ### Python ### 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | env/ 16 | build/ 17 | develop-eggs/ 18 | dist/ 19 | downloads/ 20 | eggs/ 21 | .eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *,cover 50 | .hypothesis/ 51 | 52 | # Translations 53 | *.mo 54 | *.pot 55 | 56 | # Django stuff: 57 | *.log 58 | 59 | # Sphinx documentation 60 | docs/_build/ 61 | 62 | # PyBuilder 63 | target/ 64 | 65 | 66 | ### Intellij ### 67 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 68 | 69 | *.iml 70 | 71 | ## Directory-based project format: 72 | .idea/ 73 | # if you remove the above rule, at least ignore the following: 74 | 75 | # User-specific stuff: 76 | # .idea/workspace.xml 77 | # .idea/tasks.xml 78 | # .idea/dictionaries 79 | # .idea/shelf 80 | 81 | # Sensitive or high-churn files: 82 | # .idea/dataSources.ids 83 | # .idea/dataSources.xml 84 | # .idea/sqlDataSources.xml 85 | # .idea/dynamic.xml 86 | # .idea/uiDesigner.xml 87 | 88 | # Gradle: 89 | # .idea/gradle.xml 90 | # .idea/libraries 91 | 92 | # Mongo Explorer plugin: 93 | # .idea/mongoSettings.xml 94 | 95 | ## File-based project format: 96 | *.ipr 97 | *.iws 98 | 99 | ## Plugin-specific files: 100 | 101 | # IntelliJ 102 | /out/ 103 | 104 | # mpeltonen/sbt-idea plugin 105 | .idea_modules/ 106 | 107 | # JIRA plugin 108 | atlassian-ide-plugin.xml 109 | 110 | # Crashlytics plugin (for Android Studio and IntelliJ) 111 | com_crashlytics_export_strings.xml 112 | crashlytics.properties 113 | crashlytics-build.properties 114 | fabric.properties 115 | 116 | 117 | # Created by https://www.gitignore.io/api/vagrant 118 | 119 | ### Vagrant ### 120 | .vagrant/ 121 | 122 | *.tar.gz 123 | 124 | *.jar 125 | *.retry 126 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | 5 | before_install: 6 | - sudo apt-get update -qq 7 | 8 | install: 9 | - pip install -I ansible==2.0.2.0 10 | 11 | script: 12 | - ansible-playbook -i tests/localhost, tests/test.yml --syntax-check 13 | - ansible-playbook -i tests/localhost, tests/test.yml --connection=local --sudo 14 | - ansible-playbook -i tests/localhost, tests/test.yml --connection=local --sudo # check for idempotency 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 0.3.0 2 | === 3 | * Fixed force argument (previously wasnt reading as boolean) 4 | * Added a call to setsid() to ensure sub-processes close 5 | 6 | 0.2.0 7 | === 8 | + Added 'standalone' role 9 | 10 | 0.1.0 11 | === 12 | + Initial Release 13 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Selenium module for Ansible 2 | === 3 | 4 | Get it! `ansible-galaxy install SeleniumHQ.selenium` 5 | [![star this repo](http://githubbadges.com/star.svg?user=seleniumhq&repo=ansible-selenium&style=default)](https://github.com/seleniumhq/ansible-selenium) 6 | [![fork this repo](http://githubbadges.com/fork.svg?user=seleniumhq&repo=ansible-selenium&style=default)](https://github.com/seleniumhq/ansible-selenium/fork) 7 | 8 | 9 | Use It 10 | === 11 | 12 | After using ansible galaxy to install the module, take the `library/selenium` file, and put it where relevant for your use. 13 | 14 | Include it in your playbook/roles: 15 | 16 | ```yaml 17 | - name: Start a standalone server 18 | selenium: 19 | role: standalone 20 | state: running 21 | 22 | - name: Start a standalone server (specific selenium version) 23 | selenium: 24 | version: 2.53.1 25 | role: standalone 26 | state: running 27 | 28 | - name: Start a basic grid that listens on port 4444 29 | selenium: 30 | role: hub 31 | state: running 32 | 33 | - name: Start a grid that runs on port 4445 34 | selenium: 35 | role: hub 36 | state: running 37 | args: 38 | port: 4445 39 | 40 | - name: Start the grid with greater memory 41 | selenium: 42 | role: hub 43 | state: running 44 | javaargs: 45 | - Xmx1024M 46 | - Xmy1024M 47 | 48 | - name: Start a basic node that connects locally 49 | selenium: 50 | role: node 51 | state: running 52 | args: 53 | hubUrl: http://0.0.0.0:4444 54 | 55 | - name: Restart a running node that was listening on a previous port 56 | selenium: 57 | role: node 58 | state: restarted 59 | args: 60 | hubUrl: http://0.0.0.0:4445 61 | 62 | - name: Start a node that uses a JSON config and has a logfile 63 | roles: 64 | - name: output the config file 65 | template: src=config.json.j2 dest=config.json 66 | 67 | - name: start the node 68 | selenium: 69 | role: node 70 | state: running 71 | logfile: node.log 72 | args: 73 | nodeConfig: config.json 74 | 75 | - name: Stop the running selenium standalone server 76 | selenium: 77 | state: stopped 78 | ``` 79 | 80 | 81 | Develop 82 | === 83 | 84 | *(The following instructions are for those using Vagrant)* 85 | 86 | Before running tests: 87 | 88 | ```sh 89 | alias test-module=/home/vagrant/ansible/hacking/test-module 90 | ``` 91 | 92 | To test the module manually, you can run: 93 | 94 | ```sh 95 | cd library/ 96 | test-module -m ./selenium -a "role=hub state=running" 97 | ``` 98 | 99 | To run all tests: 100 | 101 | ```sh 102 | cd tests/ 103 | ansible-playbook -i localhost, test.yml 104 | ``` 105 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANT_API_VERSION = '2' 5 | 6 | Vagrant.configure(VAGRANT_API_VERSION) do |config| 7 | config.vm.define "ubuntu" do |ubuntu| 8 | config.vm.box = 'ubuntu/trusty64' 9 | config.vm.provision :shell, path: 'vagrant-libs/bootstrap.ubuntu.sh' 10 | end 11 | 12 | config.vm.define "centos" do |centos| 13 | config.vm.box = 'geerlingguy/centos7' 14 | config.vm.provision :shell, path: 'vagrant-libs/bootstrap.centos.sh' 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | roles_path = ../ 3 | -------------------------------------------------------------------------------- /library/selenium: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright 2015 Daniel Davison and Software Freedom Conservancy 5 | # 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # selenium: Ansible module for Selenium 19 | 20 | ANSIBLE_METADATA = {'metadata_version': '1.1', 21 | 'status': ['stableinterface'], 22 | 'supported_by': 'community'} 23 | 24 | DOCUMENTATION = ''' 25 | --- 26 | module: selenium 27 | short_description: Selenium Infrastructure 28 | description: Manage Selenium Hub and Nodes 29 | version_added: "1.0" 30 | author: Dan Davison (@ddavison) 31 | options: 32 | role: 33 | description: Which role should be ran 34 | required: false 35 | default: 'standalone' 36 | choices: 37 | - "standalone" 38 | - "hub" 39 | - "node" 40 | state: 41 | description: Which state the program should be in 42 | required: true 43 | default: running 44 | choices: 45 | - "running" 46 | - "stopped" 47 | - "restarted" 48 | java: 49 | description: The path of the Java executable 50 | required: false 51 | default: '/usr/bin/java' 52 | logfile: 53 | description: Where to log the output of the hub / node 54 | required: false 55 | default: './selenium.log' 56 | javaargs: 57 | description: Java options to specify. e.g. Xmx1024M 58 | required: false 59 | version: 60 | description: Which version of Selenium to bring down. Can be branch name, hash, version, release, tag 61 | required: false 62 | default: 'master' 63 | path: 64 | description: Where to store the standalone server 65 | required: false 66 | default: '.' 67 | force: 68 | description: Force a redownload / restart of the standalone server 69 | required: false 70 | default: false 71 | ''' 72 | 73 | EXAMPLES = ''' 74 | # Start a standalone server 75 | - selenium: 76 | state: running 77 | 78 | # Start a standalone server (specific version of selenium) 79 | - selenium: 80 | version: 3.5.3 81 | state: running 82 | 83 | # Start a basic grid that listens on port 4444 84 | - selenium: 85 | role: hub 86 | state: running 87 | 88 | # Start a grid that runs on port 4445 89 | - selenium: 90 | role: hub 91 | state: running 92 | args: 93 | port: 4445 94 | 95 | # Start the grid with greater memory 96 | - selenium: 97 | role: hub 98 | state: running 99 | javaargs: 100 | - Xmx1024M 101 | - Xmy1024M 102 | 103 | # Start a basic node that connects locally 104 | - selenium: 105 | role: node 106 | state: running 107 | args: 108 | hubUrl: http://0.0.0.0:4444 109 | 110 | # Restart a running node that was listening on a previous port 111 | - selenium: 112 | role: node 113 | state: restarted 114 | args: 115 | hubUrl: http://0.0.0.0:4445 116 | 117 | # Start a node that uses a JSON config and has a logfile 118 | - template: src=config.json.j2 dest=config.json 119 | - selenium: 120 | role: node 121 | state: running 122 | logfile: node.log 123 | args: 124 | nodeConfig: config.json 125 | ''' 126 | 127 | # use https 128 | JAR_URL = 'https://selenium-release.storage.googleapis.com/%s/selenium-server-standalone-%s.jar' 129 | 130 | import signal 131 | import urllib 132 | 133 | from ansible.module_utils.basic import * 134 | 135 | def is_running(module): 136 | """ 137 | Whether or not the specific role in question is running right now. 138 | :param module: 139 | :return: 140 | """ 141 | 142 | if not get_pid(module): 143 | return False 144 | else: 145 | return True 146 | 147 | 148 | def get_pid(module): 149 | """ 150 | Fetches the pid if it is running, for the role. 151 | :param module: the module 152 | :return: 153 | """ 154 | 155 | pid_cmd = ['pgrep', '-f', '.*selenium-server-%s' % 156 | (module.params['version'])] 157 | 158 | try: 159 | return int(subprocess.check_output(pid_cmd).rstrip()) 160 | except subprocess.CalledProcessError: 161 | return False 162 | 163 | 164 | def start(module): 165 | """ 166 | Start the Selenium standalone 167 | :param module: 168 | :return: 169 | """ 170 | 171 | _, jar_file = download(module) 172 | 173 | changed = False 174 | role = module.params['role'] 175 | if role != 'standalone': 176 | role = "-role %s" % role 177 | else: 178 | role = '' 179 | 180 | if not is_running(module): 181 | changed = True 182 | args = '' 183 | java_args = '' 184 | if module.params['args']: 185 | for (k, v) in module.params['args'].iteritems(): 186 | args += '-%s %s ' % (k, v) 187 | 188 | if module.params['javaargs']: 189 | for arg in module.params['javaargs']: 190 | java_args += '-%s ' % arg 191 | 192 | java_executable = os.path.abspath(os.path.expandvars(module.params['java'])) 193 | log_file = os.path.abspath(os.path.expandvars(module.params['logfile'])) 194 | 195 | cmd = "%s %s -jar %s %s %s >> %s 2>&1 &" % (java_executable, 196 | java_args, 197 | jar_file, 198 | role, 199 | args, 200 | log_file) 201 | 202 | os.setsid() 203 | 204 | #print cmd 205 | rc = os.system(cmd) 206 | 207 | if rc != 0: 208 | abort(module, 'Running the %s role returned code %s !' % (role, rc)) 209 | 210 | pid = get_pid(module) 211 | if pid: 212 | return changed, pid 213 | else: 214 | abort(module, 'Couldnt fetch the pid of the running %s ! It may have ended abruptly.' % module.params['role']) 215 | 216 | 217 | def stop(module): 218 | """ 219 | Stop something 220 | :param module: the module 221 | :return: 222 | """ 223 | 224 | changed = False 225 | pid = get_pid(module) 226 | 227 | if is_running(module): 228 | try: 229 | os.kill(pid, signal.SIGKILL) 230 | if not get_pid(module): 231 | changed = True 232 | except Exception as e: 233 | abort(module, 'Couldnt kill pid %s! Error was: %s' % (pid, e.message)) 234 | 235 | return changed 236 | 237 | 238 | def restart(module): 239 | """ 240 | Restart it 241 | :param module: the module 242 | :return: 243 | """ 244 | 245 | changed = stop(module) 246 | (c, pid) = start(module) 247 | return (c or changed), pid 248 | 249 | 250 | def download(module): 251 | """ 252 | Download jar from downloads page 253 | :param module: the module 254 | :return: 255 | """ 256 | 257 | changed = False 258 | 259 | full_version = module.params['version'] 260 | (major, minor, patch) = full_version.split('.') 261 | 262 | url = JAR_URL % ((major + '.' + minor), full_version) 263 | jar_file = '%s/selenium-server-%s.jar' % (os.path.abspath(os.path.expanduser(module.params['path'])), 264 | full_version) 265 | 266 | if not os.path.exists(jar_file) or module.params['force']: # download if not already downloaded 267 | try: 268 | urllib.urlretrieve(url, jar_file) 269 | changed = True 270 | except Exception as e: 271 | abort(module, "Couldn't download %s. Are you using a valid version? Error was: %s" % 272 | (url, e.message)) 273 | return changed, jar_file 274 | 275 | 276 | def finish(m, **kwargs): 277 | """ 278 | Role is all down 279 | :param m: the module 280 | :param kwargs: all arguments 281 | :return: 282 | """ 283 | 284 | m.exit_json(**kwargs) 285 | 286 | 287 | def abort(m, msg): 288 | """ 289 | Something wrong happened.. abort! 290 | :param m: the module 291 | :param msg: the message 292 | :return: 293 | """ 294 | 295 | m.fail_json(msg=msg) 296 | 297 | 298 | def main(): 299 | """ 300 | Main task / entry point 301 | :return: 302 | """ 303 | 304 | module = AnsibleModule( 305 | argument_spec=dict( 306 | role=dict(choices=['standalone', 'hub', 'node'], default='standalone'), 307 | state=dict(choices=['running', 'stopped', 'restarted'], default='running'), 308 | version=dict(default='3.141.59'), 309 | path=dict(default='.'), 310 | force=dict(default=False, type='bool'), 311 | args=dict(required=False, default={}, type='dict'), 312 | java=dict(required=False, default='/usr/bin/java'), 313 | logfile=dict(required=False, default='./selenium.log'), 314 | javaargs=dict(required=False, default=[], type='list'), 315 | ), 316 | 317 | supports_check_mode=False, 318 | 319 | mutually_exclusive=[] 320 | ) 321 | 322 | state = module.params['state'] 323 | role = module.params['role'] 324 | 325 | if state == 'running': 326 | (changed, pid) = start(module) 327 | finish(module, msg='%s is running' % role, changed=changed, pid=pid) 328 | elif state == 'stopped': 329 | changed = stop(module) 330 | finish(module, msg='%s is stopped' % role, changed=changed) 331 | elif state == 'restarted': 332 | (changed, pid) = restart(module) 333 | finish(module, msg='%s has restarted' % role, changed=changed, pid=pid) 334 | 335 | 336 | main() 337 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: 4 | - "Daniel Davison" 5 | - "Software Freedom Conservancy" 6 | - "Contributors" 7 | license: Apache 2.0 8 | platforms: 9 | - name: Ubuntu 10 | versions: 11 | - all 12 | - name: EL 13 | versions: 14 | - 7 15 | min_ansible_version: 1.9 16 | galaxy_tags: 17 | - selenium 18 | - qa 19 | dependencies: [] 20 | -------------------------------------------------------------------------------- /tests/inventory: -------------------------------------------------------------------------------- 1 | localhost ansible_connection=local 2 | -------------------------------------------------------------------------------- /tests/test-selenium-hub.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: test | selenium grid starts 3 | selenium: > 4 | role=hub 5 | state=running 6 | 7 | register: pid 8 | failed_when: pid.changed == 'false' 9 | 10 | - name: test | selenium grid has the same pid 11 | selenium: > 12 | role=hub 13 | state=running 14 | register: second_pid 15 | failed_when: pid.changed == 'true' and pid.pid != second_pid.pid 16 | 17 | - name: test | selenium grid restarts 18 | selenium: 19 | role: hub 20 | state: restarted 21 | register: third_pid 22 | failed_when: third_pid.changed == 'false' and third_pid.pid == second_pid.pid 23 | 24 | # cleanup 25 | - name: stop selenium grid 26 | selenium: 27 | role: hub 28 | state: stopped 29 | register: r 30 | failed_when: r.changed == 'false' 31 | 32 | -------------------------------------------------------------------------------- /tests/test-selenium-memory.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: test | selenium grid starts 3 | selenium: 4 | role: hub 5 | state: running 6 | javaargs: 7 | - Xmx12M 8 | 9 | register: pid 10 | failed_when: pid.changed == 'false' 11 | 12 | ## cleanup 13 | - name: stop selenium grid 14 | selenium: 15 | role: hub 16 | state: stopped 17 | register: r 18 | failed_when: r.changed == 'false' 19 | 20 | -------------------------------------------------------------------------------- /tests/test-selenium-node.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: test | selenium grid starts 3 | selenium: > 4 | role=hub 5 | state=running 6 | 7 | register: pid 8 | failed_when: pid.changed == 'false' 9 | 10 | - name: test | node connects to grid 11 | selenium: 12 | role: node 13 | state: running 14 | logfile: node.log 15 | args: 16 | hubUrl: http://0.0.0.0:4444/grid/register 17 | 18 | 19 | 20 | # cleanup 21 | - name: test | stop selenium node 22 | selenium: 23 | role: node 24 | state: stopped 25 | register: r 26 | failed_when: r.changed == 'false' 27 | 28 | - name: test | stop selenium grid 29 | selenium: 30 | role: hub 31 | state: stopped 32 | register: r 33 | failed_when: r.changed == 'false' 34 | 35 | -------------------------------------------------------------------------------- /tests/test-selenium-standalone.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: test | standalone starts with role 3 | selenium: > 4 | role=standalone 5 | state=running 6 | 7 | register: pid 8 | failed_when: pid.changed == 'false' 9 | 10 | - name: test | standalone has the same pid 11 | selenium: > 12 | role=standalone 13 | state=running 14 | register: second_pid 15 | failed_when: pid.changed == 'true' and pid.pid != second_pid.pid 16 | 17 | - name: test | standalone restarts without role 18 | selenium: 19 | state: restarted 20 | register: third_pid 21 | failed_when: third_pid.changed == 'false' and third_pid.pid == second_pid.pid 22 | 23 | # cleanup 24 | - name: stop standalone without role 25 | selenium: 26 | state: stopped 27 | register: r 28 | failed_when: r.changed == 'false' 29 | 30 | -------------------------------------------------------------------------------- /tests/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | remote_user: root 4 | connection: local 5 | 6 | roles: 7 | - ../.. 8 | 9 | tasks: 10 | - include: test-selenium-standalone.yml 11 | - include: test-selenium-hub.yml 12 | - include: test-selenium-node.yml 13 | - include: test-selenium-memory.yml 14 | -------------------------------------------------------------------------------- /vagrant-libs/bootstrap.centos.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Update apt packages 4 | yum update -y 5 | 6 | # Install packages 7 | # ibus libdbus-1-devel libgtk2.0-dev 8 | yum install -y \ 9 | gcc \ 10 | git \ 11 | python-pip \ 12 | python-devel \ 13 | python-pip \ 14 | python-virtualenv \ 15 | sshpass \ 16 | openssl \ 17 | openssl-devel \ 18 | libssl-devel \ 19 | java-1.7.0-openjdk \ 20 | libffi \ 21 | libffi-devel 22 | 23 | pip install --upgrade setuptools 24 | pip install idna 25 | pip install pycparser 26 | pip install cryptography 27 | 28 | # Install Ansible if not already existing 29 | if [ ! -d /home/vagrant/ansible ]; then 30 | git clone git://github.com/ansible/ansible.git --recursive /home/vagrant/ansible; 31 | cd /home/vagrant/ansible && git fetch && git checkout stable-2.0 && git pull && git submodule update --init --recursive && make && make install; 32 | fi 33 | 34 | alias test-module=/home/vagrant/ansible/hacking/test-module 35 | -------------------------------------------------------------------------------- /vagrant-libs/bootstrap.ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Update apt packages 4 | apt-get update 5 | 6 | # Install packages 7 | # ibus libdbus-1-dev libgtk2.0-dev 8 | apt-get install -y \ 9 | git \ 10 | python-pip \ 11 | python-dev \ 12 | python-pip \ 13 | python-virtualenv \ 14 | sshpass \ 15 | openssl \ 16 | libssl-dev \ 17 | openjdk-7-jdk \ 18 | libffi6 \ 19 | libffi-dev 20 | 21 | pip install --upgrade setuptools 22 | pip install idna 23 | pip install pycparser 24 | 25 | # Install Ansible if not already existing 26 | if [ ! -d /home/vagrant/ansible ]; then 27 | git clone git://github.com/ansible/ansible.git --recursive /home/vagrant/ansible; 28 | cd /home/vagrant/ansible && git fetch && git checkout stable-2.0 && git pull && git submodule update --init --recursive && make && make install; 29 | fi 30 | 31 | alias test-module=/home/vagrant/ansible/hacking/test-module 32 | 33 | --------------------------------------------------------------------------------