Ask a Question

What Opeation Should I Use?

KaileeT
New Contributor

What Opeation Should I Use?

I'm trying to use the following code to get the current date to set a field in my test:

var currentDate=aqDateTime.Now();
var dateTime=aqConvert.DateTimeToFormatStr(currentDate);

 

When I try to use the Keys operation and have the value mode be Variable, it enters the code rather than the value. I have the code as the default value for the variable. I'm not sure if that's the issue or the operation. Any help to get this working would be much appreciated.

4 REPLIES 4
tristaanogre
Esteemed Contributor

Can you provide a screenshot showing the parameter settings for your keys operation?  There's an option called "mode" where you would need to determine what type of mode you are using for the parameter.  For what you have below, I'd actually set that mode to "code expression".

 

Alternatively, you could use the "Set Variable Value" operation to create a local variable to your keyword test and, in the "Value" parameter for that, again, select code expression. 

 

In both of the above cases, your code expression should be as follows... you are implying that you're running the code and taking the result and using it as the value.

 

aqConvert.DateTimeToFormatStr(aqDateTime.Now(), '%m/%d/%Y %H:%M')

Note that I added another parameter to the code... the DateTimeToFormatStr requires a parameter to indicate how you're formatting the string.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Marsha_R
Community Hero

@KaileeT

 

What you have in your variables right now isn't being interpreted as code, it's being interpreted as a string.  The quickest thing to do is:

mydatefield = eval(currentDate)

mytimefield = eval(dateTime)

 

The eval command causes what's in the variable to be interpreted the way you intended.  If you want that all in one field like

 

mydatetimefield = eval(currentDate) + eval(dateTime)

 

then you will need to play around with the % formatting to get the display to look pretty

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/date-and-time-f...

 

 


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame

@tristaanogre Here is what I'm using to try to set the field with the value received from the variable. I'm setting the variable in the Variables page of a keyword test.

tristaanogre
Esteemed Contributor

OK... first, you should leave the default value of your variable blank.  Code is not evaluated on that page so anything you may enter there in the way of code is simply stored as a string.  This is why it's being entered as a string in your contorl. To evaluate a code expression and assign it to a variable, you need the Set Variable Value operation

SetVariableValue.png

 

When you drag that into your keyword test, you'll get a dialog that asks you to select your variable.  Select the one you created and click Next

 

Set Variable Value dialog.png

 

When you click Next, you'll be prompted to choose the Mode for your parameter.  Set it to "Code Expression"

 

Set Variable Value code expression mode.png

 

Once you select code expression, you'll have a field where you can enter your code expression.  You should enter it as I had above where you just enter the expression to be evaluated and don't include any "=" to assign anywhere.

 

CodeExpression Variable.pngKeywordTestSetVariable.png

 

This is how you set a variable to a code expression in a keyword test.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cancel
Showing results for 
Search instead for 
Did you mean: