Selenium Jobs with Timers
Function | This Plugin is for web testing using the selenium framework. It runs RobotFramework or Python based tests on a headless chrome browser which is located on a collector, it waits for the execution to end, then fetches the generated log files and displays them in an overview page. |
---|---|
Alarming | Run time, Response code, Result code |
Selenium Job general information
Selenium projects can be created either by using the RobotFramework or Python language.
To make Selenium project files available on external collectors, the SKOOR syncfs services must be configured and running. User reranger must be configured to login without password as described in the replication guide
RobotFramework
A robot file is generated by using the header from /opt/eranger/collector/robot.robot and appended by the provided file in the Engine. Only in special cases the user might want to supply a full robot file. A good source for information about the possibilities is the RobotFramework User Guide. Robot files will be placed on /opt/eranger/collector/upload/
Information section in the job configuration:
The Chrome or Firefox extension Katalon Recorder can be used to record a test procedure and export the testcase part (format: robot framework).
Example scripts:
A simple robot file could then look like this:
[Teardown] Run Keyword If Test Failed Capture Page Screenshot Set Window Size ${1920} ${1200} Start Timer totalTime Start Timer Open Goto https://my.great.business.com/ Stop Timer Open click link=Business sleep 3s Stop Timer totalTime
A more advanced script with multiple timers and TRY/EXCEPT blocks:
Start Timer TotalTime Start Timer Open TRY Goto https://my.great.business.com/ Stop Timer Open EXCEPT Capture Page Screenshot Error Timer Website unavailable ErrorCode Timer 11 Stop Timer Open END Start Timer Contact TRY click link=Contact Stop Timer Contact EXCEPT Capture Page Screenshot Error Timer Contact link failed ErrorCode Timer 22 Stop Timer Contact END sleep 2s Start Timer Home TRY click link=Home Stop Timer Home EXCEPT Capture Page Screenshot Error Timer Home link failed ErrorCode Timer 33 Stop Timer Home END sleep 2s Stop Timer TotalTime
Python
Selenium and SKOOR Python modules for Selenium web testing are preinstalled with SKOOR Collectors. Python scripts can be developed and used with the plugin as they are developed. Additionally, the Selenium IDE can be used to record use cases.
Information section in the job configuration:
Example Script: First, the requied modules are imported and browser parameters are set. Then, the SKOOR timer totalTime ist started and a test step is run in a try/except block with a second timer, step1. This way, timers can be configured and used later in the SKOOR Engine.
#!/usr/bin/python3 import sys, time, skoor, traceback from skoor import SkoorTimer, Variables, SkoorScreenshot from selenium import webdriver from selenium.webdriver import Chrome from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.desired_capabilities import DesiredCapabilities opts = Options() opts.set_headless() cap = DesiredCapabilities().CHROME cap["marionette"] = True assert opts.headless # Operating in headless mode driver = webdriver.Chrome(chrome_options=opts) skoor.setLogLevel(skoor.INFO) driver.set_window_size(1920,1200) totalTime = SkoorTimer("TotalTime") step1 = SkoorTimer("Step 1") totalTime.start() try: step1.start() skoor.log(skoor.INFO, "Search started") driver.get("https://xyz.com") driver.find_element_by_id("html-element1") skoor.log(skoor.INFO, "Step 1 done") step1.stop() except: skoor.log(skoor.ERROR, traceback.format_exc()) SkoorScreenshot().capture(driver) step1.error(-2, "Step 1 failed") totalTime.stop() driver.quit() skoor.log(skoor.INFO, "Script done")
If Selenium IDE was used to record a testcase, the content of the test_<name> function can be copied into a try block of the Python 3 script:
def test_dict(self): self.driver.get("https://dict.leo.org/englisch-deutsch/") self.driver.set_window_size(1515, 948) self.driver.find_element(By.LINK_TEXT, "Forum").click()
If additional Python modules like by or key have been used by the Selenium IDE, this modules must be added also to the import section of the final script:
#!/usr/bin/python3 import sys, time, skoor, traceback from skoor import SkoorTimer, Variables, SkoorScreenshot from selenium import webdriver from selenium.webdriver import Chrome from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys ...
It is important that the driver.quit() operation is processed in any case. Otherwise there will be a ressource leak!
Selenium Device
When creating a Selenium device the following configuration option screen is shown:
The Selenium plugin will be running in a headless browser directly on the selected collector.
Selenium Job Parameters
Parameter | Description |
---|---|
Run time limit | Specify the amount of time to allow for running the project. This depends on what the project does. This parameter is optional, a value of 0 or left empty means no timeout at all will be set. |
Suite name | If a full robot file with 'Settings' etc is provided, it is executed unmodified. Usually only the 'Test Case' part is required. In such a case the header is taken from /opt/eranger/collector/robot.robot. |
Selenium Properties
Parameter | Description |
---|---|
Selenium Option | Escape sequences and other options may be set by this property. |
Selenium Variable | Variables for the robot file may be defined in this property like INFO:info or TIMEOUT:0 |
Selenium Timer details
In the same way timer jobs are added to EEM project jobs, timer jobs can be added below a selenium job. The only parameter is the timer name.
Timers containing a start and a stop entry (generated by either “Stop Timer” or “Pause Timer”) are considered successful.
The following keywords are available to use timers in the robot file
Start Timer $name
Pause Timer $name
Resume Timer $name
Stop Timer $name
Selenium Timer parameters
Parameter | Description |
---|---|
Timer name | Only the job name and timer name can be configured on a Selenium Timer job. The job's Name can be different from the Timer name but the Timer name must correspond to the timer name as written in the robot file. |
Selenium Timer values and alarm limits
Value / Alarm limit | Description |
---|---|
Run time | The run time of this particular timer |
Result code | 0 = Ok |
Error code | Generic job error code (see section Job error codes) |
Selenium results
After a run of the plugin, the values section of the Selenium job looks like this:
or in case of an error during the execution:
Clicking the Result files link in the Values section will bring up the following new browser tab:
This page provides an overview of the tests that have run and their results. For each run where logs were collected by SKOOR Engine there is a line with a timestamp and a link to the corresponding result file. If there were errors during a run the link is placed in the Failed tests column, along with a screenshot (if taken by the script) and the failed timer(s). This mostly gives a good idea about why a test run failed.
Clicking the Report file in the Values section will bring up a html page which includes an overview of the execution output as well as a link to a more detailed html report file (the same file that can be also accessed directly in the values section).
Selenium values and alarm limits
Value / Alarm limit | Description |
---|---|
Run time | The run time of the plugin |
Result code | 0 = Ok |
Error code | Generic job error code (see section Job error codes) |