Samples and howtos of advanced topics

Updated 4 months ago by Elena Illán

In this article, you will find some good practices and samples of complex structures of variables in our Test Cases. To learn how to create a Test Case, see Selenium Test Cases article.

CONDITIONAL AND LOOPS IN EXECUTIONS

The following short script shows complex structures, such as conditional execution (if), and a numbered loop (for), along with assigning and using variables in Javascript and Selenese.

COMMAND PARAM  1/TARGET PARAM 2/VALUE
store 1 loopVariable1
while storedVars.loopVariable <= 10
echo Value in between while and endWhile is ${loopVariable}
storeEval storedVars.loopVariable++
endWhile
comment ### CONDITIONAL EXAMPLE
gotoIf storedVars.loopVariable >= 1 SKIP
comment This command will not be executed, because loopVariable >= 1
label SKIP

RICH TEXT FIELDS

We offer limited support for rich text editors, allowing to "type" HTML in that kind of elements, but the recording cannot work.

In Salesforce classic/lightning, in order to set the value of a rich text field, you can right-click in the label of a field (not the field itself) and add it to the Copado recorder. Then change the command to type, the locator to copado=field:XXX (instead of copado=label:XXX ) and put the text in the value column. The end result should be something like:

COMMAND PARAM  1/TARGET PARAM 2/VALUE
type copado=field:Project Name Copado QA


TESTING SLOW ACTIONS

Some actions are slow and might require hard to predict delays. A simple way to deal with that is by using the "pause <milliseconds>" command. That command inserts a fixed pause, which might slow down every execution.

A better alternative is to wait for something on the page to change. E.G.: if there is a Status field in a salesforce page, that will automatically change to Closed and might take up to 5minutes ( 300000ms ), you could use:

COMMAND PARAM  1/TARGET PARAM 2/VALUE
setTimeout 300000
waitForValue copado:detail:Status Closed

This will wait for the value to change to  "Closed", for up to 5min. Bear in mind that if you want to reset the timeout to its default value ( 30 seconds ), instead of keeping it for 5 minutes, you need to add another setTimeout after the waitForValue

HANDLING NUMERIC VALUES IN WEBPAGES 

Selenese and HTML in general deals with text only, so, in order to perform any arithmetic operation or comparison, it's necessary to convert the text to a javascript number.

In the following example, we create an opportunity. This process shows, in bold, how to extract a fragment of text representing a number, how to convert it to a javascript number, and then how to perform arithmetic operations.

 
COMMAND PARAM 1/TARGET PARAM 2/VALUE
open /006/e?retURL=%2F006%2Fo
type copado=field:Opportunity Name {!RUN_ID}  test opp
type copado=field:Close Date {!TODAY}
select copado=field:Stage Prospecting
type copado=field:Amount 102.65
click copado=button: Save
comment Get the text in the locator, and store it in the variable ATEXT
storeValue copado=detail:Amount ATEXT
echo the locator contains the text: ${ATEXT}
comment Convert it to a number, removing any non-number character ($, %, comma, whitespaces, etc)
storeEval parseFloat(storedVars.ATEXT.replace(/[^0-9]+/g,"")) ANUMBER
comment Now, you can treat storedVars.ANUMBER as a regular number in javascript
verifyEval storedVars.ANUMBER+1000 > 1100 TRUE


How did we do?