Sample/howtos of advanced topics

Updated a month ago ​by Iván Minaya

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

comment### LOOP EXAMPLE FROM 1 TO 10
store1loopVariable1
whilestoredVars.loopVariable <= 10
echoValue in between while and endWhile is ${loopVariable}
storeEvalstoredVars.loopVariable++
endWhile
comment### CONDITIONAL EXAMPLE
gotoIfstoredVars.loopVariable >= 1SKIP
commentThis command will not be executed, because loopVariable >= 1
labelSKIP

POLYMER/WEBCOMPONENT SUPPORT

The webdriver protocol, and every browser but Google Chrome, do no support at all to test/manipulate those javascript frameworks.

Copado Recorder does its best to record/analyze the actions taken in the browser, but some actions are simply outside the standards. In that case, the only workaround is to right-click an element, add it to the Copado Recorder, and edit the command and value columns to something suitable.

RICH TEXT FIELDS

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

In Salesforce classic/lightning, 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.

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.
But that 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 Completed, and might take up to 5minutes ( 300000ms ) you could use:

setTimeout300000
waitForValuecopado:detail:StatusClosed

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.

the following example 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.

commentCreate an opportunity
open/006/e?retURL=%2F006%2Fo
typecopado=field:Opportunity Name{!RUN_ID}  test opp
typecopado=field:Close Date{!TODAY}
selectcopado=field:StageProspecting
typecopado=field:Amount102.65
clickcopado=button: Save
commentGet the text in the locator, and store it in the variable ATEXT
storeValuecopado=detail:AmountATEXT
echothe locator contains the text: ${ATEXT}
commentConvert it to a number, removing any non-number character ($, %, comma, whitespaces, etc)
storeEvalparseFloat(storedVars.ATEXT.replace(/[^0-9]+/g,""))ANUMBER
commentNow, you can treat storedVars.ANUMBER as a regular number in javascript
verifyEvalstoredVars.ANUMBER+1000 > 1100 TRUE

How did we do?