how to increment field value each time selenium test is run? - selenium

is there any simple way to increment for example field value by +1 every time Selenium test is run through Selenium IDE?
Command: Type
Target: some kind of id
Value: number+1
EDIT 1 :thanks for a reply krosenvold. i got your idea and this is a simplified version of what i got so far:
...
store | 10 | x
storeEval | storedVars['x'] = ${x}+1 |
...
variable's x value does realy get incremented, but how would you save that value between distinct test runs? is it even possible?
should i get $x value every time the test is run and at the end of it assign $x value to some dummy element on testing page, so i could retrieve that previously incremented value the next time test is run?

Correct Answer
store | 10 | i
store | javascript{storedVars.i++;} | i
echo | ${i}

This is solution for your problem
store | 10 | i
store | javascript{storedVars.i++;}
echo | ${i}

store | 0 | iterator
echo | ${iterator} |
execute script | return parseInt(${iterator}) + 1 | iterator
echo | ${iterator} |
As result will be:
0
1

You can use eval;
eval($('elementId').value = $('elementId').value +1);
The exact syntax I'm showing implies prototype on the client;
document.getElementById('elementId').value should also do the trick in a standard DOM environment.

This worked for me
storeEval | storedVars['nextRow'] = ${nextRow}+1 |

Related

Conditionally remove a field in Splunk

I have a table generated by chart that lists the results of a compliance scan
These results are typically Pass, Fail, and Error - but sometimes there is "Unknown" as a response
I want to show the percentage of each (Pass, Fail, Error, Unknown), so I do the following:
| fillnull value=0 Pass Fail Error Unknown
| eval _total=Pass+Fail+Error+Unknown
<calculate percentages for each field>
<append "%" to each value (Pass, Fail, Error, Unknown)>
What I want to do is eliminate a "totally" empty column, and only display it if it actually exists somewhere in the source data (not merely because of the fillnull command)
Is this possible?
I was thinking something like this, but cannot figure out the second step:
| eventstats max(Unknown) as _unk
| <if _unk is 0, drop the field>
edit
This could just as easily be reworded to:
if every entry for a given field is identical, remove it
Logically, this would look something like:
if(mvcount(values(fieldname))<2), fields - fieldname
Except, of course, that's not valid SPL
could you try that logic after the chart :
``` fill with null values ```
| fillnull value=null()
``` do 90° two time, droping empty/null ```
| transpose 0 include_empty=false | transpose 0 header_field=column | fields - column
[edit:] it is working when I do the following but not sure it is easy to make it working on all conditions
| stats count | eval keep=split("1 2 3 4 5"," ") | mvexpand keep
| table keep nokeep
| fillnull value=null()
| transpose 0 include_empty=false | transpose 0 header_field=column | fields - column
[edit2:] and if you need to add more null() could be done like that
| stats count | eval keep=split("1 2 3 4 5"," "), nokeep=0 | mvexpand keep
| table keep nokeep
| foreach nokeep [ eval nokeep=if(nokeep==0,null(),nokeep) ]
| transpose 0 include_empty=false | transpose 0 header_field=column | fields - column

Print logs only when the tests failed in karate

With Karate API tests, I would like to print the request and reponse only when the test fails.
How can I achieve that in karate.
Consider the below scenarios
Feature: Validate Addition.
Background:
Scenario Outline: Verify Addition
* def sum = <num1> + <num2>
And match sum == 10
* print "number1:" + num1 + " number2:" + num2
Examples:
| num1 | num2 |
| 5 | 5 |
| 7 | 3 |
| 3 | 8 |
| 1 | 5 |
| 1 | 9 |
In the above scenario I get the print for every iteration. Is it possible to print the numbers only when the match fails.
I think it would be more efficient if we can have such option.
Short answer is that it is not possible. You can try contributing code to make this happen. Or maybe you should use REST-assured or Selenium - those sound more like a good fit for you, based on all your questions.
One thought is that you can switch off all logging by making the levels ERROR etc. and then write some custom hook. Refer to hooks here: https://stackoverflow.com/a/60944060/143475
Also refer to how to create custom reports here: https://stackoverflow.com/a/66773839/143475

