Cycle does not include a step to add data to the OS Clipboard

Cycle does not include a step to add data to the OS Clipboard

Problem

Cycle has steps that copy, assign to variable, and clear OS clipboard contents but does not contain any steps to copy data to the OS clipboard.

Cycle can enter values into the focus application but that is done character by character. For long strings that can add unnecessary processing delays.

Solution

With Cycle's ability to execute Groovy scripts it is possible to use Groovy functionality to copy Cycle data to the OS clipboard. Once the data is copied to the clipboard it can be pasted all at once avoiding the character by character entry.

Example

The example Groovy syntax is responsible for copying the contents of a variable named "str" to the OS clipboard. The value of the variable will come from Cycle.

clipboard.groovy

import java.awt.Toolkit
import java.awt.datatransfer.Clipboard
import java.awt.datatransfer.StringSelection

Toolkit toolkit = Toolkit.getDefaultToolkit()
Clipboard clipboard = toolkit.getSystemClipboard()
StringSelection strSel = new StringSelection(str)
clipboard.setContents(strSel, null)

The example Scenario assigns a value to a variable named "str". Then executes the Groovy script clipboard.groovy which uses the value in "str". The script is responsible for copying the value of "str" to the OS clipboard. Finally, to validate, the Feature opens notepad and executes the paste shortcut for the clipboard contents.

Scenario: Copy to clipboard
Given I assign "Tryon Solutions is the proud developer of Cycle automated testing software, for individuals and teams who want to regularly test their supply chain systems and processes to identify errors before production is impacted." to variable "str"
When I execute Groovy script "scripts\clipboard.groovy"
Then I execute process "notepad.exe"
And I wait 1 seconds
And I press keys "CTRL+V"

To see the performance difference execute the following Scenario

Scenario: Enter Variable
Given I assign "Tryon Solutions is the proud developer of Cycle automated testing software, for individuals and teams who want to regularly test their supply chain systems and processes to identify errors before production is impacted." to variable "str"
When I execute process "notepad.exe"
Then I wait 1 seconds
And I enter $str

 

    • Related Articles

    • How to use Groovy to work with Strings

      Problem Other than concatenate Cycle does not include steps to work with strings. Solution Cycle now includes steps to execute simple Groovy statements inline as well as execute complex Groovy scripts.  The 2 Cycle steps that execute Groovy are:  I ...
    • How to use Groovy to work with Dates and Times

      Problem Cycle does not include steps to access and work with Date and Time. Solution Cycle now includes steps to execute simple Groovy statements as well as execute complex Groovy scripts.  The 2 Cycle steps that execute Groovy are:  I execute Groovy ...
    • How to use Groovy to return values in XML strings

      Problem It may be necessary to return values from XML strings in your automated tests.  This article provides examples for common ways to use the Groovy programming language to output XML information. Solution Cycle includes steps to execute simple ...
    • How to perform basic math in Cycle using Groovy

      Problem Cycle can increment variable values but does not include steps for simple math Solution Cycle now includes steps to execute simple Groovy statements inline as well as execute complex Groovy scripts.  The 2 Cycle steps that execute Groovy ...
    • Where can I get help using Groovy with Cycle?

      Cycle now includes steps to execute simple Groovy statements inline as well as execute complex Groovy scripts.  The 2 Cycle steps that execute Groovy are:  I execute Groovy "<GROOVY_STATEMENTS>" I execute Groovy script "<GROOVY_SCRIPT_FILE>" Creating ...