This document describes the functionality provide by the xlr-selenium-plugin
This module offers a basic interface to Selenium functionality. The plugin will run python based selenium scripts on a remote host assuming the executing machine is configured with Selenium, Python and has access to the necessary Web Drivers (either locally or via Selenium Grid Hub). Scripts can be retrieved from any remote repository that can be accessed via URL or they can be entered singly, inline, into an XL Release task. The plugin code base includes an example testbed that uses docker to spin up the necessary servers for demonstration and testing purposes.
The Selenium-Python scripts used in version 2+ expect the desired_capabilites and command_executor arguments to be defined within the scripts themselves. The plugin no longer injects that information into the script.
- Requirements
- XL Release 9.0.0+
- Copy the latest JAR file from the releases page into the
XL_RELEASE_SERVER/plugins/__local__
directory. - Restart the XL Release server
- Optionally, within XL Release->Settings->Shared Configurations, configure a UNIX Host server - the remote location where the scripts will run. This host must be configured with Selenium, Python and must have access to the necessary Web Drivers (either locally or via Selenium Grid Hub). Using a host is recommended because it obviates the need to install Python and Selenium on the XL Release server.
The Selenium: Run Single Python Test Case task type runs single script either remotely or locally.
- If executing the script remotely, choose the Unix Host from the drop down list.
- If necessary, you can override the Unix Host password in the password field
- Give the test a descriptive name.
- Copy the full script into to the 'Python Test Case' field.
- Optionally, create a new variable or chose an existing variable of type Text to hold the test results.
import time
import unittest
import os
import logging
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class PythonOrgSearchTest1(unittest.TestCase):
def setUp(self):
print("In setUp")
caps = {'browserName': 'firefox'}
self.browser = webdriver.Remote(
command_executor='http://hub:4444/wd/hub',
desired_capabilities=caps)
self.logger = logging
self.logger.info("About to call a test")
def test_simple(self):
print("In simple")
self.logger.info("In simple")
browser = self.browser
browser.get('http://www.python.org')
self.assertIn("Python", browser.title)
search_box = browser.find_element_by_name('q')
search_box.send_keys('pycon')
search_box.send_keys(Keys.RETURN)
time.sleep(3) # simulate long running test
self.assertIn('pycon', browser.page_source)
def tearDown(self):
print("In tearDown")
self.browser.quit() # quit vs close?
if __name__ == '__main__':
logging.basicConfig(filename='/selenium-plugin.log',level=logging.INFO)
logging.info("About to call main")
unittest.main()
The Selenium: Run Scripts Retrieved From Repository task type runs one or more scripts either remotely or locally. The scripts must be stored in a repository that is accessable via a URL. The size limit for a script has been set at 200,000 characters.
- If executing the script remotely, choose the Unix Host from the drop down list.
- If necessary, you can override the Unix Host password in the password field
- Enter a URL template for the location from which the file or files will be retrieved. This URL must contain the literal string :filename: as a placeholder for the script file name. For example - https://server.com/foo/:filename: or http://host/project/repo1/:filename:?raw
- Enter a list of test name / file name pairs.
- If a listed file is not found, the default behavior is to continue on with the task and retrieve the next file in the list. If 'Fail if file not found' is checked, however, the task will fail if a listed file is not retrieved.
- The default behavior is to process and report on all tests even if some fail along the way. The task itself will fail and exit at the end if any test fails. If 'Fail on first test failure' is checked however, the task will fail and exit upon the first test failure.
- Optionally, create a new variable or chose an existing variable of type Text to hold the JSON formatted test results.
Both tasks produce results in both JSON and Markdown format. The JSON object for each test contains the testname(as defined in the task), result(Passed or Failed), output(Output produced by print statements within the individual scripts), and additionalStream(contains the success stream or the error stream from the remote Unix host and the Selenium Grid Hub). The Markdown report displays the testname and result (Passed/Failed) for each test in table format followed by a listing of the output and additional stream for each test.
Build and package the plugin with...
./gradlew build
- You will need to have Docker and Docker Compose installed
- The XL-Release image expects to find a valid XL-Release license on your machine, at this location: ~xl-licenses/xl-release-license.lic
- Open a terminal in the root of the xlr-selenium-plugin project and run the test -
./gradlew clean integrationTest
The test will set up a temporary python-selenium/selenium grid hub/xlr/selenium firefox node/selenium chrome node/mockserver testbed using docker. NOTE: The integration tests take about 5 minutes to run.
- The python-selenium container - this is where the python-selenium scripts with run. This makes it possible to run python-selenium scripts from xl-release without having to install python and selenium on the xlr server itself.
- Selenium Grid container - this hub manages further execution of the tests on nodes that have been configured with various browser drivers
- Firefox node - this container is used to run tests configured to test against the Firefox browser
- Chrome node - this container is used to run tests configured to test against the Chrome browser
- The mock server is used to act as a script repository. Integration tests set up to invoke the XLR Selenium task named 'Run Scripts Retrieved From Repository' will retrieve the scripts from the mock server
- After testing is complete, the test docker containers are stopped and removed.
- For requirements, see the 'To run integration tests' above
- Build the xlr-selenium-plugin.jar - Open a terminal and cd into and run ./gradlew clean build . Be sure to re-run the command whenever code is changed.
- From another terminal, cd into the /src/test/resources/docker/ directory.
- Run (necessary the first time only): docker-compose build
- Then run: docker-compose up -d
- XL Release will run on the localhost port 15516. It may take up to a minute for XL Release to start up
- The XL Release username / password is admin / admin
- After XL Release has started, you can set up a template and shared configuration server by running the script /src/test/resources/docker/initialize/initialize_data.sh. Alternatively, follow the steps below:
- within XL Release->Settings->Shared Configurations, configure a Unix Host with the following attributes:
- Title -> python-selenium
- Conection Type -> SUDO
- Address -> python-selenium
- Port -> 22
- Username -> root
- Password -> xebialabs
- Within XL Release, navigate to the Templates page and use the import feature to import the template located here: /src/test/resources/docker/initialize/data/release-template-selenium.json .
- within XL Release->Settings->Shared Configurations, configure a Unix Host with the following attributes:
- You can now run a release based the template named 'seleniumTemplate'.
- When code is modified, re-run the ./gradlew clean build (in the first terminal), then refresh the testbed by running docker-compose down followed by docker-compose up -d (in the second terminal) and after XL Release starts up, re-import the server configuration and the template
Further Demo/Dev Notes:
- The log file for the plugin - selenium-plugin.log will be persisted to the local directory /build/reports/tests/log directory.
- The Mockserver runs on the localhost port 5099
- The example script files used in the demo are located in the /src/test/resources/mockserver/responses directory
- If you add example scripts, be sure to rebuild the mockserver docker image