I'm trying to populate an array automatically.
These stepes just returns an array containing "foo". The "bar"-string I'm trying to push into it doesnt seem to be included.
execute script | return ["foo"] | testVar
execute script | ${testVar}.push("bar") |
echo | ${testVar}
What am I doing wrong?
I use this approach to update an array in Selenium IDE
execute script | return ['foo'] | testVar
execute script | return [${testVar}, 'bar'] | testVar
echo | ${testVar}
UPDATE
Previous solution is not correct because of wrong value will be stored in the variable testVar. It will be array of array of arrays. So here is the correct one:
execute script | return ['foo'] | testVar
execute script | tmp = ${testVar}; tmp.push('bar'); return tmp; | testVar
echo | ${testVar}
Related
In the PS command below I'm getting the name, creationTimeStamp, Disk_Size and storageBytes of yesterday's snapshots in my gcp project and outputting the data to a csv file (which is later converted to HTML and emailed):
$csv = gcloud --project $gcpProject compute snapshots list --format="csv(name,creationTimestamp,diskSizeGb,storageBytes)" --filter="creationTimestamp.date('%Y-%m-%d')=$yesterday" | Out-File C:\data.csv
The result looks something like this (the number of snapshots displayed varies):
+---------------------------+-------------------------------+--------------+---------------+
| NAME | CREATION_TIMESTAMP | DISK_SIZE_GB | STORAGE_BYTES |
+---------------------------+-------------------------------+--------------+---------------+
| snapshot1-us-central1 | 2019-10-24T19:24:09.061-07:00 | 50 | 1250586048 |
| snapshot2-data-us-east1 | 2019-10-24T19:01:49.791-07:00 | 150 | 425018600 |
+---------------------------+-------------------------------+--------------+---------------+
This is good except that the STORAGE_BYTES data is all in bytes thus making it hard to read. How can I record this data in MB instead in the csv file (or just replacing this data in the csv file that's in bytes with MB)
$data=Get-Content C:\data.csv
$NewData=#($data[0..2])#Adding Header in a new Variable
$Data[3..$($data.Count - 2)]|Foreach{
$startRange=$_.LastIndexOf("| ")+1
$length=$_.LastIndexOf(" |") - $_.LastIndexOf("| ")
#Converting Bytes into MB and replacing in the line
$NewData+=$_.Replace(($_.Substring($startRange,$length)).Trim(),"$([math]::Round(($_.Substring($startRange,$length)/1MB),2)) ")
}
#Adding last line
$NewData+=$data[$data.Count - 1]
#Modifying exsiting file
$NewData |Set-Content C:\data.csv -Force
I think, it should be simple using GCP PowerShell cmdlets.
Get-GceSnapshot -Project $gcpProject
I never used it, but you can use calculated properties to convert the size in oneline, an example below
Get-Process | Select-Object -First 3 -Property Name,#{E={$_.STORAGE_BYTES/1024};L='Size'}
PS: assuming the size property name is STORAGE_BYTES
https://googlecloudplatform.github.io/google-cloud-powershell/#/google-compute-engine/GceSnapshot/Get-GceSnapshot
My example code output:
time | name | status | s_used | s_max |
+------------+-------------+-----------+------------+-----------+
| 1482222363 | asf | Closed | 0/16 | 0 |
| 1482222363 | as0 | Available | 4/16 | 4 |
I have attached the part of my output which is generated using perl cgi script and mysql database.
My query is how to take denominator value from the column s_used and store only the denominator values in the s_max column using perl.
3.I had attached the following part of code which i tried.
if($i == 4){
if(/s_used/){
print;
}
else{
chomp();
my($num,$s_max)=split /\//,$table_data{2}{'ENTRY'};
print $s_max;
}
}
Code Explanation:
$i == 4 is the column where should I store the variable.
I got time column from the sql database $time, name I got from $table_data{0}{'ENTRY'}, status from $table_data{1}{'ENTRY'}, s_used from $table_Data{2}{'ENTRY'}.
Expected output:
time | name | status | s_used | s_max |
+------------+-------------+-----------+------------+-----------+
| 1482222363 | asf | Closed | 0/16 | 16 |
| 1482222363 | as0 | Available | 4/16 | 16 |
Seems your code "my($num,$s_max)=split /\//,$table_data{2}{'ENTRY'};" is right.
Somehow the value $s_max at the time it's writing to the DB is incorrect. Since you did not post the portion of code to show the part $s_max writing back to the DB, you need to check what value is in $s_max (e.g. printing the $s_max value) at the time right before writing it back to DB. From there, please try to trace back why an incorrect value is assigned to $s_max. Then, the problem would be solved.
With the following program, I get a big list out of print~.
I want to a get the second value from this list.
How to get this second value and print it with print and not print~?
[print~] will always print the entire signal-block (in your case 128 values).
to get a specific sample, you could instead use a table, feed the monitored signal into it, and retrieve the value(s) you are interested:
...
|
[tabsend~ $0-foo]
[table $0-foo 128]
[2(
|
[tabread $0-foo]
|
[print]
note: unlike with [print~], which will only generate output at the next signal block, this will output the data immediately (that is: it will take the signal data from the last signal block).
to get the next signal-block, you can replace the lower part of the suggested solution with something like the following:
[bang~] [2(
| |
| [r $0-next] |
| | |
[spigot] [t b f]
| | |
[t f b] [1( |
| | | |
| [0( [s $0-next] |
| | |
| [s $0-next] |
| |
[float ]
|
[tabread $0-foo]
|
...
(the patch uses [s/r $0-next] to avoid cross-over connection lines in the ascii graphics; in practice you probably want to use straight connections instead)
it's probably best to encapsulate the entire thing into an abstraction.
Let's say I have two String variables: var1 and var2.
Is there any command on Selenium IDE (maybe storeEval with some javascript code), with which I can create an array and add the 2 variable values to it? Example:
var1 = "abc"
var2 = "def"
array = ("abc","def")
P.S: the array cannot have a fixed length. In this case I have just 2 variables, but in other scenarios I may have more than 10 variables, so I would need to create a loop and add all 10 variable values to the array.
Thanks!
It's pretty simple but isn't obvious
storeEval | ['one','two'] | array
storeEval | storedVars['array'][1] | second
echo | ${second}
Or simpler but with much less safety
storeEval | ['one','two'] | array
echo | javascript{storedVars['array'][1]}
Adding new item dynamically
getEval | storedVars['array'].push('three')
You can make loop using selenium IDE flow control for example. Like:
storeEval | 0 | i
while | storedVars['i']<storedVars['array'].length
echo | javascript{storedVars['array'][storedVars['i']]}
storeEval | ${i}+1 | i
endWhile
I hope it will help
I want to check whether the variable is storing blank value or not.
I tried out comparing it with '' or "" or NULL or null, but does not work.
You can try out below solution
storeValue | element | test
store | | j (blank value)
gotoIf | storedVars['test']==storedVars['j'] | true
getEval | alert("test Variable Value is not blank")
gotolabel | finish
label | true
getEval | alert("test Variable Value is blank")
label | finish
You can also use verifyEval command for this. Try following script,
verifyEval | this.page().findElement("id=gbqfq").value == '' | true