For example, this is working:
cy.nodes("[id='22132']").position('x')
And this isn't:
cy.nodes("[id=targetID]").position('x')
How can I reference ID as a variable?
You can use something fancy like Template-Strings:
cy.nodes(`[id='${variable}']`).position('x');
Or you can use something simple like normal string concatination:
cy.nodes("[id='" + variable + "']").position('x');
Related
I am trying to use an if statement with a variable in my expression and I get no results. The variable works when I use the variable on it's own but when used with the if I get no results.
I have tried:
if(OrderQtr='Apr-Jun 2018',$(vAvgOrderCost),0)
if(OrderQtr='Apr-Jun 2018',sum($(vAvgOrderCost)),0)
sum($(vAvgOrderCost)if(OrderQtr='Apr-Jun 2018',0))
Nothing seems to work. Thanks
Variables in QlikView are used as a text replace feature, so be carefull. If your variable hold a value like 1,345 an expression like "if(OrderQtr='Apr-Jun 2018',$(vAvgOrderCost),0)" will be translated into "if(OrderQtr='Apr-Jun 2018',1,345,0)" which by itself will be a syntax error.
Something like :
Num(if(OrderQtr='Apr-Jun 2018','$(vAvgOrderCost)','0'))
would be a safe way to go.
the if() syntax should work like this if(test,true,false)
So looking at your examples I suspect this is what you are trying to do
sum(if(OrderQtr='Apr-Jun 2018',$(vAvgOrderCost),0))
I know the title may be confusing but this is what I need to do:
I have a list of variables I am pulling from Jquery extractor.
myVar_1 = 343
myVar_2 = 98763
myVar_3 = 5622
etc
I generate a random number between 1 and myVar_matchNr.
Then I want to navigate to a URL that has an ID of one of the randomly selected variables. For instance, this would be the path I would like as an example:
//mydomain.com/api/resource/${myVar_${randomNumber}}
Which would translate to ( in the case my random number was 2):
//mydomain.com/api/resource/98763
I have the random number, and I have the list of variables from the Jquery extractor, but I have been unsuccessful getting the value out of the combination.
I have tried the above URL directly.
I have tried a beanshell script that looked something like:
String myvarString = "myVar_" + get("myRandNumber");
String myVar = get(myvarString);
set("mySelectedVar", myVar);
That seemed to always come up an empty string.
Any suggestions on how to accomplish this?
You can combine 2 variables using __V() function like
${__V(myVar_${randomNumber})}
In regards to Beanshell, you need to use vars object which stands for JMeterVariables class instance to manipulate the JMeter Variables like
String myvarString = "myVar_" + vars.get("myRandNumber");
String myVar = vars.get(myvarString);
vars.put("mySelectedVar", myVar);
See Here’s What to Do to Combine Multiple JMeter Variables article for more information on the topic.
One more option is Random Controller, you can create 3 different request and place it under Random Controller.i hope this will serve the purpose.
I'm trying to set a variable with a dynamic name. This means the name for my new variable comes from another variable:
<#-- in real world I wouldn't declare this variables right here -
they would come from somewhere else -->
<#assign varName = "myVarName"/>
<#assign varValue = "myVarValue/>
<#... set the variable .../>
So that the value can be referenced as follows:
${myVarName} <#-- prints "myVarValue" -->
In a Java directive I would use
Environment#setVariable(String name, TemplateModel model)
to achieve this. But is there a possibility to achieve this with Freemarker directly?
I had a similar problem and Special Variable Reference page helped me:
vars: Expression .vars.foo returns the same variable as expression foo. It's useful if for some reasons you have to use square bracket syntax, since that works only for hash sub variables, so you need an artificial parent hash. For example, to read a top-level variable that has a strange name that would confuse FreeMarker, you can write .vars["A strange name!"]. Or, to access a top-level variable with dynamic name given with variable varName you can write .vars[varName]. Note that the hash returned by .vars does not support ?keys and ?values.
In my case I had to use only strings in my model. I had a bunch of names like Name1, Name2, ... Name10. To make a table of these names I used this code:
<#list 1..10 as x>
<#if .vars["Name" + x]??>
<tr>
<td align="center">${.vars["Name" + x]}</td>
</tr>
</#if>
</#list>
Use a hash. That is, use the name of the variable as the key of the hash.
There's no directive that assigns to a variable that has a dynamic name. But here's a hack to achieve that:
<#'<#assign ${varName} = varValue>'?interpret />
This isn't terribly fast though. It involves FTL parsing each time it's evaluated.
I guess you can do it like this:
${myVarName?eval} <#-- prints "myVarValue" -->
I found the answer from here, and it works to me.
I have seen this:
$makeModels = Make::model()->findAll(array("select"=>"fieldMake", "order"=>"fieldMake DESC"));
is it possible to do so with findAllByAttributes too? I need to only select one column values. I mean I don't want findAllByAttributes return array of object I need only an array of values.
If you only want an array of values use a custom SQL command with CDbCommand
Take a look at the following url for more information:
http://www.yiiframework.com/doc/api/1.1/CDbCommand
It will probably look something like this:
Yii::app()->db->createCommand('your sql query')->queryColumn();
Maybe I'm not searching on the right keywords but: Is it possible to search given an object path?
I have '/businesses/2' and I'd simply like to do something like #object = Business.find('/businesses/2') to fetch that object
One way is to:
ids = params[:who_id].split('/')
#object = ids[1].singularize.constantize.find(ids[2])
But I'm wondering if there is a built in way since this seemed to me as something quite normal to do.
If you know that the id will be the last in the string then you can split the string by "/" and take the last element. If you're unsure, you may use regexp.
If you want also to perform a search depending on what's in your string (you do not know class name)) then use regexp to match a model name and then use these helpers:
http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
to get a name of the class.
Like:
klass = _yor_extracted_string.singularize.constantize
object = klass.find(_id_here_)