How to compare and evaluate two int variables? - selenium-ide

I have two stored int variables a and b.
I want to verify that b is bigger than a so the test to pass.
What would be the JS command in the IDE?

I would try assertEval | storedVars['a'] < storedVars['b'] | true.

In contrast to this other answer, removing the storedVars bit worked for me. I just used the var names in single quotes:
assertEval | '${a}' < '${b}' | true

Related

How to remove multiple characters between 2 special characters in a column in SSIS expression

I want to remove the multiple characters starting from '#' till the ';' in derived column expression in SSIS.
For example,
my input column values are,
and want the output as,
Note: Length after '#' is not fixed.
Already tried in SQL but want to do it via SSIS derived column expression.
First of all: Please do not post pictures. We prefer copy-and-pastable sample data. And please try to provide a minimal, complete and reproducible example, best served as DDL, INSERT and code as I do it here for you.
And just to mention this: If you control the input, you should not mix information within one string... If this is needed, try to use a "real" text container like XML or JSON.
SQL-Server is not meant for string manipulation. There is no RegEx or repeated/nested pattern matching. So we would have to use a recursive / procedural / looping approach. But - if performance is not so important - you might use a XML hack.
--DDL and INSERT
DECLARE #tbl TABLE(ID INT IDENTITY,YourString VARCHAR(1000));
INSERT INTO #tbl VALUES('Here is one without')
,('One#some comment;in here')
,('Two comments#some comment;in here#here is the second;and some more text')
--The query
SELECT t.ID
,t.YourString
,CAST(REPLACE(REPLACE((SELECT t.YourString AS [*] FOR XML PATH('')),'#','<!--'),';','--> ') AS XML) SeeTheIntermediateXML
,CAST(REPLACE(REPLACE((SELECT t.YourString AS [*] FOR XML PATH('')),'#','<!--'),';','--> ') AS XML).value('.','nvarchar(max)') CleanedValue
FROM #tbl t
The result
+----+-------------------------------------------------------------------------+-----------------------------------------+
| ID | YourString | CleanedValue |
+----+-------------------------------------------------------------------------+-----------------------------------------+
| 1 | Here is one without | Here is one without |
+----+-------------------------------------------------------------------------+-----------------------------------------+
| 2 | One#some comment;in here | One in here |
+----+-------------------------------------------------------------------------+-----------------------------------------+
| 3 | Two comments#some comment;in here#here is the second;and some more text | Two comments in here and some more text |
+----+-------------------------------------------------------------------------+-----------------------------------------+
The idea in short:
Using some string methods we can wrap your unwanted text in XML comments.
Look at this
Two comments<!--some comment--> in here<!--here is the second--> and some more text
Reading this XML with .value() the content will be returned without the comments.
Hint 1: Use '-->;' in your replacement to keep the semi-colon as delimiter.
Hint 2: If there might be a semi-colon ; somewhere else in your string, you would see the --> in the result. In this case you'd need a third REPLACE() against the resulting string.

Need to explain the kdb/q script to save partitioned table