Karate - How to pass a variable to another feature file using table [duplicate]

This question already has an answer here:
Karate - How to call multiple external features from a single main feature
(1 answer)
Closed 1 year ago.
After doing some reading, I have figured out how to send variables to another feature file. However, how do I pass a variable when I am using a table?
The setup is:
* table valueTable
| number | mode | time | status |
| 12345 | mobile | 100 | 200 |
* call read('feature1.feature#scenario1') valueTable
So if I use the following line to pass variable through, I get failures:
* call read('feature1.feature#scenario1') {table1: '#(valueTable)', payload1: '#(payload)'}
Of course in above, 'payload' is the variable I want to pass to the second feature file. I don't have any issues passing variables if there is no table involved.
Please advise.
Works for me. Put this in a new feature:
* table valueTable
| number | mode | time | status |
| 12345 | 'mobile' | 100 | 200 |
* call read('called.feature') { table1: '#(valueTable)' }
And in called.feature have this:
#ignore
Feature:
Scenario:
* print __arg
And it works fine. So if you are still stuck, please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Selenium IDE returns false when comparing a longer digit number with shorter (e.g. 11>9, returns false)

store | 11 | x
store | 9 | y
verifyEval | storedVars['x']>storedVars['y'] | true
returns false. If the numbers are of same length (e.g. 9>5) it works fine. What seems to be the problem?
verifyEval seems to be using standard Javascript for its expressions, so this should do it;
verifyEval | parseInt(storedVars['x']) > parseInt(storedVars['y']) | true

How to get the unread mails count in gmail using selenium RC?

I have a requirement to automate the Gmail.Here i need to get the unread mail count of Lables like Inbox,spam,bulk etc.How can i get the count of unread mails using selenium RC.
suppose the Lables as Inbox(5),Spam(10),Bulk(34). it mean that Inbox contains 5 unread mails, Spam contains 10 unread mails.
So For this kind of requirement how can i achieve using Selenium RC?
Thanks & Regards,
Shiva.
I think that using standard IMAP client interface you will be able to get your task done much faster.
See working example in Perl and more official documentation on Mail::ImapClient
String inbox=selenium.getText("//a[contains(#title,'Inbox')]");
Now inbox String variable contains Inbox (1)
String unreadInboxMails=inbox.substring(inbox.indexOf("(")+1,inbox.indexOf(")"));
In this way you can get for all Labels like Spam, bulk etc. only thing you need to change is Label locator .
I hope this will solve your problem.
This is the exact selenese (Selenium IDE) code that gets the unread count of all folders and shows in an alert.
You can use it with Selenium RC by tweaking few commands.
store | //div[#class='LrBjie']/div/div[ | target1
store | ]/div/div/div/span/a | target2
store | 1 | i
store | true | present
store | | countsAll
while | ${present}==true |
storeEval | storedVars['target1']+storedVars['i']+storedVars['target2'] | target
echo | ${target} |
storeText | javascript{storedVars['target']} | counts
storeEval | storedVars['countsAll']+' $ '+storedVars['counts'] | countsAll
echo | ${countsAll} |
storeEval | parseInt(storedVars['i'])+1 | i
storeEval | storedVars['target1']+storedVars['i']+storedVars['target2'] | target
storeElementPresent | javascript{storedVars['target']} | present
echo | ${present} |
endWhile | |
storeEval | javascript{alert(storedVars['countsAll'])} | countsAll
WebDriver gmail = new ChromeDriver();
//Inbox count using xpath. From this output you can separate count from the string 'Inbox(20)'
WebElement inbox = gmail.findElement(By.xpath("//*[#id=':bb']/div/div[1]"));
System.out.println(inbox.getText());