I'm trying to understand this snippet code from:
https://code.kx.com/q/kb/loading-from-large-files/
to customize it by myself (e.x partition by hours, minutes, number of ticks,...):
$ cat fs.q
\d .Q
/ extension of .Q.dpft to separate table name & data
/ and allow append or overwrite
/ pass table data in t, table name in n, : or , in g
k)dpfgnt:{[d;p;f;g;n;t]if[~&/qm'r:+en[d]t;'`unmappable];
{[d;g;t;i;x]#[d;x;g;t[x]i]}[d:par[d;p;n];g;r;<r f]'!r;
#[;f;`p#]#[d;`.d;:;f,r#&~f=r:!r];n}
/ generalization of .Q.dpfnt to auto-partition and save a multi-partition table
/ pass table data in t, table name in n, name of column to partition on in c
k)dcfgnt:{[d;c;f;g;n;t]*p dpfgnt[d;;f;g;n]'?[t;;0b;()]',:'(=;c;)'p:?[;();();c]?[t;();1b;(,c)!,c]}
\d .
r:flip`date`open`high`low`close`volume`sym!("DFFFFIS";",")0:
w:.Q.dcfgnt[`:db;`date;`sym;,;`stats]
.Q.fs[w r#]`:file.csv
But I couldn't find any resources to give me detail explain. For example:
if[~&/qm'r:+en[d]t;'`unmappable];
what does it do with the parameter d?
(Promoting this to an answer as I believe it helps answer the question).
Following on from the comment chain: in order to translate the k code into q code (or simply to understand the k code) you have a few options, none of which are particularly well documented as it defeats the purpose of the q language - to be the wrapper which obscures the k language.
Option 1 is to inspect the built-in functions in the .q namespace
q).q
| ::
neg | -:
not | ~:
null | ^:
string | $:
reciprocal| %:
floor | _:
...
Option 2 is to inspect the q.k script which creates the above namespace (be careful not to edit/change this):
vi $QHOME/q.k
Option 3 is to lookup some of the nuggets of documentation on the code.kx website, for example https://code.kx.com/q/wp/parse-trees/#k4-q-and-qk and https://code.kx.com/q/basics/exposed-infrastructure/#unary-forms
Options 4 is to google search for reference material for other/similar versions of k, for example k2/k3. They tend to be similar-ish.
Final point to note is that in most of these example you'll see a colon (:) after the primitives....this colon is required in q/kdb to use the monadic form of the primitive (most are heavily overloaded) while in k it is not required to explicitly force the monadic form. This is why where will show as &: in the q reference but will usually just be & in actual k code

How to execute inline source blocks in an org-mode table?

I would like to have the output of src_R blocks in an org-mode table:
| Variable | Value |
|----------+----------|
| x | src_R{x} |
However, when I export to PDF (via LaTeX) I get the literal src_R{x} rather than the value of the x variable in the underlying R session. I can use the same src_R{x} in text and it works as expected.
Is there a way to support inline source code in tables?
(I have seen this question with a similar title: Code blocks inside tables for org-mode, but the topic is different.)
Thanks to the prompt by Juancho (see comments), I have found the answer here: http://orgmode.org/worg/org-contrib/babel/intro.html#spreadsheet. I first define a named source block to perform my R computation:
#+NAME: my-code
#+BEGIN_SRC R :results output
message(10)
#+END_SRC
(Imagine the output is simply the number 10). Then I insert it into the table like this:
| Variable | Value |
|----------+-------|
| Name | |
#+TBLFM: #2$2='(org-sbe my-code)
Comments:
It seems that org-babel-execute is no longer there, the docs use org-sbe, which works with my 9.0.x org-mode version.
I have wrapped the code output in message() to avoid extra output from R. I have tried various header arguments to the R code (e.g., :results value raw) but I get either extra parentheses, presumably from lisp, or errors.
With org-sbe you can also pass arguments to the code, and even the output of other code blocks. This is explained in the docs referenced above.

How do you convert data types in Windows Powershell?

I'm very new to powershell and am running into walls trying to convert a string to a integer.
If I run the following command: Get-DefaultAudioDeviceVolume it often returns a number that looks something like: 50.05816%, which I have confirmed to be a string. I need to convert this to a whole number integer (50). Obviously I could hard code the integer in my script, but for the purpose of the script I need it to be flexible in it's conversion. The result of the previous test changes and I want to pass along the whole integer further down the line.
Thanks in advance!
If the string contains the % symbol you would need to remove this, then you can use the -as operator to convert to [int]
[string]$vol = "50.05816%"
$vol_int = $vol.Replace('%','') -as [int]
The -as operator is very useful and has many other uses, this article goes through a number of them: https://mcpmag.com/articles/2013/08/13/utilizing-the-as-operator.aspx
Just cast it to integer and replace the "%" with nothing:
[int]$var = (Get-DefaultAudioDeviceVolume).Replace("%","")
Powershell does automatic type casting and starts from the left. So when $var is defined as an integer, it will try to convert the right side to the same type.

How to pass arguments by reference to robot framework keywords?

I have a keyword in robot framework; it takes an argument, performs some process on it and returns it after all:
My Keyword Name
[Arguments] ${arg}
# Some process on ${arg}
[Return] ${arg}
So it would be the usage:
${x} = My Keyword Name ${x}
Which implies that I gave the old value of ${x} to the keyword and it returned me the new value of it.
I want to make a call by reference on My Keyword Name, so I don't need to use an assignment for setting new value for ${x}. I have read the BuiltIn and UserGuide,
but there was no line about this subject. Can anyone help me on this?
If ${x} is a mutable type such as a list or dictionary, you can pass the object itself. If it represents a scalar value such as a string or int, you can't do what you want. Your only choice is to return the new value and re-assign it to the original variable.
It will work if you initialize the variable as
My Keyword Name
[Arguments] ${arg}
${arg} = Set Variable 56
[Return] ${arg}
Test
Log To Console \n\nin Test
${x} = Set Variable 0
${x} = My Keyword Name ${x}
Log To Console ${x}
Or
Can you explore whether you can make use of Set Global Variable or Set Test Variable?
I'd spent some time before i got the solution!
* Variables
${someVar} initial value
* Test Cases
[Check reference]
Set this \${someVar} new value
Should Be Equal ${someVar} new value
* Keywords
Set this
[Arguments] ${varName} ${value}
Set Test Variable ${varName} ${value}
The point is in the magic "\" char :)
It actually comes down to mutable/immutable variables in python, and how they are passed to functions.
Details here in this answer, but in RF context it boils down to - you can change lists and dictionaries, and not strings and numbers (int, float). Example:
A testcase
Log To Console \n
${var}= Create List member1
Log To Console ${var}
Mutate The List ${var}
Log To Console ${var}
*** Keywords ***
Mutate The List
[Arguments] ${lst}
Append To List ${lst} new one
The output when ran would be:
==============================================================================
A testcase
['member1']
['member1', 'new one']
| PASS |
, e.g. the variable defined in the case got changed by a keyword. The same can be done with dictionaries.
If you reassign the variable in the function though, it will not change; e.g. with a keyword like this:
Mutate The Dict
[Arguments] ${lst}
${lst}= Create List fsf
Append To List ${lst} bogus
, the original variable ${var} will not be changed.
Why so? In short, in python variables are just identifiers ("names") to memory addresses; when you assign ${lst} to a new list, the variable now points to a new address in the memory, and further interactions don't change the original one.
Welp I just ran into the same issue, as I was using a Run Keyword If statement in a For Loop. Knowing that if I used a keyword that returns a value, robot framework freaks out.
So I just thought of this as a potential solution. It'll use my example. It does have redundancy, but thats because you just have to in this case.
***Keywords***
| Increment | [Arguments] | ${var} |
| | ${var} | Evaluate | ${var} + 1 |
| | Set Test Variable | ${var} | ${var} |
Usage:
| Increment | ${idx} |
| Set Test Variable | ${idx} | ${var}
Now I'm not saying this is the best solution, but if you run into the scenario that you have to return a value to a variable with a keyword, and you're inside a "Run Keyword If", this should allow you to circumvent the issue. I don't really like it that much, but it gets the job done.